Solutions to Homework 3

Similar documents
Solutions to Homework 6

Connectivity and cuts

Analysis of Algorithms, I

Midterm Practice Problems

Social Media Mining. Graph Essentials

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Data Structures and Algorithms Written Examination

CS 598CSC: Combinatorial Optimization Lecture date: 2/4/2010

each college c i C has a capacity q i - the maximum number of students it will admit

Triangle deletion. Ernie Croot. February 3, 2010

HOMEWORK 5 SOLUTIONS. n!f n (1) lim. ln x n! + xn x. 1 = G n 1 (x). (2) k + 1 n. (n 1)!

V. Adamchik 1. Graph Theory. Victor Adamchik. Fall of 2005

Lecture 22: November 10

Lecture 1: Course overview, circuits, and formulas

Full and Complete Binary Trees

SHARP BOUNDS FOR THE SUM OF THE SQUARES OF THE DEGREES OF A GRAPH

Finding and counting given length cycles

Binary Search Trees CMPSC 122

Every tree contains a large induced subgraph with all degrees odd

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Simplified External memory Algorithms for Planar DAGs. July 2004

Handout #Ch7 San Skulrattanakulchai Gustavus Adolphus College Dec 6, Chapter 7: Digraphs

Any two nodes which are connected by an edge in a graph are called adjacent node.

Lecture 15 An Arithmetic Circuit Lowerbound and Flows in Graphs

Sample Questions Csci 1112 A. Bellaachia

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

CS473 - Algorithms I

Data Structure [Question Bank]

CS311H. Prof: Peter Stone. Department of Computer Science The University of Texas at Austin

On the k-path cover problem for cacti

Institut für Informatik Lehrstuhl Theoretische Informatik I / Komplexitätstheorie. An Iterative Compression Algorithm for Vertex Cover

DATA ANALYSIS II. Matrix Algorithms

8.1 Min Degree Spanning Tree

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

THE PROBLEM WORMS (1) WORMS (2) THE PROBLEM OF WORM PROPAGATION/PREVENTION THE MINIMUM VERTEX COVER PROBLEM

Graph Theory Problems and Solutions

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

P. Jeyanthi and N. Angel Benseera

Near Optimal Solutions

Introduction to Graph Theory

GRAPH THEORY LECTURE 4: TREES

Cycles in a Graph Whose Lengths Differ by One or Two

Math 55: Discrete Mathematics

Scheduling Shop Scheduling. Tim Nieberg

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

Distributed Computing over Communication Networks: Maximal Independent Set

A Fast Algorithm For Finding Hamilton Cycles

SCORE SETS IN ORIENTED GRAPHS

Graphical degree sequences and realizations

Mathematical Induction. Lecture 10-11

Tree-representation of set families and applications to combinatorial decompositions

CIS 700: algorithms for Big Data

Data Structures. Chapter 8

A 2-factor in which each cycle has long length in claw-free graphs

5.1 Bipartite Matching

Large induced subgraphs with all degrees odd

Discrete Mathematics Problems

Reading 13 : Finite State Automata and Regular Expressions

Mathematics for Algorithm and System Analysis

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Answer: (a) Since we cannot repeat men on the committee, and the order we select them in does not matter, ( )

An inequality for the group chromatic number of a graph

Data Structure with C

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

8. Matchings and Factors

Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally

Sum of Degrees of Vertices Theorem

Cpt S 223. School of EECS, WSU

Graph Theory Lecture 3: Sum of Degrees Formulas, Planar Graphs, and Euler s Theorem Spring 2014 Morgan Schreffler Office: POT 902

Chapter 6: Graph Theory

A Turán Type Problem Concerning the Powers of the Degrees of a Graph

Generating Elementary Combinatorial Objects

Graphs without proper subgraphs of minimum degree 3 and short cycles

Analysis of Algorithms I: Binary Search Trees

Mean Ramsey-Turán numbers

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

INDISTINGUISHABILITY OF ABSOLUTELY CONTINUOUS AND SINGULAR DISTRIBUTIONS

The Goldberg Rao Algorithm for the Maximum Flow Problem

