finsolgg

Therefore t n is o n log n grading guidelines a 15

Info iconThis preview shows pages 6–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Therefore T ( n ) is O ( n log n ). Grading guidelines: (a) 15 points total; 5 points for correct and explicit analysis of for loops; 5 points for correct and explicit analysis of recursive calls; 3 points for correctly stating that the complexity of array creation is O (1); 2 points for correct recurrence relation. (b) 10 points total; 5 points for correctly solving the recurrence; but you lose 2 if no base case stated; finally 5 points for correct final answer O ( nlogn ). 8. (40 pts) For each statement below, decide whether it is true or false. In each case attach a very brief explanation of your answer. (a) In a binary min-heap both the smallest and the largest key are on leaves, true or false? Answer: FALSE. The largest key must be on a leaf but the smallest key is on the root. (b) In a binary search tree both the smallest and the largest key are on leaves, true or false? Answer: FALSE. Neither has to be on a leaf. The smallest key must be a on a node without left child but the node may have a right child. The largest key must be a on a node without right child but the node may have a left child. (c) The worst-case complexity of inserting n keys in an (empty to begin with) hash-table with open addressing and linear probing is O ( n 2 ), true or false? Answer: TRUE. For example if the keys are consecutive integers. (d) There exists a function f ( n ) such that f ( n ) is Ω( n 2 ) and is O ( n 3 ) but is neither Θ( n 2 ) nor Θ( n 3 ), true or false? Answer: TRUE. For example, f ( n ) = n 2 n or f ( n ) = n 2 log n . (e) There exist undirected graphs on which BFS traversal takes time Θ( | V | ), true or false? Answer: TRUE. For example, if the graph has no edges. (f) We can compute the strongly connected components of a DAG in time O ( | V | ), true or false? Answer: TRUE. In a DAG the strongly connected components consist of single nodes. To compute them just scan the array of nodes. 6
Background image of page 6

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
(g) Let G be a digraph with n nodes and s one of its nodes. The discovery edges found by DFS starting from s always form a tree with n - 1 edges, true or false? Answer: FALSE. They form a tree but the nodes in this tree are only those nodes reachable by a path from s and there may be strictly less than n such nodes, therefore the tree may have strictly less than n - 1 edges. (h) In a 4-way trie we store 3 distinct keys, each of them a 2-character string. The resulting trie can have as many as 22 null links, true or false? Answer: TRUE. The trie is largest of all 3 keys have a different first character. Then there 1 null link from the root, 9 null links from the 3 nodes at depth 1, and 12 null links from the 3 nodes at depth 2. 1 + 9 + 12 = 22. Grading guidelines: As usual: 2 points for correct true or false statement; 3 points for for correct explanation. 9. (20pts) Consider the following undirected weighted graph (five nodes labeled A,B,C,D,E,F and the edge weights are either 1 or 3 as shown). We use Dijkstra’s algorithm to compute the lengths of the shortest paths from A to the other nodes. ! # $ % ' ( ( ( ( ( ( ) ) ) ) (a) Dijkstra’s algorithm begins by relaxing the edges
Background image of page 7
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page6 / 11

Therefore T n is O n log n Grading guidelines a 15 points...

This preview shows document pages 6 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online