Docsity

Binary Search Tree: Concept, Representation, and Operations, Exams of Data Structures and Algorithms

Toggle sidebar
bg1
Umair Khalid
Cpen18111022
Final-2020(DSA) Engr, Hammad Shahab
Q#1:
Pictorial Representation:
BST Tree format of given data
Explanation:
As root key is given that is 8 , then all less values (3,3,1,2,4)on leftSub tree and greater
values (14,44,89) on RightSub tree . As each node has a key and associated value. During
searching the desired key is compared to the keys in BST and if found the associated value is
retrieved.
Q#2:
Binary Search Tree:
In data structure, Binary search tree is a tree in which all nodes follow the following
properties.
There is a one root node.
Left-sub tree contain less values of its root node key.
8
10
3
14
3
44
2
89
5
1
pf3

Partial preview of the text

Download Binary Search Tree: Concept, Representation, and Operations and more Exams Data Structures and Algorithms in PDF only on Docsity!

Umair Khalid

Cpen

Final-2020(DSA) Engr, Hammad Shahab

Q#1:

Pictorial Representation:

BST Tree format of given data

Explanation:

As root key is given that is 8 , then all less values (3,3,1,2,4)on leftSub tree and greater values (14,44,89) on RightSub tree. As each node has a key and associated value. During searching the desired key is compared to the keys in BST and if found the associated value is retrieved.

Q#2:

Binary Search Tree:

In data structure, Binary search tree is a tree in which all nodes follow the following properties. There is a one root node. Left-sub tree contain less values of its root node key. 8 10 3 14 3 44 2 89 1 5

Right-sub tree contain greater values of its root node key.

Explanation:

Divides all sub tree into two parts, the left sub-tree and right sub tree and write as leftSubtree(k) <= node(k) <= RightSubtree(k) First we make representation and mention root node key then all less values on left-sub tree and greater values on right-Sub tree. Operation: We can use Search , insert , preorder Traversal, In-order Traversal, Post-order Traversal Operations.  In search operation start from the root node if data is less than the key value then search from leftSub tree , if greater values then search rightSub tree.  In insert operation first locate proper location ,if data less then insert on leftSubtree if greater than insert on RightSubtree.

Presedence Operation’s Conversion with help of stack:

i+jk+p by using stack operations jk -> jk* i+jk* -> ijk+ ijk++d -> ijk*+p+ (postfix)  First i scanned and added to postfix  Then + scanned and added to stack  Then j scanned and added to postfix  Then * operator …but in stack + which has lower precedence than * … so * will be pushed to the stack  Then k scanned and added to postfix  Then + is scanned but topmost in stack is * which has higher precedence than +  Then p scanned and added to postfix  At the end all character scanned so we must pop remaining elements from stack and added to postfix string

Q#3:

Summary of Lectures:

Lec11: in this lecture we have discuss arrays ,we learn how we use arrays in data

structure and also use in using structure , arrays is a collection of an element values or variable