A solution that always finds shortest superstring takes exponential time. Contests. 2) Other nodes, may be an ancestor of target, or a node in some other subtree. The task is to find the cheapest cost path from given source to destination from K stops. Going from one node to its left child node is indicated by the letter ‘L’. Therefore, print 8. Following is the Backtracking algorithm for Knight’s tour problem. Practice Given an undirected and unweighted graph and two nodes as source and destination, the task is to print all the paths of the shortest length between the given source and destination. In other words a node is deleted if all paths going through it have lengths smaller than k. Discuss. A graph is said to be eulerian if it has a eulerian cycle. The task is to find the minimum number. Nodes are labeled from 0 to n-1, the task is to check if it contains a negative weight cycle or not. Here, for every vertex in the graph, we have a list of all the other vertices which the particular vertex has an edge to. Approach: The idea is to use the Shortest Path Faster Algorithm (SPFA) to find if a negative cycle is present and reachable from the. Expected Time Complexity: O (V + E) Expected Auxiliary Space: O (V + E) Constraints: 1 ≤ V, E ≤ 105. Initial position is top left and all characters of input string should be printed in order. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). Feeling lost in the world of random DSA topics, wasting time without progress?. Example: Input: n = 9, m= 10 edges= [ [0,1], [0,3], [3,4], [4 , Practice. Shortest Path Revisited. It's a common practice to augment dynamic programming algorithms to store parent pointers. Solve company interview questions and improve your coding intellectUnique Paths II - You are given an m x n integer array grid. Practice. Now when we are at leaf node and it is equal to arr [index] and there is no further element in given sequence of root to leaf path, this means that path exist in given tree. Create a Set to store all the visited words in current path and once the current path is completed, erase all the visited words. e. Practice. Step 2: Define a function “findLongestFromACell” that takes in a cell’s row and column index, the matrix, and a lookup table. To solve the problem, we need to try out all intermediate vertices ranging [1, N] and check: If there is a direct edge already which exists between the two nodes. The important thing to note is we can reach any destination as it is always possible to make a move of length 1. Method 1. Share. Output: Yes. Given a directed graph and two vertices ‘u’ and ‘v’ in it, count all possible walks from ‘u’ to ‘v’ with exactly k edges on the walk. He considered each of the lands as a node of a graph and each bridge in between as an edge in between. Expected Time Complexity: O (m* log (n)) Expected Space Complexity: O (n) Constraint: 2 <= n <= 105. 0. Step 4: Find the minimum among these edges. not appeared before, then. Algorithm to find shortest closed path or optimal Chinese postman route in a weighted graph that may not be Eulerian. Find cycle in undirected Graph using DFS: Use DFS from every unvisited node. We can make above string palindrome as "CBABC". A person wants to go from origin to a particular location, he can move in only 4 directions (i. Improve this. Check if it is possible to make all elements into 1 except obstacles. Solve Problem. The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i. For example consider the below graph. Step 4: Find the minimum among these edges. A Simple Solution is to use Dijkstra’s shortest path algorithm, we can get a shortest path in O (E + VLogV) time. You need to find the shortest distance between a given source cell to a destination cell. Given a graph of N Nodes and E edges in form of {U, V, W} such that there exists an edge between U and V with weight W. Number of shortest paths in an Undirected Weighted Graph; Johnson's algorithm for All-pairs shortest paths; Check if given path between two nodes of a graph represents a shortest paths; Shortest distance between two nodes in Graph by reducing weight of an edge by half; Print negative weight cycle in a Directed GraphThe basic idea behind the iterative DFS approach to finding the maximum path sum in a binary tree is to traverse the tree using a stack, maintaining the state of each node as we visit it. There is a robot initially located at the top-left corner (i. , (0, 0)) to the bottom-right cell (i. We have discussed Dijkstra’s algorithm and its implementation for adjacency matrix representation of graphs. Weight (or. Dijkstra’s Algorithm: It works on Non-Negative Weighted graphs. Algorithm. Share. For example, lcs of “geek” and “eke” is “ek”. Explanation: (1, 2) and (2, 5) are the only edges resulting into shortest path between 1 and 5. Auxiliary Space: O(ALPHABET_SIZE^L+n*L) Approach 2: Using Dynamic Programming. Example1: Input: N = 4, M = 2 edge =. For example, a more complex version. Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any order. So whenever the target word is found for the first time that will be the length of the shortest chain of words. Approach: The idea is to use Dijkstra’s shortest path algorithm with a slight variation. In general, the single source shortest path problem in graph theory deals with finding the distance of each vertex from a given source which can be solved in O (V × E) O(V imes E) O (V × E) time using the bellman ford algorithm. Contests. Follow the steps below to solve the problem: Create dp [N] [N] and ANS [N] [N] tables with all values set to INT_MAX and INT_MIN. Prerequisites: Dijkstra. Prerequisites: Dijkstra. Back to Explore Page. Use Breadth First Search to find the solution optimally. Initially, the shortest path between any two nodes u and v is v (that is the direct edge from u -> v). Practice. Another method: It can be solved in polynomial time with the help of Breadth First Search. Given a graph of N Nodes and E edges in form of {U, V, W} such that there exists an edge between U and V with weight W. Given a Directed Acyclic Graph of N vertices from 0 to N-1 and a 2D Integer array (or vector) edges [ ] [ ] of length M, where there is a directed edge from edge [i] [0] to edge [i] [1] with a distance of edge [i] [2] for all i. Given a weighted directed graph with N vertices and M edges, a source src and a destination target, the task is to find the shortest monotonic path (monotonically increasing or decreasing) from the source to the destination. The task is to find the minimum number of edges in a path in G from vertex 1 to vertex n. Shortest path from a source cell to a destination cell of a Binary Matrix through cells consisting only of 1s. when we come across ” . Explanation: The first and last node of the input sequence is 1 and 4 respectively. Dijkstra's shortest path algorithm in Java using PriorityQueue. Sum of weights of path between nodes 0 and 3 = 6. Note: It is assumed that negative cost cycles do not exist in input matrix. A Bellman-Ford algorithm is also guaranteed to find the shortest path in a graph, similar to. e. From each cell you can either move only to right or down. Problem Statement: . Count of cells in a matrix which give a Fibonacci number when the. Algorithm: Step 1: Initialize a matrix and set its size to n x n. The main idea is to recursively get the longest path from the left. Input : str = "AACECAAAA"; Output : 2. If a vertices can't be reach from the S then mark the distance as 10^8. Given a weighted, directed and connected graph of V vertices and E edges, Find the shortest distance of all the vertex's from the source vertex S. + 3 more. Explanation: The shortest path is: 2 → 1. Follow the steps below in order to solve the problem: Root the tree at any random vertex, say 1. Note: You can only move either down or right at any point in time. Dijkstra’s algorithm is a popular algorithms for solving many single-source shortest path problems having non-negative edge weight in the graphs i. Traverse all words that adjacent (differ by one character) to it and push the word in a queue (for BFS)A rat starts from source and has to reach the destination. e. A Bellman-Ford algorithm is also guaranteed to find the shortest path in a graph, similar to. Find the shortest path from src(0) vertex to all the vertices and if it is impossible to reach any vertex, then return -1 for that vertex. Step by step Shortest Path from source node to destination node in a Binary Tree. Below are the detailed steps used in Dijkstra’s algorithm to find the shortest path from a single source vertex to all other vertices in the given graph. Copy contents. . used to compare two pairs. To detect a back edge, we need to keep track of the nodes visited till now and the nodes that are in the. Please. Given a binary matrix mat[][] of dimensions of N * M and pairs of integers src and dest representing source and destination cells respectively, the task is to find the shortest sequence of moves from the given source cell to the destination cell via cells consisting only of 1s. If no valid path exists then print -1. 1 I have a working implementation of Djikstra's algorithm which calculates the length of the shortest path between any two nodes. Sum of weights of path between nodes 1 and 2 = 2. It follows Greedy Approach. Print path from root to a given node in a binary tree; Enumeration of Binary Trees; Subtree with given sum in a Binary Tree; Sink Odd nodes in Binary Tree; Minimum moves to convert Tree to Star Tree; Print Binary Tree in 2-Dimensions; Find depth of the deepest odd level leaf node; Find distance from root to given node in a binary treeCourses. In this article, an O (E*K) approach is discussed for solving this problem. An Adjacency List is used for representing graphs. There is an edge from a vertex i to a vertex j iff either j = i + 1 or j = 3 * i. If a graph contains a. Find the length of the shortest transformation sequence from startWord to targetWord. Source is already a corner of the grid. Your task is to complete the function chinesePostmanProblem () which takes the edge list e [] [], number of nodes as input parameters and returns the length of the shortest path that visits each edge at least once. For every vertex first, push current vertex into the queue and then it’s neighbours and if the vertex which is already visited comes again then the cycle is present. It allows some of the edge weights to be negative numbers, but no negative-weight cycles may exist. Let arr [] be given set of strings. The shortest path algorithms are the ones that focuses on calculating the minimum travelling cost from source node to destination node of a graph in optimal time and space complexities. Given a directed graph and a source vertex in the graph, the task is to find the shortest distance and path from source to target vertex in the given graph where edges are weighted (non-negative) and directed from parent vertex to source vertices. Example 1: Input: V = 2 adj [] = { { {1, 9}}, { {0, 9}}} S = 0 Output: 0 9 Explanation: The source vertex is 0. Menu. Note: There are only a single source and a single. Your Task: Your task is to complete the function isNegativeWeightCycle () which takes n and edges as input paramater and returns 1 if graph contains negative weight cycle otherwise returns 0. Dijkstra’s algorithm is applied on the re. Initially, the shortest path between any two nodes u and v is v (that is the direct edge from u -> v). distance as 0. Explanation: Vertex 3 from vertex 1 via vertices 2 or 4. Since a policeman is present at the 1 st house, the only path that can be chosen is the 2nd path. Discuss. Detailed solution for Shortest Path in Undirected Graph with unit distance: G-28 - Given an Undirected Graph having unit weight, find the shortest path from the source to all other nodes in this graph. Dijkstra’s shortest path for adjacency matrix representation. The description of cells is as follows: A value of cell 1 means Source. To find cycle in a directed graph we can use the Depth First Traversal (DFS) technique. 2. Following figure is taken from this source. The time complexity of this approach is O (N 2 ). step 2 : We find. The faster one is called the fast pointer and the. distance as 0. Step-2: Pick all the vertices with in-degree as 0 and add them into a queue (Enqueue operation) Step-3: Remove a vertex from the. Minimum length of jumps to avoid given array of obstacles. For example, if the target node is 8 and k is 2, then such nodes are 10 and 14. Step 2: Iterate from the end of string. Find the length of the shortest transformation sequence from startWord to targetWord. We would like to show you a description here but the site won’t allow us. Platform to practice programming problems. After the shortest distances have been calculated, you can print the shortest path to a node x by starting from x and following parent pointers p [x], p [p [x]], etc, until you hit the source. Here adj[i] contains vectors of size 2,Euler first introduced graph theory to solve this problem. If there is no possible path, return -1. Given a weighted, directed and connected graph of V vertices and E edges, Find the shortest distance of all the vertex's from the source vertex S. Count all possible paths from source to destination in given 3D array. Example 1: Input: V = 5, E = 5 adj. If multiple shortest super-sequence exists, print any one of them. And each time, you pop a position at the front of the queue ,at the same time, push all the positions which can be reached by 1 step and hasn't been visited yet. , we use Topological Sorting . In this article we’re focusing on the differences between shortest path algorithms that are: Depth-First Search (DFS) Breadth-First Search (BFS) Multi-Source. 2) Assign a distance value to all vertices in the input graph. step 1 : If graph is Eulerian, return sum of all edge weights. , whose minimum distance from the source is calculated and finalized. If a vertex is unreachable from the source node, then return -1 for that vertex. We can move exactly n steps from a cell in 4 directions i. You don't need to read input or print anything. Following is Fleury’s Algorithm for printing the Eulerian trail or cycle. Given a screen containing alphabets from A-Z, we can go from one character to another characters using a remote. Find the distance of the shortest path from Num1 to Num2 that can be attained by altering only single digit at a time such that every number that we get after changing a digit is a four digit prime number with no leading zeros. Graph is in the form of adjacency list where adj [i] contains all the nodes ith node is having edge with. The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i. Cycle 6 -> 1 -> 2 -> 6. The graph is represented as an adjacency. Print all the paths from root to leaf, with a specified sum in Binary tree. Also, replace the guards with 0 and walls with -1 in output matrix. i. The next row’s choice must be in a column that is different from the previous row’s column by at most one. Therefore the cost of the path = 3 + 5 + 4 = 12. The task is to find the sum of weights of the edges of the Minimum Spanning Tree. Note that this is a simple version of the typical Maze problem. To learn more about Minimum Spanning Tree, refer to this article. (A Knight can make maximum eight moves. , grid [m - 1] [n - 1]). The edge (a, b) must be excluded if there is. Approach: The idea is to traverse all vertices of the graph using BFS and use priority queue to store the vertices for which the shortest distance. We can start from m [n-1] [m-1] as the base case with the length of longest increasing subsequence be 1, moving upwards and leftwards updating the value of cells. , (n - 1, n - 1)) such that:. Below are steps. You are given a weighted undirected graph having n+1 vertices numbered from 0 to n and m edges describing there are edges between a to b with some weight, find the shortest path between the vertex 1 and the vertex n, and if the path does not exist then return a list consisting of only-1. Complete the function shortest path () which takes a 2d vector or array edges representing the edges of undirected graph with unit weight, an integer N as number nodes, an integer. 8. If the destination is reached, print the vector as one of the possible paths. Output: “L”. Repeat step#2 until there are (V-1) edges in the. Step 2: Pick edge 8-2. Since distance of + 5 and – 5 from 0 is same, hence we find answer for absolute value of destination. Shortest Path-Printing using Dijkstra's Algorithm for Graph (Here it is implemented for undirected Graph. Assume that we need to find reachable nodes for n nodes, the time complexity for this solution would be O (n* (V+E)) where V is number of nodes in the graph and E is number of edges in the graph. Given a directed graph, a source vertex ‘src’ and a destination vertex ‘dst’, print all paths from given ‘src’ to ‘dst’. Given a Binary Tree of distinct nodes and a pair of nodes. Your Task: You don't need to read input or print anything. Any such node should be counted only once. Given a graph and a source vertex in the graph, find the shortest paths from the source to all vertices in the given graph. Approach: The solution is to perform BFS or DFS to find whether there is a path or not. The idea is to use shortest path algorithm. Initialize a counter [] [] vector, this array will keep track of the number of remaining obstacles that can be eliminated for each visited cell. Print all root to leaf paths of an N-ary tree. It uses two pointers one moving twice as fast as the other one. Practice. Courses. Topological sorting for D irected A cyclic G raph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering. Bellman-Ford Algorithm. Let both start and finish be roots. Your task is to complete the function minimumCostPath () which takes grid as input parameter and returns the minimum cost to react at bottom right cell from top left cell. Below is BFS based solution. Another method: It can be solved in polynomial time with the help of Breadth First Search. Courses. Perform DFS at Root. Examples: Input: src = 0, the graph is shown below. Your task is to complete the function findShortestPath () which takes matrix as input parameter and return an integer denoting the shortest path. A Simple Solution is to use Dijkstra’s shortest path algorithm, we can get a shortest path in O (E + VLogV) time. If there is no such path present then print “-1” . first n characters in input string. 3) Insert source vertex into pq and make its. This gives the shortest path. Practice. An Adjacency List is used for representing graphs. Approach: The path from any root vertex to any vertex ‘i’ is the path from the root vertex to its parent followed by the parent itself. There is an edge from a vertex i to a vertex j iff either j = i + 1 or j = 3 * i. If a node X lies on multiple root-to-leaf paths and if any of the paths has path length >= k, then X is not deleted from Binary Tree. Here adj [i] contains vectors of size 2,Frequencies of Limited Range Array Elements. Let countSub (n) be count of subsequences of. Approach: To solve the problem, the idea is to use Breadth-First-Search traversal. Topological Sorting for a graph is not possible if the graph is not a DAG. The task is to find the sum of weights of the edges of the Minimum Spanning Tree. (a) Calculate the shortest path from s to all other vertices by using the Dijkstra algorithm. Example 1: Input: n = 5, m= 6 edges = [ [1,2,2], [2,5,5], [2,3,4], [1,4,1], [4,3,3], [3,5,1]] Output: 1 4 3 5 Explanation: The source vertex is 1. The following code prints the shortest distance from the source_node to all the other nodes in the graph. Expected time complexity is O (V+E). two pairs. Space Complexity: O(V). Java. Output − List of the shortest distance of all vertices from the starting node. Print the number of shortest paths from a given vertex to each of the vertices. Strings are defined as an array of characters. Below is the implementation of the approach. Whenever we encounter any file’s name, we simply push it into the stack. Find shortest safe route in a path with landmines in C++. Let’s call it. Output: 2. Given a binary tree, you need to find the number of all root to leaf paths along with their path lengths. Assume that the claim is true in some given stage, and prove that it will hold for the next step. Example 1: Input: n = 3, edges. Read. Watch the new video in more detail about dijsktra:. You don't need to read, input, or print anything. Auxiliary Space: O (R*C), The extra space is used in storing the elements of the visited matrix. Same as condition (a) for Eulerian Cycle. We choose one of the 8 moves in this step). There are two methods to solve this problem: Recursive Method. You don't need to read input or print anything. Detailed solution for Shortest Path in Undirected Graph with unit distance: G-28 - Given an Undirected Graph having unit weight, find the shortest path from the source to all other nodes in this graph. Johnson's algorithm for All-pairs shortest paths; Shortest Path in Directed Acyclic Graph; Multistage Graph (Shortest Path) Shortest path in an unweighted graph; Karp's minimum mean (or average) weight cycle algorithm; 0-1 BFS (Shortest Path in a Binary Weight Graph) Find minimum weight cycle in an undirected graph Explanation: There exists no path from start to end. Meet In The Middle solution is similar to Dijkstra’s solution with some modifications. 4% Submissions: 18K+ Points: 8. Push the word in the queue. Your task is to complete the function possible_paths () which takes edges, n, s and d as input parameter and returns the number of ways to reach from s to d. Your task is to complete the function shortestPath () which takes n vertex and m edges and vector of edges having weight as inputs and returns the shortest path between vertex 1 to n. Note: edges [i] is defined as u, v and weight. Approach: The idea is to use Floyd Warshall Algorithm to store the length of all pairs of vertices. The distance between the two nodes i and j will be equal to dist (i, LCA (i, j)) + dist (j, LCA (i. You are also given an integer k. Your task is to complete the function shortestPath() which takes n vertex and m edges and vector of edges having weight as inputs and returns the shortest path between vertex 1 to n. A minimum spanning tree (MST) or minimum weight spanning tree for a weighted, connected, undirected graph is a spanning tree with a weight less than or equal to the weight of every other spanning tree. , grid [0] [0]). O ==> Open Space G ==> Guard W ==> Wall. Time Complexity: The time complexity of this algorithm is O((V-1)!) where V is the number of vertices. The vertices are sometimes also referred to as nodes and the edges are lines or arcs that connect any two nodes in the graph. The allowed moves are moving a cell left (L), right (R), up (U), and. def BFS_SP (graph, start,. If there is an Eulerian path then there is a solution otherwise not. You are given two four digit prime numbers Num1 and Num2. Find out the minimum steps a Knight will take to reach the target position. Expected time complexity is O (V+E). Your task is to complete the function minimumStep() which takes an integer n as inputs and returns the minimum number of edges in a path from vertex 1 to vertex N. Examp. So there are n stairs. in order to generate different substring. Given a weighted, undirected and connected graph of V vertices and E edges. /. Make sure the graph has either 0 or 2 odd vertices. Exclusively for Freshers! Participate for Free on 21st November & Fast-Track Your Resume to Top Tech Companies. Now, there arises two different cases:Given a root of binary tree and two integers startValue and destValue denoting the starting and ending node respectively. Examples: Input: Root of below tree And x = pointer to node 13 10 / . Therefore, BFS is an appropriate algorithm to solve this problem. There is an edge from a vertex i to a vertex j if and only if either j = i + 1 or j = 3 * i. Examples: Input: N1 = 7, N2 = 4. , whose minimum distance from source is calculated and finalized. 0 <= m <= n* (n-1), where m is the total number of Edges in the. Edit Distance Using Dynamic Programming (Bottom-Up Approach): . Expected Time Complexity: O (R * C) Expected Auxiliary Space: O (1) Constraints: 1 <= R,C <= 103. Examples:. org or mail your article to [email protected] Path: An undirected graph has Eulerian Path if following two conditions are true. Note: If the Graph contains a nLength of longest possible route is 24. ; Loop till queue is empty. Practice Video Given a graph and a source vertex in the graph, find the shortest paths from the source to all vertices in the given graph. dp [i] [j] represents shortest path from i to j. Time Complexity: O(N 2) Efficient Approach: The idea is to use Recursion to solve this problem efficiently. Your Task: You don't need to read input or print anything. It is a single source shortest path algorithm. It is practically infeasible as Operating System may. Given a Binary Tree and a node x in it, find distance of the closest leaf to x in Binary Tree. Tutorials. The idea is to find paths from root nodes to the two nodes and store them in two separate vectors or arrays say path1 and path2. But its worst-case time complexity is still O(V^2). Iterate over all M edges and for each edge U and V set dp [U] [V] to 1 and ANS [U] [V] to A [U] + A [V]. Else, discard it. Step 1: Pick edge 7-6. Given a graph and a source vertex in the graph, find the shortest paths from the source to all vertices in the given graph. Try all 8 possible positions where a Knight can reach from its position. Johnson's algorithm for All-pairs shortest paths; Number of shortest paths in an Undirected Weighted Graph; Number of ways to reach at destination in shortest time; Check if given path between two nodes of a graph represents a shortest paths; Dijkstra's shortest path with minimum edges; Shortest Path in Directed Acyclic GraphConsider a rat placed at (0, 0) in a square matrix of order N * N. Approach: For every vertex, we check if it is possible to get the shortest cycle involving this vertex. Two cells are. Shortest path between two points in a Matrix with at most K obstacles. It may cause starvation if shorter processes keep coming. The task is to find the shortest path from the start node to the end node and print the path in the form of directions given below. This problem can be solved using the concept of ageing. A clear path in a binary matrix is a path from the top-left cell (i. Given two four digit prime numbers, suppose 1033 and 8179, we need to find the shortest path from 1033 to 8179 by altering only single digit at a time such that every number that we get after changing a digit is prime. as first item is by default used to compare. Meet In The Middle technique can be used to make the solution faster. Expected Time Complexity: O (sqrt (N!)) Expected Auxiliary Space: O (N*N. Given a square maze containing positive numbers, find all paths from a corner cell (any of the extreme four corners) to the middle cell. Arrays; public class GA { /** * @param args the command line arguments */ public static void main (String [] args) { //computation time long start = System. Given the following grid containing alphabets from A-Z and a string S. e. Top-down approach for printing Longest Common Subsequence: Follow the steps below for the implementation: Check if one of the two strings is of size zero, then we return an empty string because the LCS, in this case, is empty (base case). Number of shortest paths to reach every cell from bottom-left cell in the grid; Print all paths from a source point to all the 4 corners of a Matrix; Count of all unique paths from given source to destination in a Matrix; Find. given data and NULL left and right pointers. Introduction to Kruskal’s Algorithm: Here we will discuss Kruskal’s. A Graph is a non-linear data structure consisting of vertices and edges. Note: Y. Thus, d(S, X) = min U ∈ S(d(S, U) + w(U, X)). Step 3: Drop kth character from the substring obtained. Given a Directed Acyclic Graph of N vertices from 0 to N-1 and a 2D Integer array (or vector) edges [ ] [ ] of length M, where there is a directed edge from edge [i] [0] to edge [i] [1] with. Start from the given start word. The next row’s choice must be in a column that is different from the previous row’s column by at most one. The idea is to browse through all paths of length k from u to v using the approach discussed in the previous post and return weight of the shortest path. The Floyd-Warshall algorithm, named after its creators Robert Floyd and Stephen Warshall, is a fundamental algorithm in computer science and graph theory. Now, there arises two different cases: Explanation: The shortest path is: 3 → 1 → 5 → 2 → 6. Given a weighted directed graph with n nodes and m edges. Step 3: Drop kth character from the substring obtained. 89% Submissions: 109K+ Points: 4. Exclusively for Freshers! Participate for Free on 21st November & Fast-Track Your Resume to Top Tech Companies. 4. Menu. Print all shortest paths between given source and destination in an undirected graph.