Download 1. Define tree? root Trees are non-liner data structure, which is used

yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Linked list wikipedia, lookup

Quadtree wikipedia, lookup

Lattice model (finance) wikipedia, lookup

B-tree wikipedia, lookup

Red–black tree wikipedia, lookup

Interval tree wikipedia, lookup

Binary tree wikipedia, lookup

Binary search tree wikipedia, lookup

1. Define tree?
Trees are non-liner data structure, which is used to store data items in a shorted sequence. It
represents any hierarchical relationship between any data Item. It is a collection of nodes, which has a
distinguish node called the root and zero or more non-empty sub trees T1, T2,….Tk. each of which are
connected by a directed edge from the root.
2. Define Height of tree?
The height of n is the length of the longest path from root to a leaf. Thus all leaves have height zero.
The height of a tree is equal to a height of a root.
Give Example.
3. Define Depth of tree?
For any node n, the depth of n is the length of the unique path from the root to node n. Thus for a
root the depth is always zero.
Give Example.
4. Define Degree of a node?
It is the number of sub trees of a node in a given tree.
Give Example.
5 define Degree of a tree?
It is the maximum degree of a node in a given tree.
Give Example.
6.Define Terminal node or leaf?
Nodes with no children are known as leaves. A leaf will always have degree zero and is also
called as terminal node.
Give Example.
7. Define Non-terminal node?
Any node except the root node whose degree is a non-zero value is called as a non-terminal
node. Non-terminal nodes are the intermediate nodes in traversing the given tree from its root node to
the terminal node.
Give Example.
8.Define sibling?
Nodes with the same parent are called siblings.
Give Example.
9.Define binary tree?
A Binary tree is a finite set of data items which is either empty or consists of a single item
called root and two disjoin binary trees called left sub tree max degree of any node is two.
Give Example.
10.Define expression tree?
Expression tree is also a binary tree in which the leafs terminal nodes or operands and nonterminal intermediate nodes are operators used for traversal.
Give Example.
11.Construction of expression trees?
1.convert the given infix expression into postfix notation
2. Create a stack and read each character of the expression and push into the stack, if
operands are encountered.
3.when an operator is encountered pop 2 values from the stack. From a tree using the
12.Define lazy deletion?
When an element is to be deleted it is left in the tree itself and marked a s being deleted.
This is called as lazy deletion and is an efficient procedure if duplicate keys are present in the binary
search tree, because the field that keeps count of the frequency of appearance of the element can be
decremented of the element can be decremented.
13.Define AVL tree?
AVL tree also called as height balanced tree .It is a height balanced tree in which every
node will have a balancing factor of –1,0,1 Balancing factor Balancing factor of a node is given by the
difference between the height of the left sub tree and the height of the right sub tree.
14.what are the various operation performed in the binary search tree ?
4.find min
5.find max
15. What are the various transformation performed in AVL tree?
1.single rotation
single Left rotation
single Right rotation
2.double rotation
-Left Right rotation
-Right Left rotation
16. General idea of hashing and what is the use of hashing function?
A hash table similar to an array of some fixes size-containing keys. The keys specified here
might be either integer or strings, the size of the table is taken as table size or the keys are mapped on
to some number on the hash table from a range of 0 to table size
17. what is priority queue?
A priority queue is a data structure that allows at least the following two operations: insert
which does the obvious thing; and Delete in, which finds, returns, and removes the minimum element
in the priority queue. The Insert operation is the equivalent of Enqueue
18.Application of priority queues?
1.For scheduling purpose in operating system 2.used for external sorting
3.important for the implementation of greedy algorithm, which operate by repeatedly finding a
19.what are the main properties of a binary heap?
1.structure property
2.heaporder property
20. Define tree traversal and mention the type of traversals?
Visiting of each and every node in the tree exactly is called as tree traversal
Three types of tree traversal
1.inorder traversal
2.preoder traversal 3.postorder traversal.
21. Define the following terms: node, leaf node, sub tree, ancestors, siblings of a node
Each element of a binary tree is called node of a tree.
Each node may be a root of a tree with zero or more subtrees.
Leaf node:
A node with no children(successor) is called leaf node or terminal node.
A node with all of its descendants is called subtree or subset.
Give ex.
Node n1 is an ancestor of node n2 if n1 is either a father of n2 or father of some
ancestor of n2.
Give ex.
Two nodes are siblings if they are left and right sons of same father.
Give ex.
22. Define level of a node, degree of a node, degree of a tree, height and depth of a tree.
Level of a node: The root node is at level 1. If a node is at level l, then its children are at level
Give eg.
The number of subtrees of a node is called as degree of a node.
Give ex.
The degree of a tree is the maximum of the degree of the nodes in the tree.
Give ex.
The height or depth of a tree is defined to be the maximum level of any node in the tree.
Give eg.
23. What are the ways to represent Binary trees in memory?
1. Array representation (or) Sequential Representation.
2. Linked List representation (or) Node representation.
Give simple example for each representation.
24. Define binary tree.
Binary tree:
Binary tree is a finite set of elements that is either empty or is partitioned into three
disjoint subsets. The first subset contains the single element called the root of tree. The
other two subsets are themselves binary tree called the left and right sub tree of original
tree. Give ex.
25. Define Full binary tree:
A full binary tree of depth k is a binary tree of depth k having 2k – 1 nodes where k  0.
In other words, all the levels in the binary tree should contain the maximum number of
Give eg.
26. Define Complete binary tree:
A binary tree with n nodes & depth k is complete iff its nodes correspond to the nodes
numbered from 1 to n in the full binary tree of depth k.
In other words, Complete binary tree is a binary tree in which all the levels must be
filled from the left to right. After filling one level then only we can move on to the next
Give eg.
Full and Complete binary trees are different. All full binary trees are
complete binary trees but not vice versa.
27. List out few of the Application of tree data-structure?
The manipulation of Arithmetic expression,
Symbol Table construction,
Syntax analysis.
28. Traverse the given tree using Inorder, Preorder and Postorder traversals.
Given tree:
 Inorder : D H B E A F C I G J
 Preorder: A B D H E C F G I J
 Postorder: H D E B F I J G C A
