sol practice1

12

Upload: nitin-ainani

Post on 03-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 1/12

C S E 2 3 2 F a l l , 2 0 0 0  

S o l u t i o n s t o p r a c t i c e p r o b l e m s o n q u e r i e s  

1 . ( a ) L i s t t h e b a r s t h a t s e r v e a b e e r t h a t J o e l i k e s .

( i ) t u p l e c a l c u l u s :

f  b  : b a r  j 9  s  2  s e r v e s  9  l  2  l i k e s  

(  s  (  b a r  ) =  b  (  b a r  )   ̂ s  (  b e e r   ) =  l  (  b e e r   )   ̂ l  (  d r i n k e r  ) =  J o e  )  g  :

( i i ) d o m a i n c a l c u l u s :

f  b  : b a r  j 9  c  : b e e r   (  s e r v e s  (  b ; c  )   ̂ l i k e s   (  c ; J o e  ) )  g  :

( i i i ) r e l a t i o n a l a l g e b r a :

 

b a r 

(  s e r v e s   1   

d r i n k e r  =  J o e 

(  l i k e s   ) )  :

( i v ) S Q L :

s e l e c t   s e r v e s . b a r  

f r o m   s e r v e s  , l i k e s  

w h e r e   s e r v e s . b e e r = l i k e s . b e e r  

A N D  l i k e s . d r i n k e r =   \ J o e "  

( v ) Q B E :

s e r v e s b a r b e e r  

b c 

l i k e s d r i n k e r b e e r  

J o e c  

a n s w e r b a r  

I .  b 

( b ) L i s t t h e d r i n k e r s t h a t f r e q u e n t a t l e a s t o n e b a r t h a t s e r v e s a b e e r  

t h e y l i k e .

( i ) t u p l e c a l c u l u s :

f  d  : d r i n k e r   j 9  f  2  f r e q u e n t s  9  s  2  s e r v e s  9  l  2  l i k e s  

(  f  (  d r i n k e r   ) =  d  (  d r i n k e r  )   ̂ f  (  b a r  ) =  s  (  b a r  ) 

 ̂ s  (  b e e r   ) =  l  (  b e e r   )   ̂ l  (  d r i n k e r   ) =  d  (  d r i n k e r  ) )  g 

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 2/12

( i i ) d o m a i n c a l c u l u s :

f  d  : d r i n k e r   j 9  b  9  c    f r e q u e n t s  (  d ; b  )   ̂ s e r v e s  (  b ; c  )   ̂ l i k e s   (  d ; c  ) ] g 

( i i i ) r e l a t i o n a l a l g e b r a :

 

d r i n k e r  

(  f r e q u e n t s   1  s e r v e s   1  l i k e s   ) 

( i v ) S Q L :

s e l e c t    f r e q u e n t s . d r i n k e r 

f r o m    f r e q u e n t s  , s e r v e s  , l i k e s  

w h e r e    f r e q u e n t s . b a r  =  s e r v e s . b a r  

a n d  s e r v e s . b e e r = l i k e s . b e e r  

a n d  l i k e s . d r i n k e r   =   f r e q u e n t s . d r i n k e r 

( v ) Q B E :

f r e q u e n t s d r i n k e r b a r  

d b 

s e r v e s b a r b e e r  

b c 

l i k e s d r i n k e r b e e r  

d c 

a n s w e r d r i n k e r  

I .  d 

( c ) L i s t t h e d r i n k e r s t h a t f r e q u e n t o n l y b a r s t h a t s e r v e s o m e b e e r  

t h a t t h e y l i k e .

( A s s u m e e a c h d r i n k e r l i k e s a t l e a s t o n e b e e r a n d f r e q u e n t s a t l e a s t  

o n e b a r . )  

( i ) t u p l e c a l c u l u s :

f  d  : d r i n k e r   j 8  f  2  f r e q u e n t s    f  (  d r i n k e r  ) =  d  (  d r i n k e r  )  ! 

