This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: York University COSC 3101 Fall 2004 – Midterm (Nov 4) Instructor: Jeff Edmonds 1. 2 × 9 = 18 marks: Compute the solution and tell which rules that you use. (a) ∑ n i =0 3 i × i 8 = Θ( Type of sum: • Answer: Θ(3 n × n 8 ), Geometric. (b) ∑ n i =0 300 i 2 log 9 i + 7 i 3 log 2 i + 16 = Θ( Type of sum: • Answer: Θ( n 4 log 2 n ), Arithmetic. (c) ∑ n i =0 ∑ n j =0 i 2 j 3 = Θ( • Answer: ∑ n i =1 ∑ n j =0 i 2 j 3 = ∑ n i =1 i 2 [ ∑ n j =0 j 3 ] = ∑ n i =1 i 2 Θ( n 4 ) = Θ( n 4 )[ ∑ n i =1 i 2 ] = Θ( n 4 )Θ( n 3 ) = Θ( n 7 ) (d) 7 · 2 3 · n 5 = 3 Θ( n 5 ) True False • Answer: True (e) What is the formal definition of f ( n ) = n Θ(1) ? • Answer: ∃ c 1 > , c 2 > , n , ∀ n ≥ n , n c 1 ≤ f ( n ) ≤ n c 2 . (f) n 2 − 100 n ∈ o ( n 2 ) True False • Answer: False (g) If T ( n ) = 8 T ( n 4 ) + Θ( n ). Then T ( n ) = Θ( • Answer: Because log a log b = log 8 log 4 = log 2 8 log 2 4 = 3 2 = 1 . 5 > 1 = c , the technique concludes that time is dominated by the base cases and T ( n ) = Θ( n log a log b ) = Θ( n 1 . 5 ) (h) The solution of the recurrence T ( n ) = 5 T ( n √ 5 ) + n 2 log( n ) is T ( n ) = Θ( • Answer: Because log a log b = log √ 5 5 log √ 5 √ 5 = 2 1 = 2 = 2 = c , the technique concludes that time is dominated by the base cases and T ( n ) = Θ( f ( n )log n ) = Θ( n 2 log 2 n ). (i) If T ( n ) = 8 T ( n − 5). Then T ( n ) = Θ( • Answer: T ( n ) = 8 T ( n − 5) = 8 2 T ( n − 2 × 5) = 8 3 T ( n − 3 × 5) = 8 i T ( n − i × 5) = Θ(8 i/ 5 ). 2. 4 marks: Consider the following priority queue implemented as a heap. Consider a reasonable algorithm that changes the prioity of a node. (Its input includes a pointer to the node). Give the resulting heap after changing the priority 7 node to have priority 48 and and the priority 45 node to 3. 18 45 22 24 10 40 35 32 23 20 7 2 16 15 12 8 51 4 1 1 • Answer: Question cut from midterm: “In three or four sentences, describe the algorithm for changing the priority of a node.” Ans: If the priority is increased, bubble it up by repeatedly comparing it to its parent and swapping if bigger. If the priority is decreased, bubble it down by repeatedly comparing it to both its children and swapping if smaller with the bigger of the two. • Answer: 18 10 35 32 23 2 16 15 12 8 51 4 1 48 40 20 24 22 3 3. 6 marks: Considering Programs. algorithm Eg 1 ( n ) ( pre − cond ) : n is an integer. ( post − cond ) : Prints “Hi”s. begin i = 0 put “Hi”; put “Hi”; put “Hi”; put “Hi” loop i = 1 . . . n put “Hi”; put “Hi”; put “Hi” loop j = 1 . . . n put “Hi”; put “Hi” end loop end loop end algorithm algorithm Eg 2 ( n ) ( pre − cond ) : n is an integer....
View
Full
Document
This note was uploaded on 12/11/2010 for the course CSE CSE 3101 taught by Professor A during the Winter '10 term at York University.
 Winter '10
 A

Click to edit the document details