0% found this document useful (0 votes)
39 views

CS2003 DS Lab-8 Binary Tree Traversal

The document describes two questions related to binary trees. Question 1 asks to construct a binary tree for the expression A+B and verify that inorder, preorder, and postorder traversals represent infix, prefix, and postfix notation. Question 2 asks to construct a binary tree from preorder and inorder or postorder and inorder traversals, print the tree's height using a custom function, and write a function to check if two nodes are cousins (same level but different parents).

Uploaded by

Yukti Satheesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

CS2003 DS Lab-8 Binary Tree Traversal

The document describes two questions related to binary trees. Question 1 asks to construct a binary tree for the expression A+B and verify that inorder, preorder, and postorder traversals represent infix, prefix, and postfix notation. Question 2 asks to construct a binary tree from preorder and inorder or postorder and inorder traversals, print the tree's height using a custom function, and write a function to check if two nodes are cousins (same level but different parents).

Uploaded by

Yukti Satheesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

CS2003 Data Structures and Algorithms Lab

Date 09/10/2020 Time : 5 to 6.30pm

Binary Tree and Binary Search Tree

Q1. Recall that inorder traversal of a binary expression tree gives infix notation of the
expression.
A+B 
+

A B

a. Construct a binary tree for the given expression.


b. Perform inorder, preorder, and postorder traversals of the tree and verify that the
traversal sequence represent infix, prefix and postfix notation of the expression

Q2. A. Construct a binary tree T given either {preorder and inorder} or {postorder and
inorder} traversals of the tree.
B. Print height of the tree T that you have constructed. Write your own function for
determining height of the tree.
C. Write a function checkCousins(x, y) that checks whether two nodes in the tree T
are cousins. (nodes in the same level but having different parent)
C
A B
D E F G
Cousins : (D, F) (E, F) , (D,G), (E, G)

You might also like