9  s  2  s e r v e s  9  l  2  l i k e s   (  s  (  b a r  ) =  f  (  b a r  )   ̂

s  (  b e e r   ) =  l  (  b e e r   )   ̂ l  (  d r i n k e r   ) =  d  (  d r i n k e r  ) )  g 

( i i ) d o m a i n c a l c u l u s :

f  d  : d r i n k e r   j 8  b    f r e q u e n t s  (  d ; b  )  ! 

9  c  (  s e r v e s  (  b ; c  )   ̂ l i k e s   (  d ; c  ) ) ] g 

( i i i ) r e l a t i o n a l a l g e b r a :

 

d r i n k e r  

(  f r e q u e n t s  )     

d r i n k e r  

  f r e q u e n t s     

d r i n k e r ; b a r  

(  s e r v e s   1  l i k e s   ) ] :

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 3/12

( i v ) S Q L :

s e l e c t   d r i n k e r  

f r o m    f r e q u e n t s 

w h e r e   d r i n k e r   n o t i n  

(  s e l e c t    f . d r i n k e r 

f r o m    f r e q u e n t s f 

w h e r e    f . b a r  n o t i n  

(  s e l e c t   b a r 

f r o m   s e r v e s  , l i k e s  

w h e r e   s e r v e s . b e e r = l i k e s . b e e r  

a n d  l i k e s . d r i n k e r = f . d r i n k e r  ) ) 

( v ) Q B E :

S t a g e I   ( n d c o m p a t i b l e d r i n k e r - b a r p a i r s ) :

s e r v e s b a r b e e r  

b c 

l i k e s d r i n k e r b e e r  

d c 

c o m p a t i b l e d r i n k e r b a r  

I .  d b 

S t a g e I I   ( n d d r i n k e r s w h o f r e q u e n t s o m e i n c o m p a t i b l e b a r ) :

f r e q u e n t s d r i n k e r b a r  

d b 

c o m p a t i b l e d r i n k e r b a r  

:  d b 

b a d d r i n k e r  

I .  d 

S t a g e I I I   ( n d a n s w e r b y t a k i n g t h e c o m p l e m e n t ) :

f r e q u e n t s d r i n k e r b a r  

b a d d r i n k e r  

:  d 

a n s w e r d r i n k e r  

I .  d 

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 4/12

( d ) L i s t t h e d r i n k e r s t h a t f r e q u e n t n o b a r t h a t s e r v e s a b e e r t h a t t h e y  

l i k e .

T h i s i s j u s t t h e c o m p l e m e n t o f ( b ) .

2 . ( a ) L i s t t h e a c t o r s c a s t i n a t l e a s t o n e m o v i e b y K u r o s a w a ( h e r e a n d  

b e l o w , K  s t a n d s f o r K u r o s a w a ) .

( i ) d o m a i n c a l c u l u s :

f  a  : a c t o r   j 9  t f i l m   (  t ; K ; a  )  g  :

( i i ) r e l a t i o n a l a l g e b r a :

 

a c t o r  

(   

d i r e c t o r   =  K 

(  f i l m   ) )  :

( i i i ) S Q L :

s e l e c t   a c t o r  

f r o m     l m 

w h e r e   d i r e c t o r = K  

( i v ) Q B E :

l m t i t l e d i r e c t o r a c t o r  

K  P . 

( b ) L i s t t h e a c t o r s c a s t i n e v e r y m o v i e b y K u r o s a w a .

( i ) d o m a i n c a l c u l u s :

f  a  : a c t o r   j 8  t    9  x  (  f i l m   (  t ; K ; x   ) )  !  f i l m   (  t ; K ; a   )  g  :

( i i ) r e l a t i o n a l a l g e b r a :

 

a c t o r  

(  f i l m   )     

a c t o r  

   

t i t l e  

(   

d i r e c t o r   =  K 

(  f i l m   ) )  1   

a c t o r  

(  f i l m   ) 

   

t i t l e ; a c t o r  

(   

d i r e c t o r   =  K 

(  f i l m   ) ) ]

A l s o ,

 

t i t l e ; a c t o r  

(  f i l m   )     

t i t l e  

(   

d i r e c t o r   =  K 

(  f i l m   ) )  :

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 5/12

( i i i ) S Q L :

s e l e c t   a c t o r  

f r o m     l m 

w h e r e   a c t o r   n o t i n  

(  s e l e c t    f . a c t o r 

f r o m     l m f g 

w h e r e   g . d i r e c t o r = K   a n d   f . a c t o r  n o t i n  

(  s e l e c t   a c t o r  

f r o m     l m 

w h e r e   t i t l e = g . t i t l e   ) ) 

( i v ) Q B E :

S t a g e I  

l m t i t l e d i r e c t o r a c t o r  

t K 

:  t a 

b a d - a c t o r s a c t o r  

I .  a 

S t a g e I I  

l m t i t l e d i r e c t o r a c t o r  

b a d - a c t o r s a c t o r  

:  a 

a n s w e r a c t o r  

I .  a 

( c ) L i s t t h e a c t o r s c a s t o n l y i n m o v i e s b y K u r o s a w a .

( i ) d o m a i n c a l c u l u s :

f  a  : a c t o r   j 8  t  8  d    f i l m   (  t ; d ; a   )  !  d  =  K  ] g 

( i i ) r e l a t i o n a l a l g e b r a :

 

a c t o r  

(  f i l m   )     

a c t o r  

(   

d i r e c t o r   6=  K 

(  f i l m   ) )  :

( i i i ) S Q L :

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 6/12

s e l e c t   a c t o r  

f r o m     l m 

w h e r e   a c t o r   n o t i n  

(  s e l e c t   a c t o r  

f r o m     l m 

w h e r e   d i r e c t o r   6=  K  ) 

( i v ) Q B E :

S t a g e I  

l m t i t l e d i r e c t o r a c t o r  

6= K a 

b a d - a c t o r s a c t o r  

I .  a 

S t a g e I I  

l m t i t l e d i r e c t o r a c t o r  

b a d - a c t o r s a c t o r  

:  a 

a n s w e r a c t o r  

I .  a 

( d ) L i s t a l l p a i r s o f a c t o r s w h o a c t t o g e t h e r i n a t l e a s t o n e m o v i e .

( i ) d o m a i n c a l c u l u s :

f  a 

: a c t o r  

; a 

: a c t o r  

j 9  t  9  d  (  f i l m   (  t ; d ; a  

)   ̂ f i l m   (  t ; d ; a  

) )  g 

( i i ) r e l a t i o n a l a l g e b r a :

 

a c t o r  

; a c t o r  

   

a c t o r   !  a c t o r  

(  f i l m   )  1   

a c t o r   !  a c t o r  

(  f i l m   ) ]

( i i i ) S Q L :

s e l e c t    f . a c t o r , g . a c t o r 

f r o m     l m f g 

w h e r e    f . t i t l e = g . t i t l e 

( i v ) Q B E :

l m t i t l e d i r e c t o r a c t o r  

t  a 

t  a 

a n s w e r a c t o r  

a c t o r  

I .  a 

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 7/12

( e ) L i s t a l l p a i r s o f a c t o r s c a s t i n e x a c t l y t h e s a m e m o v i e s .

( i ) d o m a i n c a l c u l u s :

f  a 

: a c t o r  

; a 

: a c t o r  

j 8  t  8  d    f i l m   (  t ; d ; a  

)  $  f i l m   (  t ; d ; a  

) ] g 

( i i ) r e l a t i o n a l a l g e b r a :

C o n s i d e r r s t t h e q u e r y   q  a s k i n g f o r p a i r s o f a c t o r s   < a ; a  

0

s u c h t h a t   a  a c t s i n e v e r y m o v i e w h e r e   a 

0

a c t s . T h i s i s e x -  

p r e s s e d b y :

 

a c t o r  

(  f i l m   )     

a c t o r   !  a c t o r  

0

