0% found this document useful (0 votes)
54 views6 pages

DS Unit 3 2M

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views6 pages

DS Unit 3 2M

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIT-III

PART-A
1. Define Tree.
A Tree is a collection of one or more nodes with a distinct node called the root , while
remaining nodes are partitioned as T1 ,T2, ..,Tk , K≥ 0 each of which are sub trees, the edges of
T1,T2,…,Tk are connected the root.

2. Give some applications of Trees.


 Implementing the file system of several operating systems.
 Evaluation of arithmetic expression.
Set representation.
Gaming/Decision making problems.
3. Define node, degree, siblings, depth/height, level.
Node: A node is an item of information with branches to other items.
Degree: The number of subtrees of a node is called is degree.
Siblings: The children of the same parent is said to be siblings.
Level: The level of a node is defined recursively by assuming the level of the root to be one
and if a node is at level l, then its children at level l+1.
Depth/Height: The depth/height of a tree is defined to be the level of a node which is
maximum.
4.Define a path in a tree.
A path in a tree is a sequence of distinct nodes in which successive nodes are connected
by edges in the tree.
5.Define terminal nodes in a tree.
A node which has no children is called a terminal node.It is also referred as a leaf
node.these nodes have a degree as zero.
6. Define nonterminal nodes in a tree
All intermediate nodes that traverse the given tree from its root node to the terminal
nodes are referred as terminal nodes.
7.Define a Binary Tree.
A Binary Tree is a tree,which has nodes either empty or not more than two child
nodes,each of which may be a leaf node.
8.Define a full binary tree.
A full binary tree,is a tree in which all the leaves are on the same level and every non-leaf
node has exactly two children.
9.Define a complete binary tree.
A complete binary tree is a tree in which every non-leaf node has exactly two children
not necessarily to be on the same level.
10.Define a right-skewed binary tree.
A right-skewed binary tree is a tree,which has only right child nodes.
11.State the properties of a Binary Tree.
 Maximum No. of nodes on level n of a binary tree is 2^(n-1),where n>=1.
 Maximum No. of nodes in a Binary tree of height is 2^(n-1),where n>=1.
 For any non-empty tree,nl=nd+1 where nl is the number of leaf nodes and nd is the no. of
nodes of degree 2.
12.What are the different ways of representing a Binary Tree?
 Linear Representation using Arrays.
 Linked Representation using Pointers.
13.State the merits of linear representation of binary trees.
 Store methods is easy and can be easily implemented in arrays.
 When the location of the parent/child node is known,other one can be determined easily.
 It requires static memory allocation so it is easily implemented in all
programming languages.
 Insertions and deletions are tougher.
14. State the DISADVANTAGES of linear representation of binary trees.
 Processing consumes excess of time.
 Slow data movements up and down the array.

15. Define Traversal.


Traversal is an operation which can be performed on a binary tree is visiting all the
nodes exactly once.
Inorder: traversing the LST, visiting the root and finally traversing the RST.
Preorder: visiting root, traversing LST and finally traversing RST.
Post- order: traversing LST, then RST and finally visiting root.

16.What are the tasks performed while traversing a binary tree?


 Visiting a node
 Traverse the left structure
 Traverse the right structure.

17.What are the tasks performed during preorder traversal?


 Process the root node
 Traverse the left subtree
 Traverse the right
subtree. Ex : +AB
18.What are the tasks performed during inorder traversal?
 Traverse the left subtree
 Process the root node
 Traverse the right
subtree. Ex : A+B

19.What are the tasks performed during postorder traversal?


 Traverse the left subtree
 Traverse the right subtree.
 Process the root node.
Ex : AB+

