Tree Traversals: A Comprehensive Guide with Examples and Applications, Exams of Data Structures and Algorithms

Tree Traversal in data structures- definition and types of traversal algorithms

Typology: Exams

2017/2018

Uploaded on 02/21/2018

Praisesilva
Praisesilva 🇮🇳

4 documents

1 / 72

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
A. Sam Silva
J. Jeya Praise
TREE TRAVERSALS
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48

Partial preview of the text

Download Tree Traversals: A Comprehensive Guide with Examples and Applications and more Exams Data Structures and Algorithms in PDF only on Docsity!

A. Sam Silva

J. Jeya Praise

TREE TRAVERSALS

Synopsis

Introduction

Tree Terminologies

Binary Tree

Tree Traversal

Application

Conclusion

Tree Collection of nodes  (^) The collection can be empty  (^) Consists of finite set of elements, called nodes, and a finite set of directed lines called branches, that connect the nodes.

Structure of Tree H

G
I
F
D E
B
J
A
C

Level 0 Level 1 Level 2 Level 3

ROOT

LEAF

NODE

Basic Tree Concepts  (^) Root

  • (^) Top most element of the tree Root = A  (^) Node
  • (^) Each data item in the tree Node = {A,B,C,D,E,F,G,H,I,J} H
G
I
F
D E
B
J
A
C

Basic Tree Concepts  (^) Degree of node

  • (^) Maximum number of sub-tree of a node Deg {A,B,C,G} = 2 Deg {E} = 1 Deg {D,F,H,I,J} = 0 H
G
I
F
D E
B
J
A
C

Basic Tree Concepts

Terminal Node

  • (^) The node which is not having any sub-tree.
  • (^) It is also called as Leaf {D,H,F,I,J} H
G
I
F
D E
B
J
A
C

Basic Tree Concepts

Non-Terminal Node

  • (^) The node which are having sub-trees {A,B,C,E,G} H
G
I
F
D E
B
J
A
C

Basic Tree Concepts

Level

  • (^) The entire tree structure is leveled in such a way that the root node is always at level 0 {A} - Level 0 {B,C} - Level 1 {D,E,F,G} - Level 2 {H,I,J} - Level 3 H
G
I
F
D E
B
J
A
C

Basic Tree Concepts

Edge

  • (^) The line drawn from one node to another node is called edge B
A
C

EDGE

Basic Tree Concepts

Depth

  • (^) The maximum level of any node is called depth
  • (^) i.e. The longest path in the tree  (^) LEVEL 3 H
G
I
F
D E
B
J
A
C

Basic Tree Concepts

Forest

  • (^) It is a set of disjoint trees
  • (^) If the root is removed, then any tree becomes a forest H
G
I
F
D E
B
J
C

Binary Search Tree

  • (^) A binary search tree is a special binary tree, which may be empty or not
  • (^) It should have the following characteristics  (^) Every node will have a value  (^) No node can have same value  (^) Value (left) < value (parent)  (^) Value (right) > value (parent)

Operations

  1. Node Insertion
  2. Node Deletion
  3. Searching a Node
  4. Traversing