(   

a c t o r  

(  f i l m   ) )   

 

a c t o r ; a c t o r  

0

   

a c t o r  

(  f i l m   )     

a c t o r   !  a c t o r  

0

(  f i l m   )    f i l m      

a c t o r   !  a c t o r  

0

(   

a c t o r  

(  f i l

T h e g i v e n q u e r y i s n o w e x p r e s s e d b y :

q  1   

a c t o r ; a c t o r  

0

!  a c t o r  

0

; a c t o r  

(  q  )  :

( i i i ) S Q L :

s e l e c t    f . a c t o r , g . a c t o r 

f r o m     l m f g 

w h e r e   <   f . a c t o r , g . a c t o r  >  n o t i n   Q 

a n d  <  g . a c t o r , f . a c t o r   >  n o t i n   Q 

w h e r e Q i s :

s e l e c t   x . a c t o r , y . a c t o r  

f r o m     l m x y 

w h e r e   y . a c t o r   n o t i n  

(  s e l e c t   a c t o r  

f r o m     l m 

w h e r e   t i t l e = x . t i t l e   ) 

( i v ) Q B E :

S t a g e I  

l m t i t l e d i r e c t o r a c t o r  

t a 

:  t a 

b a d a c t o r  

a c t o r  

I .  a 

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 8/12

S t a g e I I  

l m t i t l e d i r e c t o r a c t o r  

b a d a c t o r  

a c t o r  

:  a 

:  a 

a n s w e r a c t o r  

a c t o r  

I .  a 

( f ) L i s t t h e d i r e c t o r s s u c h t h a t e v e r y a c t o r i s c a s t i n o n e o f h i s / h e r  

l m s .

( i ) d o m a i n c a l c u l u s :

f  d  : d i r e c t o r   j 8  a    9  t  9  e  (  f i l m   (  t ; e ; a   ) )  ! 9  t f i l m   (  t ; d ; a   ) ] g 

( i i ) r e l a t i o n a l a l g e b r a :

 

d i r e c t o r ; a c t o r  

(  f i l m   )     

a c t o r  

(  f i l m   )  :

( i i i ) S Q L :

s e l e c t   d i r e c t o r  

f r o m     l m 

w h e r e   d i r e c t o r   n o t i n  

(  s e l e c t    f . d i r e c t o r 

f r o m     l m f g 

w h e r e    f . d i r e c t o r  n o t i n  

(  s e l e c t   d i r e c t o r  

f r o m     l m 

w h e r e   a c t o r = g . a c t o r   ) ) 

( i v ) Q B E :

S t a g e I  

l m t i t l e d i r e c t o r a c t o r  

:  d a 

b a d - d i r e c t o r s d i r e c t o r  

I .  d 

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 9/12

S t a g e I I  

l m t i t l e d i r e c t o r a c t o r  

b a d - d i r e c t o r s d i r e c t o r  

:  d 

a n s w e r d i r e c t o r  

I .  d 

3 . ( a ) T r u e . T h e p r o o f u s e s d i s t r i b u t i v i t y o f e x i s t e n t i a l q u a n t i c a t i o n  

o v e r d i s j u n c t i o n .

( b ) F a l s e ( n o t e t h a t t h i s s a y s , e s s e n t i a l l y , t h a t e x i s t e n t i a l q u a n t i c a  

t i o n d i s t r i b u t e s o v e r c o n j u n c t i o n ) . A c o u n t e r e x a m p l e i s :

R A B 

0 0 

S A B 

0 1 

( c ) F a l s e . S a m e c o u n t e r x a m p l e a s f o r ( b ) .

4 . O n e w a y t o m a k e t h e e v a l u a t i o n m o r e e c i e n t i s t o r e w r i t e t h e q u e r y  

a s 

 

d i r e c t o r  

   

t i t l e ; d i r e c t o r  

(  m o v i e  )  1   

t i t l e  

(   

t h e a t e r  6= "  C o v e  " 

(  s c h e d u l e  ) ) ]

