You are on page 1of 2

Unlike linear data structures like Array, Linked List, Queues, Stacks, etc) which

have only one logical way to traverse them, But trees can be traversed in
different ways. Following are the generally used ways for traversing trees.

Consider above binary tree

In Biary tree there are two different types of traversal

1. Depth First Traversal and

2. Breadth First Traversal

In Depth First Traversal, can traverse in three manner

1.Inorder-(Left, Root,Right) ----(4,5,2,1,6,3,7)

2.preorder(Root,Left,Right)---(1,2,4,5,3,6,7)

3.post order(Left,Right,Root)---(4,5,2,6,7,3,1)

Breadth FirstTraversal: 1,2,3,,4,5,6,7( refer the picture for easy understanding)


Depth First Search Applications

1. Basically binary tree search is used for applications like data is constantly entering or leaving
such as map and set objects in programming languages.
2. To create syntax tree in compiler design, for simple example , for an expression x=a+b*c,
processor not knowing in which manner the expression has to evalute. Using with syntax
tree can set the manner of evaluation like (b*c) then + C or a+b the *C.
3. Detecting cycle in a graph
A graph has cycle if and only if we see a back edge during DFS. So we can run DFS for the graph and check
for back edges. 
4. Solving puzzles with only one solution, such as mazes. (DFS can be adapted to find all solutions to a maze
by only including nodes on the current path in the visited set.)
5. Huffman Coding Tree (Chip Uni) - used in compression algorithms, such as those used by the .jpeg and .mp3 file-
formats.

2. Breadth First Search Applications

1) Peer to Peer Networks. In Peer to Peer Networks like BitTorrent, Breadth First Search is used to find all neighbor
nodes.

2) Broadcasting in Network: In networks, a broadcasted packet follows Breadth First Search to reach all nodes. Since
broadcasting done through neighbour device, which is possible BFS.

3) GPS Navigation systems: Breadth First Search is used to find all neighboring locations.

4) Finding all nodes within one connected component: We can either use Breadth First or Depth First Traversal to
find all nodes reachable from a given node. Since every node is connected in BFS

5) Path Finding We can either use Breadth First or Depth First Traversal to find if there is a path between two
vertices. Since every node is connected in BFS

You might also like