MidtermPracticeProblems_Hints.pdf

# How much work is required to combine the solutions

• Test Prep
• 4
• 100% (1) 1 out of 1 people found this document helpful

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

How big is each subproblem? How much work is required to combine the solutions? Use the Master Theo- 1

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

rem to solve the resulting recurrence relation, and get that the running time is O( n log 3 2 ). 5. For this problem, a tree is an undirected graph without cycles. Show that for every pair of nodes x, y in the tree, there is exactly one path between x and y . Solution Hint: What would it mean if there were more than one path from x to y ? 6. Suppose you have a weighted, undirected tree. Show that if you run Di- jkstra’s algorithm on this tree starting from the root, then at each iteration, the known region also consists of a tree. What if you run Dijkstra’s algorithm from a different node? Solution Hint: Show that the known region is always a connected set. What would it mean if it were not a tree? 7. You are given an array A of length n . Each value is 1. However, you do not know what the value of n is. You are allowed to access an element i of the array by calling A [ i ] If i < n , this will return 1, and if i n , this will return a message saying that the location does not exist (you can think of this as an error message, but it will not crash your program). Describe an O(log n ) algorithm to determine the value of n . Solution Hint: This is a variation on binary search! 8. Suppose you want to implement the merge operation from MergeSort, but instead of merging 2 arrays, you want to merge k arrays, each of length n . a. You can do this by first merging the first array and the second array, and then merging the result with the third array, and then merging the result with the fourth array, etc. What is the running time of the described algorithm?
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