20. Give the pre & postfix form of the expression (a + ((b*(c-e))/f).

21.Define a Binary Search Tree.


A Binary Search Tree is a special binary tree,which is either empty or if it is
empty it should satisfy the conditions given below:
 Every node has a value and no two nodes should have the same value(Values should be
distinct).

The value in any left subtree is less than the value of its parent node.
The value in any right subtree is greater than the value of its parent node.
22.What do u mean by General trees?
General Tree is a tree with nodes having any number of children.

23. Define Forest.


A forest is a collection on N(N>0) disjoint tree or group of trees are called forest. If the
root is removed from the tree that tree becomes a forest.
24.Define balanced search tree.
Balanced search tree have the structure of binary tree and obey binary search tree properties
with that it always maintains the height as O(log n) by means of a special kind of rotations. Eg.
AVL, Splay, B-tree.

25. Define AVL tree.


An empty tree is height balanced. If T is a non-empty binary tree with TL and TR
as Its left and right subtrees, then T is height balanced if
1. TL and TR are height balanced.
2. | hL - hR | ≤ 1.
Where hl and hr are the height of TL and TR respectively.

26.What are the drawbacks of AVL trees?


The drawbacks of AVL trees are
 Frequent rotations
 The need to maintain balances for the tree’ s nodes
 Overall complexity, especially of the deletion operation.

27. What is a heap?


A heap is a partially ordered data structure, and can be defined as a binary tree
assigned to its nodes, one key per node, provided the following two conditions
are met
 The tree’s shape requirement-The binary tree is essentially complete, that is all
the leaves are full except possibly the last level, where only some rightmost leaves
will be missing.
 The parental dominance requirement-The key at each node is greater that or equal
to the keys of its children

28.What is the main use of heap?


Heaps are especially suitable for implementing priority queues. Priority queue is a set of
items with orderable characteristic called an item’s priority, with the following operations
 Finding an item with the highest priority
 Deleting an item with highest priority
 Adding a new item to the set

29.Give three properties of heaps?


The properties of heap are
 There exists exactly one essentially complete binary tree with ‘n’ nodes. Its height is equal to
log2n
 The root of the heap is always the largest element
 A node of a heap considered with all its descendants is also a heap
30.Give the main property of a heap that is implemented as an array.

A heap can be implemented as an array by recording its elements in the top-down, left-to-right
fashion.
It is convenient to store the heap’s elements in positions 1 through n of such an array. In such a
representation
 The parental node keys will be in the first n/2 positions of the array, while the leaf keys will
occupy the last n/2 positions
 The children of a key in the array’s parental position ‘i’ (1 i n/2) will be in positions 2i and
2i+1and correspondingly, the parent of the key in position ‘i’ (2 i n) will be in position i/2.
31.What are the two alternatives that are used to construct a heap?
The two alternatives to construct a heap are
 Bottom-up heap construction
 Top-down heap construction
32.Give the pseudocode for Bottom-up heap construction.
ALGORITHM HeapBottomUp(H[1..n])
//Constructs a heap from the elements of the given array
//Input An array H[1..n] of orderable elements
//Output A heap H[1..n]
for I n/2 downto 1 do
k I ; v H[k] heap false while not heap and 2*k n do j 2*k if j < n
if H[j] < H[j+1] j j+1
if v H[j]
heap true
else H[k] H[j]; k j
H[k] v
33.What is the algorithm to delete the root’s key from the heap?
ALGORITHM
 Exchange the root’s key with the last key K of the heap
 Decrease the heap’s size by one
 “Heapify” the smaller tree by sifting K down the tree exactly in the same way as
bottom-up heap construction. Verify the parental dominance for K: if it holds stop
the process, if not swap K with the larger of its children and repeat this operation
until the parental dominance holds for K in its new position.

34.Who discovered heapsort and how does it work?


Heapsort was discovered by J.W.J. Williams. This is a two stage process that
works as follows
 Stage 1 Heap construction: construct a heap for a given array.
 Stage 2 Maximum deletions: Apply the root deletion operation n-1 times to the
remaining heap

35.What is a min-heap?
A min-heap is a mirror image of the heap structure. It is a complete binary tree in which
every element is less than or equal to its children. So the root of the min-heap contains the
smallest element.A B-tree of order m in an m-way search tree that is either empty or is of height
≥1 and

1. The root node has at least 2 children

2. All nodes other than the root node and failure nodes have at least m/2 children.

3. All failure nodes are at same level.

38. Define Binary Heap?

A Binary Heap is a complete binary tree in which the key value of any node must be
lesser than its children is called min heap. If the key value of any node is greater than its children
is called max heap.Binary heap is also called as partially ordered tree.

39. Explain array implementation of Binary Heap.

For any element in the array position ‘i’, the left child is at the position ‘2i’, the right
child is at the position ‘2i+1’ and parent is at the position ‘i/2’.
PART-B

1. Write an algorithm for preorder, inorder and postorder traversal of a binary tree.
2. Explain the following operations on a binary search tree with
suitable algorithms
i. Find a node
ii. Find the minimum and maximum elements of binary search tree.
3. Write an algorithm for inserting and deleting a node in a binary search tree.
4. Describe the concept of threaded binary tree with example.
5. Discuss in detail the various methods in which a binary tree can be represented. Discuss
theadvantage and disadvantage of each method.

6. Consider the following list of


numbers14,15,4,9,7,18,3,5,16,4,20,17,9,14,5.Using that construct abinary search tree.
7. Construct B Tree of order m=5 for the following keys
1,12,8,2,25,5,14,28,17,7,52,16,48,68,3,26,29,53,55,45.Delete the keys 8 and 55.State the
rules for deletion.
8. Discuss how to insert an element in a AVL tree and explain with algorithm.
9. Explain how deletion can take place in AVL trees with suitable algorithm
10. What are AVL trees? Describe the different rotations defined for AVL tree.
11. Analyze the operations of B-tree using 2-3 tree with example.
12. Explain the construction of expression tree with example. Give the applications of trees
14.Illustrate the construction of binomial heaps and its operations with a suitable example.
15.Illustrate how the delete operation is performed on binary heap?
13. Write suitable operations for percolate up and percolate down operations in a binary
heap.

You might also like