Definition Given a graph G on n vertices, we define the following quantities:

Reminder: Complexity (1) Parallel Complexity Theory. Reminder: Complexity (2) Complexity-new

3. Eulerian and Hamiltonian Graphs

Sample Induction Proofs

Class One: Degree Sequences

Strategic Deployment in Graphs. 1 Introduction. v 1 = v s. v 2. v 4. e 1. e e 3. e 2. e 4

Polytope Examples (PolyComp Fukuda) Matching Polytope 1

Network (Tree) Topology Inference Based on Prüfer Sequence

SEQUENCES OF MAXIMAL DEGREE VERTICES IN GRAPHS. Nickolay Khadzhiivanov, Nedyalko Nenov

Introduced by Stuart Kauffman (ca. 1986) as a tunable family of fitness landscapes.

Even Faster Algorithm for Set Splitting!

Simple Graphs Degrees, Isomorphism, Paths

Exponential time algorithms for graph coloring

136 CHAPTER 4. INDUCTION, GRAPHS AND TREES

Transcription:

Solutions to Homework 3 Debasish Das EECS Department, Northwestern University ddas@northwestern.edu 1 Problem 2.4 Recurrence for Algorithm A Using Master s theorem we get a bound of O(n log 5 ). Recurrence for Algorithm B T (n) = 5T ( n ) + O(n) (1) 2 T (n) = 2T (n 1) + O(1) (2) The idea to solve such recurrence is to use a recursion tree and combine the constant time operation at each level of recursion tree. Alternatively you can use substitution. T (n) = 2T (n 1) + O(1) T (n 1) = 2T (n 2) + O(1)... T (2) = 2T (1) + O(1) Substituting the values of T(i-1) into the equation of T(i), we get the following sum n 1 T (n) = 2 i O(1) (3) Thus we obtain T(n) as O(2 n ) Recurrence for Algorithm C i=0 T (n) = 9T ( n 3 ) + O(n2 ) (4) Using Master s theorem we get O(n 2 log n) If we do an order analysis, it turns out that Algorithm C is most efficient, since log n grows slower than n log 5 2. 1

