# Answer true for example if the keys are consecutive

This preview shows pages 6–9. Sign up to view the full content.

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

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

View Full Document
(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 A-B, A-C and A-D . After these relaxations, what are the distances computed so far from A to B and to C ? Answer: Distance to B is 3. Distance to C is 1. 7
(b) Which edges does Dijkstra’s algorithm relax in the second round? Answer: C-B, C-D, C-E, C-F . (c) After the second round, what is the distance computed from A to E ? Answer: 4. (d) What is the last edge that needs to be relaxed for the algorithm to finally compute the correct shortest distance from A to E ? Answer: B-E . Grading guidelines: 5pts for each of the 4 parts. For part (b) you lose 1pt for each incorrect edge. 10. (20pts) We define a node r in a digraph G to be “potential root” if for any other node v in G there exists a directed path from r to v . (a) Draw a digraph in which every node is a potential root. Answer: Any directed cycle would do. (b) Draw a digraph without any potential roots. Answer: u-->v<--w (c) Give the pseudocode of an efficient algorithm that takes a digraph as input and finds out whether it has any potential roots. (The more efficient your algorithm, the more points you get.) Answer: Here is a first solution. For each node v we can perform directed DFS starting from v and then count the marked nodes. If there are | V | of them then v is a potential root. This takes time O ( | V | ( | E | + | V | )).

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern