GATE Overflow - Recent questions tagged graph-algorithms
https://gateoverflow.in/tag/graph-algorithms
Powered by Question2AnswerCormen Edition 3 Exercise 22.2 Question 8 (Page No. 539)
https://gateoverflow.in/326019/cormen-edition-3-exercise-22-2-question-8-page-no-539
<p><span style="font-size: larger;">The diameter of a tree $T= (V, E)$ is defined as $max_{u,v\ \epsilon\ V}\ \delta(u,v)$, that is, the largest of all shortest-path distances in the tree. Give an efficient algorithm to compute the diameter of a tree, and analyze the running time of your algorithm.</span></p>Algorithmshttps://gateoverflow.in/326019/cormen-edition-3-exercise-22-2-question-8-page-no-539Tue, 12 Nov 2019 15:45:00 +0000Cormen Edition 3 Exercise 22.2 Question 7 (Page No. 539)
https://gateoverflow.in/326018/cormen-edition-3-exercise-22-2-question-7-page-no-539
<p><span style="font-size: larger;">There are two types of professional wrestlers: “babyfaces” (“good guys”) and “heels” (“bad guys”). Between any pair of professional wrestlers, there may or may not be a rivalry. Suppose we have n professional wrestlers and we have a list of r pairs of wrestlers for which there are rivalries. Give an $O(n+r)$ time algorithm that determines whether it is possible to designate some of the wrestlers as babyfaces and the remainder as heels such that each rivalry is between a babyface and a heel. If it is possible to perform such a designation, your algorithm should produce it.</span></p>Algorithmshttps://gateoverflow.in/326018/cormen-edition-3-exercise-22-2-question-7-page-no-539Tue, 12 Nov 2019 15:38:50 +0000Cormen Edition 3 Exercise 22.2 Question 6 (Page No. 539)
https://gateoverflow.in/326017/cormen-edition-3-exercise-22-2-question-6-page-no-539
Give an example of a directed graph $G=(V, E)$, a source vertex $s\ \epsilon\ V$ , and a set of tree edges $E_{\Pi}\subseteq E$ such that for each vertex $v\ \epsilon\ V$ , the unique simple path in the graph $(V, E_{\Pi})$ from s to v is a shortest path in G, yet the set of edges $E_{\Pi}$ cannot be produced by running BFS on G, no matter how the vertices are ordered in each adjacency list.Algorithmshttps://gateoverflow.in/326017/cormen-edition-3-exercise-22-2-question-6-page-no-539Tue, 12 Nov 2019 15:32:39 +0000UGCNET-June-2019-II-61
https://gateoverflow.in/316218/ugcnet-june-2019-ii-61
<p>Match List-I with List-II:</p>
<p>$$\begin{array}{|c|c|c|c|} \hline {} & \text{List-I} & {} & \text{List-II} \\ \hline (a) & \text{Prim’s algorithm} & (i) & O(V^3 \log V) \\ \hline (b) & \text{Dijkstra’s algorithm} & (ii) & O(VE^2) \\ \hline (c) & \text{Faster all-pairs shortest path} & (iii) & O(ElgV) \\ \hline (d) & \text{Edmonds-Karp algorithm} & (iv) & O(V^2) \\ \hline \end{array}$$</p>
<p>Choose the correct option from those options given below:</p>
<ol style="list-style-type:upper-alpha" type="A">
<li>(a) – (ii); (b)-(iv); (c)-(i); (d)-(iii)</li>
<li>(a) – (iii); (b)-(iv); (c)-(i); (d)-(ii)</li>
<li>(a) – (ii); (b)-(i); (c)-(iv); (d)-(iii)</li>
<li>(a) – (iii); (b)-(i); (c)-(iv); (d)-(ii)</li>
</ol>Algorithmshttps://gateoverflow.in/316218/ugcnet-june-2019-ii-61Tue, 02 Jul 2019 13:45:36 +0000GEEKS FOR GEEKS GATE 2017 MOCK
https://gateoverflow.in/314511/geeks-for-geeks-gate-2017-mock
<p>If Kruskal’s algorithm is used for finding a minimum spanning tree of a weighted graph G with n vertices and m edges and edge weights are already given in a sorted list, then, What will be the time complexity to compute the minimum cost spanning tree given that union and find operations take amortized O(1) ?</p>
<div class="mtq_question_text"> </div>
<table style="width:137px">
<tbody>
<tr>
<td style="width:31px">
<div class="mtq_css_letter_button mtq_letter_button_0">A</div>
</td>
<td style="width:94px">
<div class="mtq_answer_text">O(m logn)</div>
</td>
</tr>
<tr>
<td style="width:31px">
<div class="mtq_css_letter_button mtq_letter_button_1">B</div>
</td>
<td style="width:94px">
<div class="mtq_answer_text">O(n)</div>
</td>
</tr>
<tr>
<td style="width:31px">
<div class="mtq_css_letter_button mtq_letter_button_2">C</div>
</td>
<td style="width:94px">
<div class="mtq_answer_text">O(m)</div>
</td>
</tr>
<tr>
<td style="width:31px">
<div class="mtq_css_letter_button mtq_letter_button_3">D</div>
</td>
<td style="width:94px">
<div class="mtq_answer_text">O(n logm)</div>
</td>
</tr>
</tbody>
</table>Algorithmshttps://gateoverflow.in/314511/geeks-for-geeks-gate-2017-mockSun, 09 Jun 2019 06:08:25 +0000Difference between DAG and Multi-stage graph
https://gateoverflow.in/310910/difference-between-dag-and-multi-stage-graph
I have trouble understanding the difference between DAG and Multi-stage graph. I know what each of them is<br />
<br />
But I think that a multi-stage graph is also a DAG. Are multi-stage graphs a special kind of DAG?Graph Theoryhttps://gateoverflow.in/310910/difference-between-dag-and-multi-stage-graphSun, 28 Apr 2019 10:55:21 +0000Cormen Edition 3 Exercise 22.1 Question 8 (Page No. 593)
https://gateoverflow.in/309198/cormen-edition-3-exercise-22-1-question-8-page-no-593
Suppose that instead of a linked list, each array entry $adj[u]$ is a hash table containing the vertices $v$ for which $(u,v) \in E$. If all edge lookups are equally likely, what is the expected time to determine whether an edge is in the graph? What disadvantages does this scheme have ? Suggest an alternate data structure for each edge list that solves these problems. Does your alternative have disadvantages compared to the hash table ?Algorithmshttps://gateoverflow.in/309198/cormen-edition-3-exercise-22-1-question-8-page-no-593Sun, 07 Apr 2019 03:53:40 +0000Cormen Edition 3 Exercise 22.1 Question 6 (Page No. 593)
https://gateoverflow.in/309193/cormen-edition-3-exercise-22-1-question-6-page-no-593
<p>Most graph algorithms that take an adjacency-matrix representation as input require time $\Omega(V^2)$,but there are some exceptions. Show how to determine whether a directed graph $G$ contains a <strong>universal link</strong> $-$ a vertex with in-degree $|V-1|$ and out-degree $0$ in time $O(V)$ , given an adjacency matrix for $G$.</p>Algorithmshttps://gateoverflow.in/309193/cormen-edition-3-exercise-22-1-question-6-page-no-593Sun, 07 Apr 2019 03:26:26 +0000Cormen Edition 3 Exercise 22.1 Question 5 (Page No. 593)
https://gateoverflow.in/309191/cormen-edition-3-exercise-22-1-question-5-page-no-593
The square of a directed graph $G=(V,E)$ is the graph $G^2=(V,E^2)$ such that $(u,v) \in E^2$ if and only $G$ contains a path with at most two edges between $u$ and $v$ .Describe efficient algorithms for computing $G^2$ and $G$ for both the adjacency list and adjacency-matrix representations of G. Analyze the running times of your algorithms.Algorithmshttps://gateoverflow.in/309191/cormen-edition-3-exercise-22-1-question-5-page-no-593Sun, 07 Apr 2019 03:20:44 +0000Cormen Edition 3 Exercise 22.1 Question 4 (Page No. 593)
https://gateoverflow.in/309190/cormen-edition-3-exercise-22-1-question-4-page-no-593
Given an adjacency-list representation of a multi graph $G=(V,E)$, describe an $O(V+E)$ time algorithm to compute the adjacency-list representation of the “equivalent” undirected graph $G’=(V,E’)$ , where $E’$ is consists of the edges in $E$ with all multiple edges between two vertices replaced by a single edge and with all self-loops removed.Algorithmshttps://gateoverflow.in/309190/cormen-edition-3-exercise-22-1-question-4-page-no-593Sun, 07 Apr 2019 03:16:06 +0000Cormen Edition 3 Exercise 22.1 Question 3 (Page No. 592)
https://gateoverflow.in/309188/cormen-edition-3-exercise-22-1-question-3-page-no-592
The transpose of a directed graph $G=(V,E)$ is the graph $G^T=(V,E^T)$, where $E^T=\{(v,u) \in V * V :(u,v) \in E \ \}$ .Thus ,$G^T$ is $G$ with all its edges reversed . Describe efficient algorithms for computing $G^T$ from $G$,for both the adjacency list and adjacency matrix representations of $G$. Analyze the running times of your algorithms.Algorithmshttps://gateoverflow.in/309188/cormen-edition-3-exercise-22-1-question-3-page-no-592Sun, 07 Apr 2019 03:10:23 +0000Cormen Edition 3 Exercise 22.1 Question 2 (Page No. 592)
https://gateoverflow.in/309187/cormen-edition-3-exercise-22-1-question-2-page-no-592
Give an adjacency-list representation for a complete binary tree on $7$ vertices. Give an equivalent adjacency-matrix representation. Assume that vertices are numbered from $1\ to\ 7$ as in a binary heap.Algorithmshttps://gateoverflow.in/309187/cormen-edition-3-exercise-22-1-question-2-page-no-592Sun, 07 Apr 2019 03:02:07 +0000Cormen Edition 3 Exercise 22.1 Question 1 (Page No. 592)
https://gateoverflow.in/309186/cormen-edition-3-exercise-22-1-question-1-page-no-592
Given an adjacency-list representation of a directed graph, how long does it take to compute the out-degree of every vertex ? How long does it take to compute the in-degrees ?Algorithmshttps://gateoverflow.in/309186/cormen-edition-3-exercise-22-1-question-1-page-no-592Sun, 07 Apr 2019 03:00:30 +0000GATE | GATE-CS-2003
https://gateoverflow.in/308092/gate-gate-cs-2003
<p>Let G be an arbitrary graph with n nodes and k components. If a vertex is removed from G, the number of components in the resultant graph must necessarily lie between
<br>
<strong>(A)</strong> k and n
<br>
<strong>(B)</strong> k – 1 and k + 1
<br>
<strong>(C)</strong> k – 1 and n – 1
<br>
<strong>(D)</strong> k + 1 and n – k</p>
<p>The answer is C . how is it <strong>k-1</strong>?? </p>
<p>I mean if we have only one component .?Please explain</p>Algorithmshttps://gateoverflow.in/308092/gate-gate-cs-2003Sun, 31 Mar 2019 10:08:22 +0000CLRS CHAPTER 25
https://gateoverflow.in/307993/clrs-chapter-25
<p><img alt="" height="252" src="https://gateoverflow.in/?qa=blob&qa_blobid=7575253551468206227" width="336"><img alt="" height="260" src="https://gateoverflow.in/?qa=blob&qa_blobid=12960139681733774680" width="346"></p>
<p>FOR THE EXTENDED-SHORTEST-PATH if we want to find the distance between 1->4 and the 1->5 +5->4 gives the shortest path and if 1->5 gets its shortest path as 1->2->5 and 5>4 gets its shortest path as 5->3->4 then how will we get it?? as one of the operands is always from the initial array.</p>Programminghttps://gateoverflow.in/307993/clrs-chapter-25Sat, 30 Mar 2019 14:55:43 +0000CLRS Chapter-22 Figure-22.6
https://gateoverflow.in/307928/clrs-chapter-22-figure-22-6
<p> </p>
<p><img alt="" height="194" src="https://gateoverflow.in/?qa=blob&qa_blobid=11903096499861454160" style="float:left" width="517"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>What are the strongly connected components in the above figure ?</p>Algorithmshttps://gateoverflow.in/307928/clrs-chapter-22-figure-22-6Sat, 30 Mar 2019 08:06:38 +0000Made Easy Workbook
https://gateoverflow.in/305772/made-easy-workbook
<p>Suppose that you are running Dijkstra’s algorithm on the edge-weighted diagram below, starting from vertex A.</p>
<p style="text-align:center"><img alt="" height="292" src="https://gateoverflow.in/?qa=blob&qa_blobid=3109623711580816817" width="389"></p>
<p> </p>
<p> </p>
<p>The Table gives ‘Distance’ and ‘Parent’ entry of each vertex after vertex E has been deleted from the priority queue and relaxed.</p>
<table border="1" cellpadding="1" style="width:500px; margin: auto; border-spacing: 1px;">
<thead>
<tr>
<th scope="col">Vertex</th>
<th scope="col">Distance</th>
<th scope="col">Parent</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>0</td>
<td>Null</td>
</tr>
<tr>
<td>B</td>
<td>2</td>
<td>A</td>
</tr>
<tr>
<td>C</td>
<td>13</td>
<td>F</td>
</tr>
<tr>
<td>D</td>
<td>23</td>
<td>A</td>
</tr>
<tr>
<td>E</td>
<td>11</td>
<td>F</td>
</tr>
<tr>
<td>F</td>
<td>7</td>
<td>B</td>
</tr>
<tr>
<td>G</td>
<td>36</td>
<td>F</td>
</tr>
<tr>
<td>H</td>
<td>19</td>
<td>E</td>
</tr>
</tbody>
</table>
<p> </p>
<p>What could be the possible value of expression x+y?</p>Algorithmshttps://gateoverflow.in/305772/made-easy-workbookSun, 10 Mar 2019 17:09:43 +0000BFS traversal path
https://gateoverflow.in/301800/bfs-traversal-path
<p>What will be the path from A-H if BFS is used in the following graph?
<br>
</p>
<p><img alt="bfs-graph" src="https://gateoverflow.in/?qa=blob&qa_blobid=9357280455466299053"></p>Algorithmshttps://gateoverflow.in/301800/bfs-traversal-pathFri, 01 Feb 2019 21:20:52 +0000made easy
https://gateoverflow.in/299888/made-easy
<figure class="image"><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=11922849780140372176">
<figcaption>can anyone explain how dijkstras will behave as BFS whwn a graph is unweighted?</figcaption>
</figure>
<p> </p>Algorithmshttps://gateoverflow.in/299888/made-easySat, 26 Jan 2019 11:47:29 +0000MadeEasy Test Series 2019: Algorithms - Graph Algorithms
https://gateoverflow.in/289718/madeeasy-test-series-2019-algorithms-graph-algorithms
<p>Which is the best data structure to implement topological sort on directed graph?</p>
<ol style="list-style-type:lower-alpha">
<li>Heap</li>
<li>Stack</li>
<li>queue</li>
<li>Array</li>
</ol>
<p> </p>Algorithmshttps://gateoverflow.in/289718/madeeasy-test-series-2019-algorithms-graph-algorithmsSat, 05 Jan 2019 09:43:02 +0000MadeEasy Test Series: Algorithms - Graph Algorithms
https://gateoverflow.in/289273/madeeasy-test-series-algorithms-graph-algorithms
<p><strong>Which of the following statement is true?</strong></p>
<ol>
<li>For a directed graph, the absence of back edges in a DFS tree can have cycle.</li>
<li>If all edge in a graph have distinct weight then the shortest path between two vertices is unique.</li>
<li>The depth of any DFS (Depth First Search) tree rooted at a vertex is atleast as depth of any BFS tree rooted at the same vertex.</li>
<li>Both (a) and (c)</li>
</ol>Algorithmshttps://gateoverflow.in/289273/madeeasy-test-series-algorithms-graph-algorithmsFri, 04 Jan 2019 12:31:47 +0000Zeal Test Series 2019: Algorithms - Graph Algorithms
https://gateoverflow.in/288085/zeal-test-series-2019-algorithms-graph-algorithms
If the DFS finishing time f[u] < f[v] for two vertices u and v in a directed graph G, and u and v are in the same DFS tree in the DFS forest, then u is an ancestor of v in the depth first tree ?<br />
<br />
True /False<br />
<br />
can anyone explain it ?Algorithmshttps://gateoverflow.in/288085/zeal-test-series-2019-algorithms-graph-algorithmsWed, 02 Jan 2019 10:59:36 +0000BFS and DFS - types of edges
https://gateoverflow.in/286405/bfs-and-dfs-types-of-edges
Can someone please explain what are the types of edges possible in BFS and DFS for DIRECTED as well as UNDIRECTED graphs?<br />
<br />
Individual meaning of BACK, FRONT and CROSS edges is clear, but can’t decide which are present and which are not for Traversals.<br />
<br />
an example would be of great help or any specific reference on this.Algorithmshttps://gateoverflow.in/286405/bfs-and-dfs-types-of-edgesSun, 30 Dec 2018 02:16:47 +0000GO2019-FLT1-47
https://gateoverflow.in/285432/go2019-flt1-47
Which of the following statements is/are correct with respect to Djikstra Algorithm?
<br>
(P) It always works perfectly for graphs with negative weight edges.
<br>
(Q) It does not work perfectly for graphs with negative weight cycles.
<br>
(R) It may or may not work for graphs with negative weight edges.
<br>
(S) It may not terminate if the graph has negative weight cycle
<br>
(T) It always terminates for graphs with negative weight edges.
<br>
(U) Time complexity of Djikstra algorithm becomes $O(V*E)$ if AVL tree is used instead of priority queues.
<br>
<br>
<br>
<ol style="list-style-type:upper-alpha">
<li> Only P, Q, S and T are correct
<br> </li>
<li> Only P, Q, S, T and U are correct
<br> </li>
<li> Only Q, R, T are correct
<br> </li>
<li> Only Q, R, S, T and U are correct </li></ol>Algorithmshttps://gateoverflow.in/285432/go2019-flt1-47Thu, 27 Dec 2018 17:24:40 +0000MadeEasy Test Series: Algorithms - Graph Algorithms
https://gateoverflow.in/284548/madeeasy-test-series-algorithms-graph-algorithms
<h2><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=18294790886677648362"></h2>
<p> </p>
<h2>According To Me Answer Should Be 6… Anyone Please Try Once!!! Given Is 5 With No Explaination !!!!</h2>
<h2>like 11-12-12 then for second square 4 times 13 so c(4,2) any two of then lead to me @ answer @6.</h2>Algorithmshttps://gateoverflow.in/284548/madeeasy-test-series-algorithms-graph-algorithmsTue, 25 Dec 2018 19:09:17 +0000BFS problem
https://gateoverflow.in/284157/bfs-problem
True or False , with reason.<br />
<br />
For a directed graph, the absence of back edges with respect to a BFS tree implies that the graph is acyclic?<br />
<br />
Answer is False<br />
<br />
Explanation:<br />
<br />
FALSE. It is true that the absence of back edges with respect to a DFS tree implies that the graph is acyclic. However, the same is not true for a BFS tree. There may be cross edges which go from one branch of the BFS tree to a lower level of another branch of the BFS tree. It is possible to construct a cycle using such cross edges (which decrease the level) and using forward edges (which increase the level)<br />
<br />
<br />
<br />
Can someone explain it ?Algorithmshttps://gateoverflow.in/284157/bfs-problemTue, 25 Dec 2018 07:49:44 +0000Which of the following condition is sufficient to detect cycle in a directed graph?
https://gateoverflow.in/277531/which-following-condition-sufficient-detect-cycle-directed
<p>Which of the following condition is sufficient to detect cycle in a directed graph?
<br>
<strong>(A)</strong> There is an edge from currently being visited node to an already visited node.
<br>
<strong>(B)</strong> There is an edge from currently being visited node to an ancestor of currently visited node in DFS forest.
<br>
<strong>(C)</strong> Every node is seen twice in DFS.
<br>
<strong>(D)</strong> None of the bove</p>
<p> </p>
<p>here option B is right, but why not option A?</p>Algorithmshttps://gateoverflow.in/277531/which-following-condition-sufficient-detect-cycle-directedWed, 12 Dec 2018 09:33:23 +0000which DFS algorithm to follow?
https://gateoverflow.in/276438/which-dfs-algorithm-to-follow
<p>there are multiple algorithm of DFS available and i cant figure out which one to follow for solving question asking for the nodes which aren’t pushed into the stack or the nodes which are pushed more than once,</p>
<p>Tried to figure out from already asked question but still can’t get it,</p>
<p><a rel="nofollow" href="https://gateoverflow.in/98484/dfs-using-stack">https://gateoverflow.in/98484/dfs-using-stack</a></p>
<p><a rel="nofollow" href="https://gateoverflow.in/161225/dfs-number-of-nodes-not-pushed-into-the-stack">https://gateoverflow.in/161225/dfs-number-of-nodes-not-pushed-into-the-stack</a></p>Algorithmshttps://gateoverflow.in/276438/which-dfs-algorithm-to-followSun, 09 Dec 2018 17:49:57 +0000Depth First Search: Finding if The graph is connected
https://gateoverflow.in/275937/depth-first-search-finding-if-the-graph-is-connected
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=2224418432697632817"></p>
<p>Better Explanation??</p>DShttps://gateoverflow.in/275937/depth-first-search-finding-if-the-graph-is-connectedSat, 08 Dec 2018 13:25:53 +0000Graph Algorithms
https://gateoverflow.in/270013/graph-algorithms
Dijktra Algo selects shortest path having maximum number of shortest edges, for non adjacent nodes. Is it true? Please justify..Algorithmshttps://gateoverflow.in/270013/graph-algorithmsSun, 25 Nov 2018 09:54:40 +0000Edge-Classification In DIrected Graph using BFS
https://gateoverflow.in/268879/edge-classification-in-directed-graph-using-bfs
<p>In BFS of a directed graph, we don't have forward edges.Only tree edge,cross edge or back edge.</p>
<p>Below is a sample graph I have taken and classified edge types.</p>
<p>Please verify guys whether it's correct.</p>
<p>The algorithm I have used is<strong> the pseudocode given by "</strong><strong>redtuna</strong><strong>" i</strong>n the selected answer here.</p>
<p><a rel="nofollow" href="https://stackoverflow.com/questions/29631211/edge-classification-during-breadth-first-search-on-a-directed-graph">https://stackoverflow.com/questions/29631211/edge-classification-during-breadth-first-search-on-a-directed-graph</a></p>
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=8848286091263841616"></p>Programminghttps://gateoverflow.in/268879/edge-classification-in-directed-graph-using-bfsThu, 22 Nov 2018 11:39:40 +0000BFS TRAVERSAL
https://gateoverflow.in/268272/bfs-traversal
HOW CAN WE GET A CROSS EDGE WHILE PERFORMING A BFS ON UNDIRECTED AND DIRECTED GRAPH CAN ANYONE SHOW WITH AN EXAMPLE?Programminghttps://gateoverflow.in/268272/bfs-traversalWed, 21 Nov 2018 07:28:25 +0000MADE EASY TEST SERIES SELF DOUBT
https://gateoverflow.in/268235/made-easy-test-series-self-doubt
<p>In an adjacency list representation of an undirected graph G = (V,E), for any 2 sets of vertices V<sub>1</sub> and V<sub>2</sub> let, distance (V<sub>1</sub>,V<sub>2</sub>) be defined as the minimum of the length of shortest distance between a vertex in V<sub>1</sub> and V<sub>2</sub>, if V<sub>1</sub> ∩ V<sub>2</sub> ≠ ∅, then distance (V<sub>1</sub>,V<sub>2</sub>) = 0. the most optimal time complexity for computing distance (V<sub>1</sub>,V<sub>2</sub>) is :</p>
<p> </p>
<p>WHAT KIND OF SETS IT IS TALKING ABOUT .....?AND HOW IT CAN BE FORMED PLEASE GIVE EXAMPLE .</p>Algorithmshttps://gateoverflow.in/268235/made-easy-test-series-self-doubtWed, 21 Nov 2018 06:36:24 +0000Connected Components
https://gateoverflow.in/264998/connected-components
<p style="text-align:center"><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=12913570869254494683"></p>
<p> </p>Graph Theoryhttps://gateoverflow.in/264998/connected-componentsWed, 14 Nov 2018 08:27:16 +0000Breadth First Search(BFS)
https://gateoverflow.in/264642/breadth-first-search-bfs
$0-1$ $BFS$ (Breadth First Search)al is used to find the shortest distance between two nodes in a graph provided<br />
that the edges in the graph have the weights $0$ or $1.$Which of the following data structure is most efficient<br />
in traversing a graph by $0-1$ $BFS?$<br />
$A)$ Priority queue $B)$Stack $C)$ Double-ended queue $D)$ Linked listAlgorithmshttps://gateoverflow.in/264642/breadth-first-search-bfsTue, 13 Nov 2018 13:22:27 +0000Graph Search
https://gateoverflow.in/264637/graph-search
<p>Which of the following statements are true?</p>
<ol>
<li> In a depth-first search of an undirected graph $G,$every edge of $G$ is either a tree edge or a back edge</li>
<li>Forward and cross edges never occur in a depth-first search of an undirected graph</li>
<li>A directed graph is acyclic if and only if a depth-first search yields no back edges</li>
</ol>
<ol start="1" style="list-style-type:upper-alpha">
<li>$1$ </li>
<li>$1$ and $2$ </li>
<li>$2$ and $3$ </li>
<li>All of these</li>
</ol>Algorithmshttps://gateoverflow.in/264637/graph-searchTue, 13 Nov 2018 13:09:29 +0000Depth First Search (DFS)
https://gateoverflow.in/264632/depth-first-search-dfs
<p>Consider the following sequence of nodes for the undirected graph given below$:$</p>
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=15415974684464118723"></p>
<p>$(1)PQSTWVUR$
<br>
$(2)PQRSTUWV$
<br>
$(3)PQRTUSVW$
<br>
A Depth First Search (DFS) is started at node $P.$The nodes are listed in the order they are first visited.
<br>
Which all of the above are possible outputs$?$
<br>
$A)Only (2)$
<br>
$B)(1) and (2)$
<br>
$C)(2) and (3)$
<br>
$D)(1) and (2)$</p>Algorithmshttps://gateoverflow.in/264632/depth-first-search-dfsTue, 13 Nov 2018 12:58:53 +0000Minimum spanning tree implementation in other way
https://gateoverflow.in/263318/minimum-spanning-tree-implementation-in-other-way
Which algorithm will be implemented on the weighted graph in which the edges are uniformly distributed over the half-open interval $[0,1)$ to construct MST so that it runs in linear time?<br />
$A)$ Kruskal's algorithm $B)$ Prim's algorithm<br />
$C)$ Both $(A)$ and $(B)$ $D)$ None of theseAlgorithmshttps://gateoverflow.in/263318/minimum-spanning-tree-implementation-in-other-waySat, 10 Nov 2018 07:05:54 +0000Depth First Search
https://gateoverflow.in/262340/depth-first-search
<p style="text-align:center"><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=8955084302214325070"></p>
<p> </p>Programminghttps://gateoverflow.in/262340/depth-first-searchWed, 07 Nov 2018 08:05:36 +0000general doubt on breadth first search
https://gateoverflow.in/249159/general-doubt-on-breadth-first-search
<p><strong>While doing BFS , at any time in queue suppose there are r vertices v1,v2,v3.....vr with v.d as the distance from the source</strong>.</p>
<p>Then according to me at any time in a queue,</p>
<p><strong>v1.d=v2.d</strong></p>
<p>or</p>
<p><strong>v2.d=v1.d+1</strong></p>
<p>But in cormen its written that v2.d<=v1.d+1</p>
<p>Can someone please explain?</p>DShttps://gateoverflow.in/249159/general-doubt-on-breadth-first-searchWed, 03 Oct 2018 03:38:22 +0000MadeEasy Test Series: Programming & DS - Graphs
https://gateoverflow.in/243853/madeeasy-test-series-programming-%26-ds-graphs
<p><img alt="" height="836" src="https://gateoverflow.in/?qa=blob&qa_blobid=7258038337665468458" width="949"></p>DShttps://gateoverflow.in/243853/madeeasy-test-series-programming-%26-ds-graphsMon, 17 Sep 2018 05:12:37 +0000Graph
https://gateoverflow.in/243393/graph
<p>Also let me know the approach to find back edges, cross edges, forward edges,</p>
<p>How to solve these questions</p>
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=11912430808391725667"></p>Algorithmshttps://gateoverflow.in/243393/graphSat, 15 Sep 2018 12:19:01 +0000Strongly connected components
https://gateoverflow.in/243279/strongly-connected-components
<p>Consider the following graph:</p>
<p><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=9551826490378390348"></p>
<p>The number of strongly connected components of the graph are ________.</p>Algorithmshttps://gateoverflow.in/243279/strongly-connected-componentsSat, 15 Sep 2018 07:34:42 +0000MadeEasy Workbook: Algorithms - Graph Algorithms
https://gateoverflow.in/243236/madeeasy-workbook-algorithms-graph-algorithms
<p style="text-align:center"><img alt="" src="https://gateoverflow.in/?qa=blob&qa_blobid=15802043341897666058"></p>
<p>Approach for Q8 and Q9 please</p>Algorithmshttps://gateoverflow.in/243236/madeeasy-workbook-algorithms-graph-algorithmsSat, 15 Sep 2018 05:25:02 +0000DFS Tree
https://gateoverflow.in/238929/dfs-tree
Consider the tree arcs of a DFS traversal from a source node W in an unweighted, connected, undirected, acyclic graph. The tree T formed by the tree arcs is a data structure for computing-<br />
1. the shortest path between every pair of vertices.<br />
2. the shortest path from W to every vertex in the graph.<br />
3. the shortest paths from W to only those nodes that are leaves of T.<br />
4. the longest path in the graph.Algorithmshttps://gateoverflow.in/238929/dfs-treeSat, 01 Sep 2018 02:11:41 +0000GATE Minimum Spanning Trees
https://gateoverflow.in/238784/gate-minimum-spanning-trees
Q1) Why is the path between a pair of vertices in a minimum Spanning tree of an undirected graph not the shortest( minimum weight) path?Mathematical Logichttps://gateoverflow.in/238784/gate-minimum-spanning-treesFri, 31 Aug 2018 10:51:31 +0000Breadth first Search
https://gateoverflow.in/235758/breadth-first-search
Which of following statement is true ?<br />
<br />
A. In BFS of UDG there are no back edges and forward edges.<br />
<br />
B. In BFS of Directed Graph there is no back edge and forward edges.<br />
<br />
C. In BFS of UDG for each back edge(u,v) we have 0<= v.d <= u.d<br />
<br />
D. Both b and c.<br />
<br />
Ans. ADShttps://gateoverflow.in/235758/breadth-first-searchTue, 21 Aug 2018 14:51:28 +0000Depth first search
https://gateoverflow.in/235743/depth-first-search
The maximum number of edges possible with UDG of n nodes,when DFS call on any random node in the graph result in stack size of 5. i.e. 5 function calls present in stack simultaneously are .........<br />
<br />
Ans. 10DShttps://gateoverflow.in/235743/depth-first-searchTue, 21 Aug 2018 14:27:43 +0000CLRS INTRODUCTION TO ALGORITHMS 3rd Edition, CHAPTER 23 QUESTION 23.2.7
https://gateoverflow.in/234860/clrs-introduction-algorithms-3rd-edition-chapter-question
<blockquote>
<p>suppose that a graph G has MST already computed. How quickly can we update the MST if we add a new vertex and incident edges to it.</p>
</blockquote>
<p>I know for the best case scenario when a single edge is incident from the newly added vertex. but for the worst case, when the newly added vertex has an edge incident to the every other vertex in the MST, then i'm getting confused as how should we proceed?</p>
<p>there are two solutions i've got online, which i'm attaching here for reference.</p>
<blockquote>
<p>solution 1:</p>
<p>If there is only one edge, just add this edge.</p>
<p>If there are k(k > 1) edges, then we need to remmove k-1 edges. We can find cycles by Union-Find and remove the weightest edge in an union. This algorithm need (k-1) passes.</p>
</blockquote>
<blockquote>
<p>solution 2:</p>
<p>We first add all the edges to the new vertex. Then, we preform a DFS rooted at that vertex. As we go down, we keep track of the largest weight edge seen so far since each vertex above us in the DFS. We know from exercise 23.3-6 that in a directed graph, we don’t need to consider cross or forward edges. Every cycle that we detect will then be formed by a back edge. So, we just remove the edge of greatest weight seen since we were at the vertex that the back edge is going to. Then, we’ll keep going until we’ve removed one less than the degree of the vertex we added many edges. This will end up being linear time since we can reuse part of the DFS that we had already computed before detecting each cycle.</p>
</blockquote>
<p> </p>Algorithmshttps://gateoverflow.in/234860/clrs-introduction-algorithms-3rd-edition-chapter-questionSun, 19 Aug 2018 07:58:53 +0000How Bellman ford is dynamic programming?
https://gateoverflow.in/230530/how-bellman-ford-is-dynamic-programming
<pre>
What is the reason behind it? How do we find an optimal substructure and overlapping sub problems in this ? In which line of code memoization is done?
BELLMAN-FORD(G,w,s)
Code
1. INITIALIZE-SINGLE-SOURCE(G,s)
2. for i = 1 to |G.V|-1
3. for each edge (u,v) ∈ G.E
4. RELAX(u,v,w)
5. for each edge (u,v) ∈ G.E
6. if v.d > u.d + w(u,v)
7. return FALSE
8. return TRUE
INITIALIZE-SINGLE-SOURCE(G,s)
1. for each vertex v ∈ G.V
2. v.d = ∞
3. v.pi = NIL
4. s.d = 0
RELAX(u,v,w)
1. if v.d > u.d + w(u,v)
2. v.d = u.d + w(u,v)
3. v.pi = u</pre>Algorithmshttps://gateoverflow.in/230530/how-bellman-ford-is-dynamic-programmingFri, 03 Aug 2018 05:16:29 +0000