0% found this document useful (0 votes)
47 views

Assignment 4

This document contains instructions for 4 exercises on graph algorithms and data structures for an assignment. Exercise 1 involves drawing a graph from adjacency lists and performing DFS and BFS searches. Exercise 2 asks whether a greedy shortest path algorithm always works. Exercise 3 applies minimum spanning tree and shortest path algorithms to a weighted graph. Exercise 4 sorts a list of numbers using bubble sort, merge sort, and quicksort, showing steps.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Assignment 4

This document contains instructions for 4 exercises on graph algorithms and data structures for an assignment. Exercise 1 involves drawing a graph from adjacency lists and performing DFS and BFS searches. Exercise 2 asks whether a greedy shortest path algorithm always works. Exercise 3 applies minimum spanning tree and shortest path algorithms to a weighted graph. Exercise 4 sorts a list of numbers using bubble sort, merge sort, and quicksort, showing steps.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSI2114 - Spring 2006 - Assignment # 4

Due: July 12, 2006

Exercise 1. [10 points]

Suppose that graph G has the following adjacency lists:

1 - (2; 3; 4)
2 - (1; 5)
3 - (1; 4; 5; 6)
4 - (1; 3; 6)
5 - (2; 3; 6; 7; 8)
6 - (3; 4; 5; 9)
7 - (5; 8; 9)
8 - (5; 7)
9 - (6; 7; 8)

a) Draw G.
b) Give the sequence of vertices visited using depth-first search starting at vertex 1.
c) Give the sequence of vertices visited using breadth-first search starting at vertex 1.

Exercise 2. [10 points]

Consider the following greedy strategy for finding shortest path from vertex start to
vertex goal in a given connected graph.

1. Initialize path to start.


2. Initialize VisitedVertices to {start}.
3. If start = goal, return path and exit; otherwise, continue.
4. Find the edge (start, v) of minimum weight such that v is adjacent to start and v is
not in VisitedVertices.
5. Add v to path.
6. Add v to VisitedVertices.
7. Set start equal to v and go to step 3.

Does this greedy strategy always find a shortest path from start to goal? Either explain
intuitively why it works, or give a counter example.
Exercise 3. [15 points]

Consider the following graph (weights are shown on the edges). Showing all intermediate
steps,

8
b f

2 7 3
1
2

3 3 6
a c e g i

1
1
8
4
7

d h
7

a) Find the minimum spanning tree using Kruskal’s algorithm.


b) Find the minimum spanning tree using Prim’s algorithm.
c) Find the shortest path from a to i using Dijkstra’s algorithm.

Exercise 4. [15 points]

Consider the sequence of keys {2, 12, 16, 15, 8, 18, 14, 6, 21, 7, 20, 5}. Sort the keys
(showing all the intermediate steps) using:

a) Bubblesort
b) Merge Sort
c) Quick Sort

You might also like