T h i s c u t s d o w n t h e s i z e o f r e l a t i o n s p a r t i c i p a t i n g i n t h e j o i n a n d a v o i d s  

b u i l d i n g u p a n u n n e c e s s a r i l y l a r g e i n t e r m e d i a t e r e s u l t ( r e s u l t i n g f r o m  

t h e j o i n ) .

5 . C o n s i d e r t h e f o l l o w i n g r s p j a l g e b r a q u e r y (  R  i s a r e l a t i o n w i t h a t -  

t r i b u t e s   A B C  ) :

 

A C 

   

A B 

(  R  )  1   

B C 

(  R  ) ] 1   

   

A C 

(  R  )  1   

C B 

(  R  ) ] :

( a ) T h e t a b l e a u c o r r e s p o n d i n g t o t h e q u e r y i s :

A B C 

a b 

a b 

a c 

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 10/12

( b ) T h e r e i s a h o m o m o r p h i s m o f t h e t a b l e a u m a p p i n g t h e 2 n d a n d  

3 r d r o w s t o t h e r s t . S o t h e m i n i m i z e d t a b l e a u i s :

A B C 

a b 

a c 

( c ) A n r s p j a l g e b r a q u e r y c o r r e s p o n d i n g t o t h e m i n i m i z e d t a b l e a u i s :

 

A C 

(   

A B 

(  R  )  1   

B C 

(  R  ) )  :

( d ) R e d o ( a ) , ( b ) , ( c ) f o r t h e q u e r y :

 

A C 

   

A B 

(  R  )  1   

B C 

(   

B  = 8 

(  R  ) ) ] 1   

   

A C 

(   

A  = 5 

(  R  ) )  1   

C B 

(  R  ) ] :

T h e c o r r e s p o n d i n g t a b l e a u i s :

A B C 

5 8  c 

8  c 

5  b 

5  c 

T h e l a s t t w o r o w s c a n b e m a p p e d t o t h e r s t . T h e m i n i m i z e d  

t a b l e a u i s :

A B C 

5 8  c 

8  c 

5  c 

A c o r r e s p o n d i n g a l g e b r a q u e r y i s :

 

A C 

(   

A  = 5 

 

B  = 8 

(  R  ) )  1   

(   

B  = 8 

(  R  ) )  :

1 0 

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 11/12

6 . ( i ) T h e t a b l e a u   T  c o r r e s p o n d i n g t o   q  i s 

A B C 

a b 

b c 

b c 

a b c 

C h a s i n g w i t h r e s p e c t t o =   f  A C  !  B ; B  !  C ; C  !  A  g  y i e l d s :

C H A S E  

 

(  T  ) = 

A B C 

a b c 

a b c 

a b c 

a b 

a b c 

E l i m i n a t i n g d u p l i c a t e r o w s f r o m   C H A S E  

 

(  T  ) y i e l d s t h e m i n i m a l t a b l e a u :

A B C 

a b c 

a b 

a b c 

a n d t h e c o r r e s p o n d i n g r s p j q u e r y i s  

 

A B 

(  R  )  1   

A C 

(  R  )  :

( i i ) T h e t a b l e a u   T  c o r r e s p o n d i n g t o   q  i s 

A B C 

a b 

b  5 

8  b c 

8  b 

a b c 

C h a s i n g w i t h r e s p e c t t o =   f  A C  !  B ; B  !  C ; C  !  A  g  y i e l d s ( a f t e r  

e l i m i n a t i n g d u p l i c a t e r o w s ) :

1 1 

7/28/2019 Sol Practice1

http://slidepdf.com/reader/full/sol-practice1 12/12

C H A S E  

 

(  T  ) = 

A B C 

8  b  5 

8  b 

a b c 

T h i s t a b l u e a u i s m i n i m a l , a n d t h e c o r r e s p o n d i n g r s p j q u e r y i s  

 

A B 

(   

A  = 8 

(   

C  = 5 

(  R  ) ) )  1   

A C 

(   

A  = 8 

(  R  ) )  :

1 2