2 Problem 2.12 In this problem we have to give an recurrence for the number of lines printed by the algorithm. The recurrence is given as follows L(n) = { 1 + 2L( n 2 ) if n > 1 0 if n = 1 (5) Theorem 1 L(n) = Θ(n) Proof: Base Case: L(1) = 0 which is Θ(1) Hypothesis: c 1 k L(k) c 2 (k-1), k < n Induction: L(n) = 1 + 2L( n 2 ) 1 + 2(c 1 n 2 )=1+c 1n=k 1 n where k 1 is a constant equal to c 1 + 1 n Similarly for the other bound, L(n) = 1 + 2L( n 2 ) 1 + 2(c 2 ( n 2 1)) = 1+c 2n - 2c 2 = k 2 (n-1) where k 2 = c 2 (c2 1) (n 1) Using above result we can say that L(n) is Θ(n). We can do a more accurate analysis using recursion tree and establish that the line will be printed n-1 times, which is still Θ(n). 3 Problem 2.14 Given an array of n elements, we need to remove the duplicate elements from the array in O(n log n) time. Idea is to maintain the order of elements in the array after the duplicates are removed. The following example explains the idea. Let the array A has following numbers: 2 3 1 3 1 4. Once the duplicate numbers are removed the output array should be 2 3 1 4. Note that the order of elements in the final output array is maintained. In other words the final array is not sorted. function remove-duplicate(a[1...n]) Input: An array of numbers a[1...n] Output: Array A with duplicates removed Construct an array temp[1..n]: temp[i] has two fields key and value for i = 1 to n temp[i].value = a[i] temp[i].key = i sort temp based on value remove duplicates from temp based on value: keep the entry with minimum key sort temp based on key construct array A from temp: A[i] = temp[i].value return A 2

The field key helps in keeping the order of elements in output array. Two sort takes O(n log n). Duplicate removal considering key is O(n). Therefore the algorithm is O(n log n). If we don t consider maintaining the order of the original array in the output array the algorithm can be simply given as function remove-duplicate(a[1...n]) Input: An array of numbers a[1...n] Output: Array A with duplicates removed sort a construct array A from a: by removing duplicate entries from a return A 4 Problem 3.5 Given a graph G = (V,E) we have th find another graph G R = (V, E R ) where E R = (v, u) : (u, v) E. We assume that each edge e has a source vertex u and a sink vertex v associated with it. function find-reverse(g) Input: Graph G = (V,E) in adjacency list representation Output: Graph G R Generate all edges e E using any traversal Construct adjacency list G R : vertex set = V For each generated edge e temp = e.source e.source = e.sink e.sink = temp insert e into G R return G R Complexity Analysis: All edges can be generated in O(V + E). Edges can be modified and new adjacency list can be populated in O(E). Therefore the algorithm is linear. 5 Problem 3.7 A bipartite graph G=(V,E) is a graph whose vertices can be partitioned into two sets (V=V 1 V 2 and V 1 V 2 = such that there are no edges between vertices in the same set.formally u, v V 1 (u, v) / E u, v V 2 (u, v) / E 3

(a)we use the property given in (b) to get a linear time algorithm to determine whether a graph is bipartite. The property says that an undirected graph is bipartite if it can be colored by two colors. The algorithm we present is a modified DFS that colors the graph using 2 colors. Whenever an back-edge, forward-edge or cross-edge is encountered, the algorithm checks whether 2-coloring still holds. function graph-coloring(g) Input: Graph G Output: returns true if the graph is bipartite false otherwise for all v V: visited(v)= false color(v) = GREY while s V : visited(s) = false visited(s) = true color(s) = WHITE S = [s] (stack containing v) while S is not empty u = pop(s) for all edges (u,v) E: if visited(v) = false: visited[v] = true push(s,v) if color(v) = GREY if color(u) = BLACK: color(v) = WHITE if color(u) = WHITE: color(v) = BLACK else if color(v) = WHITE: if color(u) BLACK: return false else if color(v) = BLACK: if color(u) WHITE: return false return true (b) Lemma 1 An undirected graph is bipartite if and only if it contains no cyles of odd length Proof: Consider a path P whose start vertex is s, end vertex is t and it passes through vertices u 1, u 2,..., u n and the associated edges are (s, u 1 ), (u 1, u 2 ),..., (u n, t). Now if P is a cycle, then s and t are the same vertices. Without loss of generality assume s is in V 1. Each edge (u i, u i+1 ) goes from one vertex set to other. Therefore a path must have 2 i edges to come back into the same vertex set where i N. Since s and t are in same vertex set, so the length of the cycle formed must be 2 i which is even. Suppose the graph has a cycle of odd length. Let the cycle be C and it 4

passes through vertices u 1, u 2,..., u n where u 1 = u n. The associated edges are (u 1, u 2 ),..., (u n 1, u n ). We start coloring edges of using two colors WHITE and BLACK. Without any loss of generality u 1 is colored WHITE while u n 1 is colored BLACK since n is odd and therefore n 1 is even. Choosing color of u n as WHITE conflicts with the color of u n 1 while choosing color as BLACK conflicts with the color of u 1. Therefore it is not possible to color an odd cycle with 2 colors which implies that the graph is not bipartite(using the property mentioned in (b)) (c)3. It follows from the proof of part (b). 6 Problem 3.13 (a) Lemma 2 In any connected undirected graph G=(V,E) there is a vertex v V whose removal leaves G connected Proof: Consider a graph G=(V,E) and a Depth-first-search tree T constructed from the graph using DFS. Given any connected graph, generation of T is linear time O(V+E) and there exist one unique tree T. Denote the leaves of the tree T by L(T). If we choose any vertex v L(T), removal of that vertex and the edges associated with it will keep T connected (by the definition of tree). Thus ˆT = T - {v} is connected which implies that the graph Ĝ=(V-{v},E- {(i, j) : i = v j = v}) is connected since ˆT and Ĝ are isomorphic. (b)see Figure 1(a) (c)see Figure 1(b) Figure 1: Examples for 3.13(b) and 3.13(c) 5