{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

quiz2 - Introduction to Algorithms Massachusetts Institute...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Algorithms November 17, 2011 Massachusetts Institute of Technology 6.006 Fall 2011 Professors Erik Demaine and Srini Devadas Quiz 2 Solutions Quiz 2 Solutions Problem 1. [1 points] Write your name on top of each page. Problem 2. True/False [28 points] (14 parts) Circle (T)rue or (F)alse. You don’t need to justify your choice. (a) T F [2 points] Computing b a c for an n -bit positive integer a can be done in O (lg n ) iterations of Newton’s method. Solution: True. This is the bound obtained by Newton’s Method’s quadratic convergence. (b) T F [2 points] Suppose we want to solve a polynomial equation f ( x ) = 0 . While our choice of initial approximation x 0 will affect how quickly Newton’s method converges, it will always converge eventually. Solution: False. Take e.g. f ( x ) = x 3 - 2 x +2 and x 0 = 0 . Then x 2 i +1 = 1 and x 2 i = 0 for all i (that is, the approximations alternate between 0 and 1 without ever converging). (c) T F [2 points] Karatsuba’s integer multiplication algorithm always runs faster than the grade-school integer multiplication algorithm. Solution: False. Problem Set 5 has shown that the O ( N 2 ) algorithm runs faster for small numbers. (d) T F [2 points] If we convert an n -digit base-256 number into base 2, the resulting number of digits is Θ( n 2 ) . Solution: False. log 256 n = log 2 n = log 2 n log 256 8 . By converting a base-256 number to base 2, the number of digits is 2 multiplied by 8. For all b 1 , b 2 = 1 , converting a base- b 1 number to base- b 2 results in a linear increase or decrease in the number of digits. (e) T F [2 points] In a weighted undirected graph G = ( V, E, w ) , breadth-first search from a vertex s finds single-source shortest paths from s (via parent pointers) in O ( V + E ) time. Solution: False. Only in unweighted graphs. (f) T F [2 points] In a weighted undirected tree G = ( V, E, w ) , breadth-first search from a vertex s finds single-source shortest paths from s (via parent pointers) in O ( V + E ) time. 6
Image of page 1

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

View Full Document Right Arrow Icon
6.006 Quiz 2 Solutions Name 2 Solution: True. In a tree, there is only one path between two vertices, and breadth-first search finds it. (g) T F [2 points] In a weighted undirected tree G = ( V, E, w ) , depth -first search from a vertex s finds single-source shortest paths from s (via parent pointers) in O ( V + E ) time. Solution: True. In a tree, there is only one path between two vertices, and depth-first search finds it. (h) T F [2 points] If a graph represents tasks and their interdependencies (i.e., an edge ( u, v ) indicates that u must happen before v happens), then the breadth-first search order of vertices is a valid order in which to tackle the tasks. Solution: No, you’d prefer depth-first search, which can easily be used to pro- duce a topological sort of the graph, which would correspond to a valid task order. BFS can produce incorrect results. (i) T F [2 points] Dijkstra’s shortest-path algorithm may relax an edge more than once in a graph with a cycle.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern