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

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

View Full Document Right Arrow Icon
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 ±gure 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
Background image of page 1
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 Kruskals 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

This note was uploaded on 08/06/2008 for the course CS 130B taught by Professor Suri during the Winter '08 term at UCSB.

Ask a homework question - tutors are online