Professional Documents
Culture Documents
MANOJ ROLLNO:10
1.Write a C program to perform all the operations of single linked list
Output
2. a) Explain AVL trees with example.
In computer science, an AVL tree is a self-balancing binary search tree. It was the first such data
structure to be invented.[2] In an AVL tree, the heights of the two child subtrees of any node differ by at
most one; if at any time they differ by more than one, rebalancing is done to restore this property. Lookup,
insertion, and deletion all take O(log n) time in both the average and worst cases, where n is the number
of nodes in the tree prior to the operation. Insertions and deletions may require the tree to be rebalanced
by one or more tree rotations.
Here we see that the first tree is balanced and the next two trees are not balanced
In the second tree, the left sub tree of C has height 2 and the right sub tree
has height 0, so the difference is 2. In the third tree, the right sub tree
of A has height 2 and the left is missing, so it is 0, and the difference is 2
again. AVL tree permits difference (balance factor) to be only 1.
Right Rotation
AVL tree may become unbalanced, if a node is
inserted in the left subtree of the left subtree.
The tree then needs a right rotation.
if stack is full
return null
endif
top ← top + 1
stack[top] ← data
end procedure
Pop Operation
Accessing the content while removing it from the
stack, is known as a Pop Operation. In an array
implementation of pop() operation, the data
element is not actually removed, instead top is
decremented to a lower position in the stack to
point to the next value. But in linked-list
implementation, pop() actually removes data
element and deallocates memory space.
A Pop operation may involve the following steps −
• Step 1 − Checks if the stack is empty.
• Step 2 − If the stack is empty, produces an
error and exit.
• Step 3 − If the stack is not empty, accesses the
data element at which top is pointing.
• Step 4 − Decreases the value of top by 1.
• Step 5 − Returns success.
Algorithm for Pop Operation
A simple algorithm for Pop operation can be
derived as follows −
begin procedure pop: stack
if stack is empty
return null
endif
data ← stack[top]
top ← top - 1
return data
end procedure