This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: COT5405 Analysis of Algorithms Homework 3 Solutions 1. Prove or give a counter example: (a) In the textbook, we have two routines for graph traversal - DFS( G ) and BFS( G , s ) - where G is a graph and s is any node in G . These two procedures will create a DFS tree and a BFS tree respectively. If G = ( V, E ) is a connected, undirected graph then the height of DFS( G ) tree is always larger than or equal to the height of any of the BFS trees created by BFS( G , s ). Answer 1 2 3 4 5 Counter example: The DFS can start from any arbitrary node. So we pick the center node. For BFS we pick any of the boundary nodes. Then the height of DFS tree is 1, whereas the height of BFS tree is 2. For this problem, if you make an assumption that DFS and BFS always start at the same node and prove that the height of the DFS tree is always larger than that of BFS tree, then also you’ll get credit – if your proof is good. (b) BFS and DFS algorithms on a undirected, connected graph G = ( V, E ), produce the same tree if and only if G is a tree. Answer First we show that G is a tree when both BFS-tree and DFS-tree are same. If G and T are not same, then there should exist an edge e ( u, v ) in G , that does not belong to T . In such a case: 1 – in the DFS-tree, one of the u or v , should be an ancestor of the other. – in the BFS-tree, u and v can differ by only one level. Since, both DFS-tree and BFS-tree are same tree T , it follows that one of u and v should be an ancestor of the other and they can differ by only one level. This implies that the edge connecting them must be in T . So, there can not be any edges in G which are not in T . In the second part of the proof: Since G is a tree, each node has a unique path from the root. So, both BFS and DFS produce the same tree, and the tree is same as G . 2. When an adjacency-matrix representation is used, most graph algorithms require time Ω( V 2 ), but there are some exceptions. Show that determining whether a directed graph G contains a universal sink – a vertex with in-degree | V | - 1 and out-degree 0 – can be determined in time O ( V ), given an adjacency matrix for G . Answer We are looking for a universal sink i.e. a vertex in degree of | V | - 1 and out degree of zero. In the adjacent matrix the elements the element in row i represent the edges that are out-going from node i to other nodes. And the elements in column j represent the edges that are in-coming to node j . The task is to find k , such that row k has all zero’s and column k has all 1 ′ s except for the element in row k (which is a zero)....
View Full Document
This note was uploaded on 01/15/2012 for the course COT 5405 taught by Professor Ungor during the Fall '08 term at University of Florida.
- Fall '08