Problem Set 9 - Fundamental Algorithms | CS 231, Assignments of Algorithms and Programming

Material Type: Assignment; Class: Fundamental Algorithms; Subject: Computer Science; University: Wellesley College; Term: Spring 2001;

Typology: Assignments

Pre 2010

Uploaded on 08/17/2009

koofers-user-zbq
koofers-user-zbq 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CS231 Algorithms Handout #29
Prof Lyn Turbak April 26, 2001
Wellesley College
PROBLEM SET 9
Due: Monday, May 7
Reading: Handouts 28 (Depth-First Search), 30 (P&NP), 31 (NP-Completeness); CLR
Sections 23.3--23.5 (Depth-First Search, Toplogical Sort, Strongly Connected
Components); CLR Chapter 36;
Suggested Problems: ; 23.3-9; 23.4-2, 23.4-5; 23.5-1, 23..5-3, 23.5-4, 23.5-4; 23-1, 23-
2; 36.1-2, 36.1-7; 36.2-2, 36.2-4;
Problem 1 [30] Consider the following weighted graph G (this is the same graph from
PS8 Problem 1):
a b c
def g h
ijk
3
4
5
6
7
1
2
4
8
2
7
9
2
6
15
3
10
1
In the following problems, you should assume that G is represented as a collection of
adjacency lists, and that vertices are ordered alphabetically within each adjacency list.
a [15] Draw the tree the is induced by performing a depth-first-search starting at node a.
Label each vertex by its discovery and finish times (as on CLR p. 479). Using dotted
lines, draw the edges of G that are not in the depth-first tree and label them as forward
edges (F), back edges (B), or cross edges (C).
b [5] Give a topological sort of the vertices in G.
c [10] Use the strongly connected component algorithm from CLR 23.5 to determine the
strongly connected components of G.
Problem 2 [15]
a [10] CLR 23.4-3 (p. 488).
b [5] Does your algorithm from part a work for directed graphs? Explain.
Problem 3 [15] CLR 23.4-5 (p. 488)
pf3

Partial preview of the text

Download Problem Set 9 - Fundamental Algorithms | CS 231 and more Assignments Algorithms and Programming in PDF only on Docsity!

CS231 Algorithms Handout # Prof Lyn Turbak April 26, 2001 Wellesley College

PROBLEM SET 9 Due: Monday, May 7

Reading: Handouts 28 (Depth-First Search), 30 (P&NP), 31 (NP-Completeness); CLR Sections 23.3--23.5 (Depth-First Search, Toplogical Sort, Strongly Connected Components); CLR Chapter 36;

Suggested Problems: ; 23.3-9; 23.4-2, 23.4-5; 23.5-1, 23..5-3, 23.5-4, 23.5-4; 23-1, 23- 2; 36.1-2, 36.1-7; 36.2-2, 36.2-4;

Problem 1 [30] Consider the following weighted graph G (this is the same graph from PS8 Problem 1):

a b c

d e f g h

i j k

In the following problems, you should assume that G is represented as a collection of adjacency lists, and that vertices are ordered alphabetically within each adjacency list.

a [15] Draw the tree the is induced by performing a depth-first-search starting at node a. Label each vertex by its discovery and finish times (as on CLR p. 479). Using dotted lines, draw the edges of G that are not in the depth-first tree and label them as forward edges (F), back edges (B), or cross edges (C).

b [5] Give a topological sort of the vertices in G.

c [10] Use the strongly connected component algorithm from CLR 23.5 to determine the strongly connected components of G.

Problem 2 [15]

a [10] CLR 23.4-3 (p. 488).

b [5] Does your algorithm from part a work for directed graphs? Explain.

Problem 3 [15] CLR 23.4-5 (p. 488)

Problem 4 [10]: CLR 36.1-1 (p. 923). Note that the graph is an unweighted graph, so the length of a path is just the number of edges in it. To prove the “if and only if” condition, you must show two things:

  1. If there is an algorithm that computes LONGEST-PATH-LENGTH in polynomial time, then LONGEST-PATH ∈ P.

  2. If LONGEST-PATH ∈ P, then there is an algorithm that computes LONGEST- PATH-LENGTH in polynomial time.

Problem 5 [15]: CLR 36.2-8 (p. 929).

Problem 6 [15]: CLR 36.3-2 (p. 938).

Extra Credit Problems:

Problem EC1 [15]: CLR 36.2-3 (p. 928). The problem could be rephrased as follows: Suppose you are given a black box predicate HAS-HAM-CYCLE?(G) that can determine in polynomial time whether G has a hamiltonian cycle. How could you use such a predicate to compute in polynomial time an ordered list of vertices for a hamiltonian path in a graph H for which HAS-HAM-CYCLE?(H) returns true?You do not need to give pseudocode, but need to give enough details so that it is clear how your algorithm works.

Problem EC2 [10]: CLR 36.2-7 (p. 929). Hint: Topologically sort the vertices. What must be true of the result?