{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# hw2 - algorithm assume that vertices are considered in...

This preview shows page 1. Sign up to view the full content.

Computer Science 130B Winter 2007 Homework #2 Due: 4pm, February 2nd, Friday Problem 1 Consider the coin change problem. You are at a check out register, and have an unlimited supply of quarters, dimes, nickels, and pennies. You have to make a small change for a customer. Design a greedy algorithm to make out an amount of x cents that uses the smallest number of coins. Prove the optimality of your algorithm. Problem 2 We know that a minimum-cost spanning tree links all the vertices in a connected undirected graph together in such a way that the total cost of the tree arcs is minimized. Does this fact imply that given two vertices i and j in a graph and a minimum-cost spanning tree of that graph, the shortest path from i to j must contain only the tree arcs in the minimum-cost spanning tree? If you think so, prove it, otherwise, give a counterexample. Problem 3 Consider the graph shown in figure 1. a. Find the shortest path from vertex a to vertex e using Dijkstra’s algorithm. Show intermediate steps in executing the algorithm. b. Find the minimum-cost spanning tree using both Prim’s algorithm and Kruskal’s algorithm. In Prim’s
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: algorithm, assume that vertices are considered in alphabetic order. In Kruskal’s algorithm, if two edges are of the same costs, the one which has smaller end vertices (in the alphabetical order) should be considered ±rst. Show intermediate steps in executing the algorithm. a b c d e f g h i 1 3 7 5 4 3 5 7 8 2 4 6 8 4 1 Figure 1: Problem 4 Assume n programs of length l 1 , l 2 , · · · , l n are to be stored on a tape. Program i is to be retrieved with frequency f i . If the program are stored in the order of i 1 , i 2 , · · · , i n , the expected retrieval time (ERT) is ∑ j ( f i j ∑ j k =1 l i k ) ∑ f i a. Show that storing programs in nondecreasing order of l i does not necessarily minimize ERT. b. Show that storing programs in non-increasing order of f i does not necessarily minimize ERT. c. Show that storing programs in non-increasing order of f i /l i does minimize ERT. 1...
View Full 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