Give a linear-time algorithm to find an odd-length cycle in a directed graph. (Hint: First solve this problem under the assumption that the graph is strongly connected.)
Let the graph be denoted as G. We can find out if has odd cycle in two ways.
Method 1:
Here we have to note that a directed graph has an odd-length directed cycle if and only if one (or more) of its strong components is non-bipartite.
Indirectly, if we can check whether the graph is bipartite, it means no odd cycle exists in graph. If it is not a bipartite graph it simply implies it can have odd cycle.
A graph is bipartite if and only if it is 2 colorable.
Algorithm steps:
Method 2:
In this method , we keep a track of all nodes visited.
Algorithm steps:
Both the methods take the linear time complexity that O(n) since we are traversing the whole graph. n is number of nodes in G.
Give a linear-time algorithm to find an odd-length cycle in a directed graph. (Hint: First solve...
Suppose is a directed graph represented by a adjacency lists. Divise a linear time algorithm that, given such a , returns a list of all the source vertices of . (Note, this list may be empty.) Prove your algorithm runs in -time. Hint: There is a simple solution that does not involve any DFS’s or BFS’s. G (V. E) We were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this image
Given an undirected graph that is a tree, give a linear time algorithm to find the two leaves in the tree that have the minimum distance between them.
Problem 5. (12 marks) Connectivity in undirected graphs vs. directed graphs. a. (8 marks) Prove that in any connected undirected graph G- (V, E) with VI > 2, there are at least two vertices u, u є V whose removal (along with all the edges that touch them) leaves G still connected. Propose an efficient algorithm to find two such vertices. (Hint: The algorithm should be based on the proof or the proof should be based on the algorithm.) b....
(10) Sketch an algorithm, in pseudocode, to find and return a shortest cycle in a graph, if one exists. You may return null or empty list or something like that if none exists. a) To avoid reinventing the wheel, you should use an algorithm, or parts of algorithms, presented in class. b) Assume the graph is directed, connected, and unweighted. c) Efficiency is not a concern (as long as your solution remains polynomial).
Given a directed graph G, give an algorithm that tests if G is acyclic. Analyze running time.
2. Design a deterministic algorithm to solve the following problem. input: A directed acyclic graph G = (V, E) stored using adjacency lists. output: A Hamiltonian path, if such a path exists. Otherwise, return NONE. Your algorithm must take O(|V| + |E|) time. You must describe your algorithm in plain English (no pseudocode) and you must explain why the running time of your algorithm is O(|V| + |E|). Maximum half a page
Consider the following directed graph for each of the problems: 1. Perform a breadth-first search on the graph assuming that the vertices and adjacency lists are listed in alphabetical order. Show the breadth-first search tree that is generated. 2. Perform a depth-first search on the graph assuming that the vertices and adjacency lists are listed in alphabetical order. Classify each edge as tree, back or cross edge. Label each vertex with its start and finish time. 3. Remove all the...
Please show your work 3. Give an efficient algorithm that takes as input a directed graph G-(V,E) with edges labeled with either 0 or 1, and vertices s and t that ouputs TRUE if and only if there is a path (not necessarily simple) that goes from s to t such that the binary sequence of edges in the path avoids the substring "11" and outputs FALSE otherwise. (For example, the string 10100010 avoids 11 but the string 00101101110 does...
ALGORITHM DESIGN Given a connected weighted graph, give a scheme to find the farthest node from a given source node. Note that you do not have to start from scratch, but use a known standard algorithm. Hint: Make sure use of a known algorithm for finding the shortest paths.
Give an efficient algorithm that takes a directed graph G = (V, E) and two vertices u, v E V, and determines if there are at least two edge-disjoint paths in G from u to v. i.e., your algorithm should determine whether there are at least two paths from u to v in G that have no edges in common. Argue your algorithm's correctness and analyze its time complexity.