Presentation tree traversal

13

Transcript of Presentation tree traversal

Page 1: Presentation tree traversal
Page 2: Presentation tree traversal

PRESENTED TO:

MA’M AMNA

Page 3: Presentation tree traversal

PRESENTED BY

Page 4: Presentation tree traversal

ROLL # 1430303MOMINA IDREES

ROLL # 1430278AYESHA TAHIR

ROLL # 1430328UME AYMEN

ROLL # 1430324SOHA NAEEM

Page 5: Presentation tree traversal
Page 6: Presentation tree traversal
Page 7: Presentation tree traversal

Binary tree->binary tree is defined as finite set of node in which number of the children of a node should not exceed more than two .it means the degree of binary tree not then greater then two.

Page 8: Presentation tree traversal

BINARY TREEA

B C

D EF

G

Page 9: Presentation tree traversal

TREE TRAVERSALTRAVERSAL REFERS TO THE

PROCESS OF VISITING (EXAMINING AND/OR

UPDATING) EACH NODE IN A TREE DATA STRUCTURE,

EXACTLY ONCE.

Page 10: Presentation tree traversal

To traverse a non empty binary tree in in-order following three operations are performed Traverse the left sub –tree in in-orderVisit the root nodeTraverse the right sub-tree in in-order

A

B C

D EF G

TRVERSE STARTS FROM THE ROOT NODESince D is the leaf node ,it gets printed ,which is the left child of D.

D

Now B gets printed as it is the parent of the node D

B

Since E is the leaf node ,it gets printed ,which is right child of B

E

Now A gets printed as it is the parent of the node B

A

Since F is the leaf node ,it gets printed ,which is the left child of c

F

Now C gets printed as it is the parent of the node F

C

Since G is leaf node ,it gets printed ,which the right child of C

G

IN ORDER TRAVERSAL

Page 11: Presentation tree traversal

POST -ORDER TRAVERSALPrinting the data in post-order traversal

To traverse a non empty binary tree in post-order following three operations are performed Traverse the left sub –tree in post-orderTraverse the right sub-tree in post-orderVisit the root node

A

B C

DE F G

0

Now A gets printed as it is the parent of the node B

Now C gets printed as it is the parent of the node FSince D is the leaf node ,it gets printed ,which is the left child of D.TRVERSE STARTS FROM THE ROOT NODENow B gets printed as it is the parent of the node D

D E B

Now F gets printed as it is the left child of C

F G C A

Since E is the leaf node ,it gets printed ,which is right child of BNow G gets printed ,as it is the right child of C

Page 12: Presentation tree traversal

a non empty binary tree in pre-order following three operations are performed To traverse Visit the root nodeTraverse the left sub –tree in pre-orderTraverse the right sub-tree in pre-order

PRE-ORDER TRAVERSAL

A

B C

D EF G

Printing the data in pre-order traversal

Traversal starts from the root nodeThe data at the root node i.e. A gets printed

A

Since D is the leaf node ,it gets printed ,which is the left child of B.

D

Now B gets printed as it is the parent of the node D

B

Since E is the leaf node ,it gets printed ,

which is right child of B

E

Now C gets printed as it is the parent of

the node F

C

Since F is the leaf node ,it gets printed ,which is the left child of c

F

Since G is leaf node ,it gets printed ,

which the right child of C

G

Page 13: Presentation tree traversal