print shortest path gfg practice. Follow the steps below to solve the given problem. print shortest path gfg practice

 
 Follow the steps below to solve the given problemprint shortest path gfg practice Given a weighted, undirected and connected graph of V vertices and an adjacency list adj where adj [i] is a list of lists containing two integers where the first integer of each list

a) Extract minimum distance vertex from Set. in all 4 directions. 8. , whose minimum distance from source is calculated and finalized. You. Initially, this set is empty. Solve practice problems for Shortest Path Algorithms to test your programming skills. The graph needs not to be created to perform the bfs, but the matrix itself will be used as a graph. recursively write it as below. The shortest among the two is {0, 2, 3} and weight of path is 3+6 = 9. Input: source vertex = 0 and destination vertex is = 7. /. You are given an Undirected Graph having unit weight, Find the shortest path from src to all the vertex and if it is unreachable to reach any vertex, then return -1 for that vertex. Minimum weighted cycle is : Minimum weighed cycle : 7 + 1 + 6 = 14 or 2 + 6 + 2 + 4 = 14. Shortest direction | Practice | GeeksforGeeks. Approach: The solution is to perform BFS or DFS to find whether there is a path or not. It chooses one element from each next row. We can make above string palindrome as AAAACECAAAA. Bellman-Ford Algorithm. Nodes should be printed from left to right. Distance from the Source (Bellman-Ford Algorithm) | Practice | GeeksforGeeks. Example 1: Input: A = 6, B = 6. 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. Expected Time Complexity: O (R * C) Expected Auxiliary Space: O (1) Constraints: 1 <= R,C <= 103. Example 2: Input: K = 3 3 / 2 1 / 5 3 Output: 5 3. Characteristics of SJF Scheduling: Shortest Job first has the advantage of having a minimum average waiting time among all scheduling algorithms. Contests. Introduction to Kruskal’s Algorithm: Here we will discuss Kruskal’s. The robot tries to move to the bottom-right corner (i. Given a Binary Tree of size N, you need to find all the possible paths from root node to all the leaf node's of the binary tree. When it finds the first leaf node, it calls the printPath function to print the path from the leaf node to the root. 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. Use induction to prove that at each stage it has given you the shortest path to the vertices visited. Since the graph is unweighted, we can solve this problem in O (V + E) time. Given a Binary Tree with all unique values and two nodes value,&nbsp;n1 and n2. Given a directed graph, find out if a vertex j is reachable from another vertex i for all vertex pairs (i, j) in the given graph. 2) Create an empty priority_queue pq. Now, the shortest distance to reach 2 from 0 through the path 0 -> 1 -> 2 is (4 + 4) = 8. The idea is to consider the given snake and ladder board as a directed graph with a number of vertices equal to the number of cells in the board. Note: Please read the G-32 and the. Pop the top-most element from pq. Step 5: Add the chosen edge to the MST if it does not. 2) Create an empty set. The distance between the two nodes i and j will be equal to dist (i, LCA (i, j)) + dist (j, LCA (i. Distance from the Source (Bellman-Ford Algorithm) | Practice | GeeksforGeeks. ; Loop till queue is empty. You don't need to read input or print anything. 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. If there is an Eulerian path then there is a solution otherwise not. Step 4: Find the minimum among these edges. Practice. A Simple Solution is to use Dijkstra’s shortest path algorithm, we can get a shortest path in O (E + VLogV) time. Output − List of the shortest distance of all vertices from the starting node. Given a Binary Tree and a number k, remove all nodes that lie only on root to leaf path (s) of length smaller than k. Input: V = 5, E = 5, Below is the graph: Here, for the given negative cycle o/p (1->2->3->4->1) ; In fig there has to be Edge from 4–>1 not from 4–>0. First you init the queue by all the positions of A in the grid. Algorithm: Steps involved in finding the topological ordering of a DAG: Step-1: Compute in-degree (number of incoming edges) for each of the vertex present in the DAG and initialize the count of visited nodes as 0. Use two arrays, say dist [] to store the shortest distance from the source vertex and paths [] of size N, to store the number of. Can you solve this real interview question? Shortest Path Visiting All Nodes - You have an undirected, connected graph of n nodes labeled from 0 to n - 1. Step 4: Pick edge 0-1. ; Initialise a priority-queue pq with S and its weight as 1 and a visited array v[]. Create a Set to store all the visited words in current path and once the current path is completed, erase all the visited words. This problem is an extension of problem: Min Cost Path with right and bottom moves allowed. Approach: This problem is similar to finding the shortest path in an unweighted graph. Practice. For Example, in the above binary tree the path between the nodes 7 and 4 is 7 -> 3 -> 1 -> 4 . Initialize dist [] = {INF, INF,. 2K 161 You have an undirected, connected graph of n nodes labeled from 0 to n - 1. Below is BFS based solution. While performing BFS if an edge having weight. The idea is to perform BFS from one of given input vertex (u). The given two nodes are guaranteed to be in the binary tree and nodes are numbered from 1 to N. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge. If there is only one topological sort. In the below map of Ninjaland let say you want to go from S=1 to T=8, the shortest path is (1, 3, 8). Given a Binary Tree of distinct nodes and a pair of nodes. Shortest_Path_Faster_Algorithm is an improvement of the Bellman–Ford algorithm(as well as yours). Set value of count [0] [j] equal to 1 for 0 <= j < N as the answer of subproblem with a single row is equal to 1. Shortest path in Undirected Graph having unit distance | Practice | GeeksforGeeks. Input: grid = {{1,3},{3,2}} Output: 1 Explanation: The grid is- 1 3 3 2 There is a path from (0,0) i,e source to (1,1) i,e destination. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. Paytm. Simple Approach: A naive approach is to calculate the length of the longest path from every node using DFS . e. If no valid path exists then print -1. This problem can be solved using the concept of ageing. Return -1 if it is not possible to visit every edge once. Given a weighted, undirected and connected graph of V vertices and E edges. You are given a weighted undirected graph having n vertices numbered from 1 to n and m edges describing there are edges between a to b with some. Widest Path Problem | Practical application of Dijkstra's Algorithm. Example 2: Input: Output: 1 Explanation: The output 1 denotes that the order is valid. Follow the steps below to solve the problem: Start from the root node of the Binary tree with the initial path sum of 0. Since a policeman is present at the 1 st house, the only path that can be chosen is the 2nd path. A Bellman-Ford algorithm is also guaranteed to find the shortest path in a graph, similar to. No cycle is formed, include it. as first item is by default used to compare. Assume any vertex (let’s say ‘0’) as source and assign dist = 0. Discuss. If you like GeeksforGeeks and would like to. The task is to print the cyclic path whose sum of weight is negative. Approach: The main idea here is to use a matrix (2D array) that will keep track of the next node to point if the shortest path changes for any pair of nodes. Therefore, print 8. In this post, O (ELogV) algorithm for. If a vertices can't be reach from the S then mark the distance as 10^8. Example 1: Input:&nbsp;&nbsp; V = 5, E = 5 adj. Menu. Explanation: Starting from the source node 1, the graph contains cycle as 1 -> 2 -> 3 -> 1. org. Note: One can move from node u to node v only if there's an edge from u to v. Back to Explore Page. used to compare two pairs. Example 1: Input: N = 9 Output: 2 Explanation: 9 -> 3 -> 1, so number of steps are 2. Check if not the base case, then if we have a solution for the current a and b saved in the memory, we. Time Complexity: O (N*M). Solve Problems. If zero or two vertices have odd degree and all other vertices have even degree. Sort all the edges in non-decreasing order of their weight. If there is no possible path, return -1. 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. Explanation: Path is 4 2 1 3. Below is a recursive solution suggested by Arpit Thapar here . distance as 0. Menu. Your task is to complete the function findShortestPath () which takes matrix as input parameter and return an integer denoting the shortest path. This algorithm can be used on both weighted and unweighted graphs. But its worst-case time complexity is still O(V^2). Given adjacency list adj as input parameters . Now, there arises two different cases: Explanation: The shortest path is: 3 → 1 → 5 → 2 → 6. You may start and stop at any node, you may revisit nodes multiple times. not appeared before, then. Example 1: Input: 3 / 2 4 Output: 2 2 $ Explanation : There are 2 roots to leaf paths of length 2 (3 -> 2 and 3 -> 4) Example 2: Input: 10 / 20 30 / 40 60 Output: 2 1 $3 2 $ Explanation: There is 1 root leaf paths of length 2 and 2. Approach 1: By looking at examples we can see that the above simplification process just behaves like a stack. Note: The Graph doesn't contain any negative weight cycle. Expected Time Complexity: O (n*m) Expected Space Compelxity: O (n) Constraints: 1 <= n <= 100. 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. Python3. 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. Given a Directed Graph having V nodes numbered from 0 to V-1, and E directed edges. Auxiliary Space: O (R * C), as we are using extra space like visted [R] [C]. Follow the steps below to solve the problem: Initialize a 3D array that ensures that we don’t visit the same cell again and again. if there a multiple short paths with same cost then choose the one with the minimum number of edges. Given the following&nbsp;grid&nbsp;containing alphabets from A-Z and&nbsp; a string S. It chooses one element from each next row. Given a Binary Tree and a positive integer k. If the popped node is the destination node, return its distance. Also go through detailed tutorials to improve your understanding to the topic. of pq is a pair (weight, vertex). Find minimum number of edges between (1, 5). Edit Distance Using Dynamic Programming (Bottom-Up Approach): . Auxiliary Space: O (R*C), The extra space is used in storing the elements of the visited matrix. Below is algorithm based on set data structure. Input: Num1 = 1033 Num2 = 8179 Output: 6 Explanation: 1033 -> 1733 -> 3733 -> 3739 -> 3779 -> 8779 -> 8179. Find out the minimum steps a Knight will take to reach the target position. A falling path will start at any element in the first row and ends in last row. If a vertices can't be reach from the S then mark the distance as 10^8. Shortest path in a graph from a source S to destination D with exactly K edges for multiple Queries. But if I need to find the actual path,. Exclusively for Freshers! Participate for Free on 21st November & Fast-Track Your Resume to Top Tech Companies. 1) Nodes in the subtree rooted with target node. In this Video, we are going to learn about Shortest Path in DAG. No cycle is formed, include it. package ga; import java. Shortest Path-Printing using Dijkstra's Algorithm for Graph (Here it is implemented for undirected Graph. For example, if the target node is 8 and k is 2, then such nodes are 10 and 14. It uses the Bellman-Ford algorithm to re-weight the original graph, removing all negative weights. From each cell you can either move only to right or down. Input : str = "ABC". Therefore, the number of paths in which the edge occurs = Product of the count of nodes in the two subtrees = 5 * 3 = 15. Else do following steps. Count all possible paths from source to destination in given 3D array. Johnson’s algorithm finds the shortest paths between all pairs of vertices in a weighted directed graph. 2) Create a separate stack to store the path from the root to the current node. It's a common practice to augment dynamic programming algorithms to store parent pointers. In the path list, for each unvisited vertex, add the copy of the path of its. 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 graphExplanation: There exists no path from start to end. Find the distance of the shortest path from Num1. 1) Create an auxiliary array of strings, temp []. e. The valid moves are: Go Top: (x, y) ——> (x – 1, y) Go. Practice. geeksforgeeks. Given an unweighted graph, a source, and a destination, we need to find the shortest path from source to destination in the graph in the most optimal way. Single-Source Shortest Path Problems Input A (undirected or directed) graph G = (V;E) 1 Given nodes s;t nd shortest path from s to t. It defines a path with landmines which are marked as 0. Then the LIP value for cell m [0] [0] will be the answer. Every item of set is a pair. Note that only one vertex with odd degree is not possible in an undirected graph (sum of all degrees is always even in an. e. You are given an Undirected Graph having unit weight, Find the shortest path from src to all the vertex and if it is unreachable to reach any vertex, then return -1 for that vertex. e. Example 1: Input: K = 0 1 / 3 2 Output: 1. The path can only be created out of a cell if its value is 1. You dont need to read input or print anything. Let dp [X] [J] be the shortest path from. Please to report an issue. Feeling lost in the world of random DSA topics, wasting time without progress?. e. An Adjacency List is used for representing graphs. You are. We start BFS from both the roots, start and finish at the same time but using only one queue. You have to return a list of integers denoting shortest distance between each node and Source vertex S. Also, you should only take nodes directly or indirectly connected from Node. In this post, an algorithm to print an Eulerian trail or circuit is discussed. Method 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. (weight, vertex). Dijkstra's shortest path algorithm in Java using PriorityQueue. Queries to find distance between two nodes of a Binary tree. Another method: It can be solved in polynomial time with the help of Breadth First Search. A solution that always finds shortest superstring takes exponential time. Output : 2. The following steps can be followed to compute the result: If the source is equal to the destination then return 0. Shortest Path by Removing K walls. A value of cell 3 means Blank cell. Using the fact that the second shortest path can not contain all the edges same as that in the shortest path. Your task is to complete the function longestPath() which takes matrix ,source and destination as input parameters and returns an integer denoting the longest path. Courses. 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. 4% Submissions: 18K+ Points: 8. Strings are defined as an array of characters. The path can only be created out of a cell if its value is 1. , grid [0] [0]). two pairs. Example 1: Input: V = 2 adj [] = { { {1, 9}}, { {0, 9}}} S = 0 Output: 0 9 Explanation: The source vertex is 0. Sum of weights of path between nodes 1 and 2 = 2. Naive Approach: The simplest approach to solve this problem is to first construct the graph using the given conditions, then find the shortest path between the nodes using a and b using bfs by considering a as the source node of the graph. Compute the minimum number of steps required for each index to reach the end of the array by iterating over indices N – 2 to 1. Approach: For every vertex, we check if it is possible to get the shortest cycle involving this vertex. Time Complexity: The time complexity of this algorithm is O((V-1)!) where V is the number of vertices. Output: 7 3 1 4. You don't need to read input or print anything. We have discussed eulerian circuit for an undirected graph. from above to generate different subsequence. If multiple shortest super-sequence exists, print any one of them. Example1: Input: N = 4, M = 2 edge =. 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. There are 3 different paths from 2 to 3. Example 1: Input: K = 0 1 / 3 2 Output: 1. GfG-Problem Link: and Notes Link: two distinct words startWord and targetWord, and a list&nbsp;denoting wordList&nbsp;of unique words of equal lengths. Given a square maze containing positive numbers, find all paths from a corner cell (any of the extreme four corners) to the middle cell. Dijkstra in 1956. ATTEMPTED BY: 2015 SUCCESS RATE: 86% LEVEL: Medium. Input: root = [2, 1], startValue = 2, destValue = 1. Back to Explore Page. (The values are returned as vector in cpp, as. The Minimum distance of all nodes from Source, intermediate, and destination can be found by doing Dijkstra’s Shortest Path algorithm from these 3. Nodes are labeled from 0 to n-1, the task is to check if it contains a negative weight cycle or not. These paths should no. Note: If the Graph contains. Try all 8 possible positions where a Knight can reach from its position. Read. 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 graphPractice. Approach: The idea is to use Floyd Warshall Algorithm to store the length of all pairs of vertices. Find the length of the shortest transformation sequence from startWord to targetWord. Therefore, BFS is an appropriate algorithm to solve this problem. It shows step by step process of finding shortest paths. The task is to find the minimum sum of a falling path through A. Step 2: Define a function “findLongestFromACell” that takes in a cell’s row and column index, the matrix, and a lookup table. The first time you visit a B, you get the shortest path from A to B. You&nbsp;need to find the shortest distance&nbsp;between a given source cell to a destination cell. Approach: An O (V^3*K) approach for this problem has already been discussed in the previous article. For example, consider below graph. ” we do nothing. Given a 2-D binary matrix of size n*m, where 0 represents an empty space while 1 represents a wall you cannot walk through. Step 1: Pick edge 7-6. You can traverse up, down, right and left. A Graph is a non-linear data structure consisting of vertices and edges. Make sure the graph has either 0 or 2 odd vertices. An obstacle and space are marked as 1 or 0 respectively. Step 3: Drop kth character from the substring obtained. The task is to find the cheapest cost path from given source to destination from K stops. The task is to find the sum of weights of the edges of the Minimum Spanning Tree. Print path from given Source to Destination in 2-D PlanePractice. Follow. It shows step by step process of finding shortest paths. Following is the Backtracking algorithm for Knight’s tour problem. in all 4 directions. So the space needed is O(V). Example 1: Input: V = 2 adj [] = { { {1, 9}}, { {0, 9}}} S = 0 Output: 0 9 Explanation: The source vertex is 0. &nbsp; Example 1: Input: n = 3, edges. Below is the step by step algorithm to solve this problem:Queries to check if the path between two nodes in a tree is a palindrome. Expected Time Compelxity: O (n2*log (n)) Expected Auxiliary Space: O (n2) Constraints: 1 ≤ n ≤ 500. 4% Submissions: 18K+ Points: 8. If current character, i. Problem here, is a generalized version of the. It is based on the idea that there is a cycle in a graph only if there is a back edge [i. Find shortest safe route in a path with landmines; Print all paths from a source point to all the 4 corners of a Matrix; Printing all solutions in N-Queen Problem; Longest path in a Matrix from a specific source cell to destination cell; Count of Possible paths of given Matrix having Bitwise XOR equal to K; Print all unique paths from given. , from a cell (i, j) having value k in a matrix M, we can move to ( i+k, j), ( i-k, j), ( i, j+k), or (i, j-k). In other words a node is deleted if all paths going through it have lengths smaller than k. in order to generate different substring. Shortest Path in Undirected Graph with Unit Weights. Sum of weights of path between nodes 1 and 3 = 5. Shortest path in a directed graph by Dijkstra’s algorithm. Practice. */. Expected Time Complexity: O (N) Expected Auxillary Space: O (1) Constraints: 1 ≤ |S| ≤ 106. ” in our path, we simply pop the topmost element as we have to jump back to parent’s directory. If a vertices can't be reach from the S then mark the distance as 10^8. 1) Initialize distances of all vertices as infinite. Below is an Approximate Greedy algorithm. Time Complexity: O(n*n*L) where n is the length of the input string and L is the maximum length of word in the dictionary. Meet In The Middle solution is similar to Dijkstra’s solution with some modifications. e. Bellman-Ford Algorithm. The red cells are blocked, white cell denotes the path and the green cells are not blocked cells. Given a Binary Tree of size N and an integer K. You have to return a list of integers denoting shortest distance between each node and Source vertex S. Below is the implementation of the approach. 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. Consider a directed graph whose vertices are numbered from 1 to n. Find if possible to visit every nodes in given Graph exactly once based on given conditions. Every item of set is a pair. , a node points to one of its ancestors] present in the graph. Practice this problem. U = 1, V = 3. Input: i = 4, j = 3. Following figure is taken from this source. Jobs. Example 1: Input: Output: 1 Explanation: 3 -&gt; 3 is a cycle Example 2: Input: Output: 0 Explanation: no cycle in the graph. If there is no possible path, return -1. Contests. Remove nodes from Binary Tree such that sum of all remaining root-to-leaf paths is atleast K. 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. In the above algorithm, we start by setting the shortest path distance to the target vertex t as 0 and all other vertices as infinity. Auxiliary Space: O(ALPHABET_SIZE^L+n*L) Approach 2: Using Dynamic Programming. Dijkstra's Shortest Path Algorithm using priority_queue of STL. (The values are returned as vector in cpp, as. The task is to find the minimum number. Going from one node to its left child node is indicated by the letter ‘L’. Examples:. GCD from root to leaf path in an N-ary tree. Count of shortest paths containing (U, V) as an edge = subtreeSize (U) * (N – subtreeSize (V)). 2) Other nodes, may be an ancestor of target, or a node in some other subtree. 2) In weighted graph, minimum total weight of edges to duplicate so that given graph converts to a graph with Eulerian Cycle. Back to Explore Page. Step by step Shortest Path from source node to destination node in a Binary Tree. from above to generate different subsequence. 1 2 3. Nodes are labeled from 0 to n-1, the task is to check if it contains a negative weight cycle or not. Auxiliary Space: O (V+E) If you like GeeksforGeeks and would like to contribute, you can also write an article using write. Below is the implementation of the above approach:Given a Binary Tree of size N, you need to find all the possible paths from root node to all the leaf node's of the binary tree. Minimum steps to reach the target by a Knight using BFS: This problem can be seen as the shortest path in an unweighted graph. e. 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. C++ Program for Shortest distance between two cells in a matrix or grid. While traversing through the safe path, we need to avoid walking adjacent cells of the landmine (left, right, above. The first line of input will have a single positive integer ‘T’, denoting the number of test cases. You are given an Undirected Graph having unit weight, Find the shortest path from src to all the vertex and if it is unreachable to reach any vertex, then return -1 for that vertex. The following code prints the shortest distance from the source_node to all the other nodes in the graph. One possible Topological order for the graph is 3, 2, 1, 0. , we can move to (i+1, j) or (i, j+1) or. , there is a directed edge from node i to node graph[i][j] ). Follow the steps mentioned below to implement the idea: Create a recursive function. 8. Output : 3. Problem: Given the adjacency list and number of vertices and edges of a graph, the task is to represent the adjacency list for a directed graph. Time Complexity: O (R * C), where R is number of rows and C are the number of columns in the given matrix. Practice. Explanation: Path is 4 2 1 3. If all squares are visited print the solution Else a) Add one of the next moves to solution vector and recursively check if this move leads to a solution. Approach: The idea is to use Dijkstra’s shortest path algorithm with a slight variation. Notation: If s is clear from context we may use dist(u)as short hand for dist(s;u). 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 M as number of edges and an integer src as the input parameters and returns an integer array or vector, denoting the vector of distance from src to all nodes. Any such node should be counted only once. C / C++ Program for Dijkstra's shortest path algorithm | Greedy Algo-7. Insert non-lcs characters (in their original order in strings) to the lcs found above, and return the result. The graph is represented as an adjacency. Complete the function printPath() which takes N and 2D array m[ ][ ] as input parameters and returns the list of paths in lexicographically increasing order. countSub (n) = 2*Count (n-1) - Repetition. The vertices are sometimes also referred to as nodes and the edges are lines or arcs that connect any two nodes in the graph. Given a boolean matrix of size RxC where each cell contains either 0 or 1, modify it such that if a matrix cell matrix [i] [j] is 1 then all the cells in its ith row and jth column will become 1. Given a Binary Tree of distinct nodes and a pair of nodes.