29. A binary tree with 20 nodes has how many null branches?
21 null branches
Let us take a tree with 5 nodes (n=5)
Null Branches
It will have only 6 (ie,5+1) null branches. In general,
A binary tree with n nodes has exactly n+1 null nodes. Thus a binary tree with 20 nodes will have
21 null branches.
30. How many different trees are possible with 10 nodes ?
1014 trees.
For example, consider a tree with 3 nodes(n=3), it will have the maximum combination of 5
different (ie, 23 - 3 = 5) trees.
In general:
If there are n nodes, there exist 2n-n different trees.
31. In the given binary tree, using array you can store the node 4 at which location?
NODE 4 is stored at LOCATION 5.
The root node is stored at location 0. The left child of the node at location i is stored in location
2i+1 & the right child of it is stored in location 2i+2
32. Draw a binary Tree for the expression :
A * B - (C + D) * (P / Q)
7 8 9 10 11 12
33. Define expression tree?
An expression tree is built up from the simple operands and operators of
an(arithmetic or logical) expression by placing the simple operands as the leaves of a
binary tree and the operators as the interior nodes.
Give simple ex.
34. What is meant by fully threaded binary tree (or) 2-way threaded binary tree? How do you
construct a threaded binary tree?
In a right threaded binary tree each null right link is replaced by a special link to the successor of
that node under inorder traversal,called a right thread. In a left threaded binary tree,each null left link is
replaced by a special link to the predecessor of the node under inorder traversal called a left thread. In a
fully threaded binary tree, the null left link is replaced by the inorder predecessor ( left thread) & the
null right link is replaced by the inorder successor(right thread).
Give simple eg.
35. What are the advantages of threaded binary tree over ordinary binary trees?
Threaded binary tree is a simple modification to the ordinary binary tree structure.
The Null links in the binary tree are replaced by pointers called threads.
1. A 0 right child is replaced by the inorder successor.
2. A 0 left child is replaced by the in order predecessor.
This modifications allows inorder traversal of a binary tree without any recursion that
uses no stack.
Node structure of a threaded binary tree is
Left Thread
Left Child
Right Child
Right Thread
Left thread and right thread fields are Boolean. If left thread = true, then the left child
field contains the thread, otherwise it contains pointer to the left child.
36. What is a binary search tree? How will u construct such tree?
A binary search tree is a binary tree. It may be empty. If it is not empty then, it satisfies the
following properties.
1. Every element has a key & the keys are distinct.
2. The keys in the left sub tree is smaller than the key in the root.
3. Keys in the right sub tree is larger than the key in the root.
4. The left & right sub trees are also BST.
Construction of a BST:
1. Make the first node as the root node.
2. To insert the next node into the BST, search for the value in the BST. If the value is found in the
BST, then a duplicate value cannot be inserted into the BST.
If the element is not found, add the element at the point where the search bocpmes
37.Is the following tree an AVL tree Justify Your Answer?
Computing balance factors for AVL representation results in 0,-1,1.Therefore the
given tree is a AVL tree.
38. What is the minimum number of nodes in an AVL tree of height 5?
39. What is the use of sentinel value in binary heap?
40. What are the properties of Binary Heap?
41. Explain the representation of Priority Queue?
42. Define the tree terminology?
43. What is a binary search tree/
44. List out the steps involved in deleting a node from a binary search tree?
45. Show that the maximum number nodes in a binary tree of height is 𝟸ͪ⁺¹-1
46. A full node is a node with 2 children. Prove that the number of full nodes plus one is
equal to number of leaves in a non empty binary tree.
47. What are the collision resolution methods.
48. Give the advantages and disadvantages of linear probing.
49. Types of binary tree.
1) Skewed Tree
All the nodes as queued in one direction.
2) Left Skewed Tree
All nodes are skewed in left side
3) Right skewed Tree
All nodes are skewed in right side
4) Strictly Binary tree
If every non leaf node in a binary tree has non-empty left and right sub trees. the tree is
termed as strictly binary tree (each node degree will be either zero or two)
50. Difference between Tree and Binary Tree.
Tree cannot be empty
Each element in a tree can have
any element of sub trees
Sub trees in a tree are unordered
Binary Tree
Can be empty
Each element can have at most
two sub trees
In a binary tree ,there is a
distinction between left and right
49. How many nodes in a complete binary tree?
No. of nodes at each level l = 2 l
So, 20 + 21 + 22 + . . . 2 d = ∑= 2 d+1 -1
50)Define almost complete binary tree.
A binary tree of depth d is an almost complete binary tree if,
1) The leaves are the level d &d-1
2) For any node in the tree with right descendent must have left descendent.
51) What are the applications of binary tree?
Binary trees are useful for
a) Finding the duplicates of a list of numbers
b) Easy sorting
c) Easy searching of elements from a list of numbers.
52)What are the types of tree traversals?
Tree traversal is the order of visiting the nodes in a tree.
3 types
1) Pre order
2) In order
3) Post order
53) Define pre order traversal
1) Visit the root
2) Traverse the left sub tree in preorder
3) Traverse the right sub tree in preorder
Pre order traversal – A B D E C F
54) Define in order traversal
1) Traverse the left sub tree in inorder
2) Visit the root
3) Traverse the right sub tree in inorder
For the above tree, Inorder is D B E A F C
55) Define post order traversal
1) Traverse the left subtree in preorder
2) Traverse the right subtree in preorder
3) Visit the root
For the above tree, Postorder is D E B F C A
56) Define binary search tree
A binary tree that has a property that all elements in the left sub tree of a node is less than the root
value & the right sub tree has greater value the root.
57) What is expression tree?
The binary tree that has operands in the leaves & the operator as the internal nodes, then the tree is
said to be an expression tree.
Eg:- Expression – A*B + C / D
58) What are internal & external nodes?
The leaf nodes are called as external nodes & the non-leaves are called as internal nodes.
59) Explain about implicit array representation of binary tree.
If the binary tree is represented as arrays, if the parent at position p, then the left child is present at
2p+1 & right child at 2p+2.
60) Advantages of linked representation over sequential representation.
 In sequential (array) representation, tree is stored in contiguous blocks of memory, but in
