You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The DFS algorithm we start from starting point and go into depth of graph until we reach a dead end and then move up to parent node (Backtrack). The stack is used to implement DFS.
310
316
@@ -313,21 +319,22 @@ The DFS algorithm we start from starting point and go into depth of graph until
| Search from root to the leaf| Search level by level|
327
-
| Uses Stack to sort | Uses Queue to sort|
328
-
| Time complexity: Fast| Time complexity: Slow|
329
-
| Where to use: if you can find at root or leaf, find connected components. | Where to use: Find shortest path,find connected components. When you think you have less data go for it.|
330
-
| Time Complexity: O(V+E) | Time Complexity: O(V+E)|
| Search level by level | Search from root to the leaf|
334
+
| Uses Queue to sort | Uses Stack to sort|
335
+
| Time complexity: Slow| Time complexity: Fast|
336
+
| Where to use: solution is not far from the root of the tree,If the tree is very deep and solutions are rare, If solutions are frequent but located deep in the tree, | Where to use: tree is very wide|
337
+
| Time Complexity: O(V+E) | Time Complexity: O(V+E)|
331
338
332
339
### Binary Tree
333
340
@@ -385,7 +392,31 @@ It is just like a dictionary or key value pair.
385
392

386
393
387
394
Graph represents network. It has Nodes, Vertices and Edges.
0 commit comments