The document discusses data structures and algorithms. It provides an overview of binary trees, binary search trees, and their traversals. It then discusses graphs and poses questions related to binary trees, binary search tree traversals, and graphs.
2. Agenda
• Data Structure Overview
• Binary Trees
• Binary Search Trees
• Binary Search Tree Traversal
• Binary Tree, BST Questions
• Graph Overview
• Problems & Questions
3. What Is Data Structure?
Program Contains Data
Where the data to be stored?(Capacity)
How the data efficiently handle & used? (Efficiently)
Data structure just a plain container
6. Algorithm & Datastructure
A Program is a combination of Algorithm and
Data Structure
Simple Example:
Addition of two Numbers
Int A,B,C
C= A + B
Program Algorithm Data Structure
Addition Logic is an Algorithm
A & B are Data Structure ‘ elements.
7. Types Of Data Structure
Data Structure
Linear DS Non Linear DS
33. Questions
1) Consider the following tree:
If the post order traversal gives a b – c d * + then
the label of the nodes 1,2,3,4,5,6,7 respectively are
a) +, -, *, a, b, c, d (b) a, b, c, d, -, *, +
(c) a, -, b, +, c, *, d (d) -, a, b, +, *, c, d
34. Questions
2) The number of possible ordered trees with 3
nodes A,B,C is
a) 16 (b)12 c)6
(d)10
35. Questions
3) The depth of a complete binary tree with n
nodes is (log is to the base two)
a) Log (n+1) -1 (b) Log (n)
(c)Log (n-1) +1 (d) Log (n) +1
36. Questions
(a)
Explanation: If the depth of a complete binary tree is d, the number of nodes
n= 2d+1-1
n+1=2d+1 Applying logarithm to base 2 on both sides we have
log 2 (n+1) = d+1(log 2 2)
Therefore d= log 2 (n+1) -1
Total no. of nodes n = (2^(d+1))-1
log (n+1) = d+1
d = log(n+1)-1
41. Questions
A binary search tree contains the values 1,2,3,4,5,6,7 and 8. The tree is
traversed in preorder and the values are printed out. Which of the following
sequences is a valid output
(a)5 3 1 2 4 7 8 6 (b) 5 3 1 2 6 4 9 7
(c)5 3 2 4 1 6 7 8 d) 5 3 1 2 4 7 6 8
42. Questions
The post order traversal of a binary tree is DEBFCA. Find out the preorder
traversal.
(a) ABFCDE (b) ADBFEC (c) ABDECF
d) ABDCEF
44. Questions
If a node having two children is deleted from a binary tree, it is replaced by its
(A)Inorder predecessor B) Inorder successor
(C)Preorder predecessor (D) None of the above
46. Questions
.The number of leaf nodes in a complete binary tree of depth d is
A) 2d (B) 2d–1+1 (C) 2d+1+1 (D)
2d+1
47. Questions
. The pre-order and post order traversal of a Binary Tree generates the same
output. The tree can have maximum
(A)Three nodes (B) Two nodes
C) One node (D) Any number of nodes
49. Questions
In order to get the information stored in a Binary Search Tree in the
descending order, one should traverse it in which of the following order?
(A) left, root, right (B) root, left, right
C) right, root, left (D) right, left, root