linked representation, pointers connect the nodes.
 If the tree is not an almost complete binary tree, there may be gaps between the nodes &
wastage of spaces.
61) What are the demerits of Linked List?
 In linked list, inserting & deleting an element is easily performed by altering the pointers.
 But finding an kth element is inefficient by traveling from the first element to the k th
 It is not possible to delete a particular element in a singly linked list, given the pointer to
that element.
 It is only possible in a circular list but it is inefficient since traversing the entire list.
 The deletion is efficient in doubly linked list, but it needs more space for two pointers (left &
right) in each node.
62) Suggest an efficient way for traversing the list?
 The linked list can be traversed efficiently by representing the list as binary tree.
 Each internal node has leaf count i.e. no. of leaves in the left sub tree.
63) What is ordered tree?
 An ordered tree is defined as the tree in which the sub trees of each node form an ordered
 The first son is the oldest son.
 The last son is the youngest son.
Ordered tree
64) Represent the node of a general tree in C
struct node
int data;
struct node * next, son;
typedef struct node * nodeptr;
65) Write the routine for inorder traversal for tree.
Void inorder( nodeptr root)
printf(“ %d” ,root->data);
Not an ordered tree
66) Mention the level, depth, internal nodes, external nodes, array representation of
given binary tree
Level -0
Level -1
Level- 2
Level -3
Depth – maximum level -3
Internal nodes – A, B, C, D
External nodes-E, F, G, H
5 6
9 10
1. A binary tree has 8 nodes. The inorder & post order traversal of the tree are given. Draw
the tree & find PreOrder.
PostOrder:F E C H G D B A
InOrder :F C E A B H D G
2. Define a binary search tree with an example and how will you balance it?
3. Given an Unix File System as an input, formulate a routine to list a directory.
4. Write a pgm in c to create Empty binary tree and to search for element X in it.
5. Construct an expression tree for the expression A+ (B-C)*D+ (E*F)
6. (i) Define a binary search tree (BST).Write a routine to insert a node into a BST?
(ii) How do you insert an element in a binary search tree?
7. Show that for the Perfect binary tree of height h containing 𝟸ͪ⁺¹-1 node the sum of the
heights of the nodes is 𝟸ͪ⁺¹-1-(h+1).
8. (i)Write the routines to insert & remove a node from Binary search Tree?.
(ii)A full node is a node with 2 children. Prove that the number of full node Plus one is
equal to the number leaves in a binary tree.
9. (a) Describe AVL Tree and construct the AVL Tree for the following
10 8 12 11 15 7 9
(b) Write algorithm for inserting an element in AVL Tree?
10. (i)Write the Procedure to implement single and double rotations while inserting nodes in
an AVL Tree?
(ii)Show the result of inserting 2,1,4,5,9,3,6,7 into an empty AVL tree?
11. (a) What is an AVL Tree?
(b)Explain about the rotations of AVL Tree?
12. Explain with suitable example the basic heap operations and write algorithms for the
13. Explain in detail about the Binary Heap?
14. How do you insert an element into an AVL Tree?
15. (i)Write a function to generate the AVL Tree of height H with fewest nodes. What is the
running time of your function?
(ii) Write a function to perform DeleteMin in a binary heap?
16. Give one implementation of a Priority Queue and Explain the Routines Used?
17. Explain with example how a node is inserted into an AVL tree.Discuss all possible
18. Write Routines for ADT Operation of AVL Tree?
19. Write Algorithm for ADT Operation of PriorityQueue?
20. Explain all the following operations of binary search trees along with its routines.
Iv)FindMin &FindMax
21. Explain separate chaining in hashing in detail with suitable example
And routines.
22. Describe the basic priority queue operations with routines and examples.
23. Write the source code for binary search tree and explain the operation with examples.
24. Give the best case and worst case analysis of the binary search.
25. Write an algorithm to delete a node from a binary search tree.
26. Give the iterative algorithm for the inorder traversal of a binary tree
27. Write recursive and non recursive algorithms for inorder traversal
28. Explain the representations of binary tree. Discuss about one
application of stack
29. Write an algorithm to delete an element from binary tree
30. The node of the linked list consists of an info and link, write the algorithms for the
(i) Count the number of nodes in the list.
(ii) Change the info field of the k th node to the value given by Y.
(iii) Perform an insertion to the immediate left of the k th node in the list.
(iv) Appends a linear list to another linear list.
31. Write down the algorithm binary search for searching x from an array a[L,n] and give the
stepwise execution for an array (10,12,20,23,27,30,31,39,42,44,45,49,57,63,70)to
search X=44.
32. The exponential growth constant e is charactertzed by the expression
e=1/0!+1/1!+1/2!…. Device an algorithm to compute e to n terms,
33. Explain in detail the Linear Probing technique
34. Write a function to delete the minimum element from a Binary heap.
35. Write a recursive algorithm to determine the following:
(i) The number of nodes in binary tree.
(ii)The sum of the contents of all the nodes in the binary tree.
(iii) The depth of the binary tree.