ADSA
ADSA
Binomial Heaps
Binomial Heaps are a type of heap data structure that supports efficient merging of two heaps. They
consist of a collection of binomial trees, each of which has a specific structure.
Detailed Explanation:
• Binomial Tree:
o Properties: The root node has k children, and each child is the root of a binomial tree
of order k-1.
• Heap Properties:
o Each binomial tree within the binomial heap must satisfy the min-heap property: the
key of each node is greater than or equal to the key of its parent.
o There can be at most one binomial tree of each order in a binomial heap.
• Operations:
o Insert: Insert a new element by creating a binomial tree of order 0 and merging it
with the existing heap.
o Find Min: To find the minimum element, scan all root nodes of binomial trees. The
smallest key among these roots is the minimum element.
o Extract Min: Remove the root of the binomial tree containing the minimum key and
adjust the heap by merging its subtrees.
o Union: Combine two binomial heaps by merging trees of the same order.
o Decrease Key: Reduce the key value of a node and adjust the tree to maintain heap
properties.
o Delete: Decrease the key of the node to negative infinity to bring it to the root and
then extract it.
• Advantages:
o Efficient merging operations, making binomial heaps suitable for priority queue
applications.
• Disadvantages:
• Use Cases:
o Useful in graph algorithms like Prim's and Dijkstra's where efficient merging of
priority queues is required.
2. AVL Tree
AVL Trees are self-balancing binary search trees named after their inventors Adelson-Velsky and
Landis. They maintain a balanced tree structure to ensure efficient operations.
Detailed Explanation:
• Structure:
o Each node in an AVL tree has a balance factor, which is the height difference
between its left and right subtrees.
o The balance factor of each node must be -1, 0, or 1 to ensure the tree remains
balanced.
• Operations:
o Insertion: Insert a new node as in a standard binary search tree. After insertion,
update the balance factors of the ancestors. If an imbalance occurs, perform
rotations to restore balance.
o Deletion: Remove a node as in a standard binary search tree. After deletion, update
the balance factors of the ancestors and perform rotations to restore balance.
o Search: Traverse the tree using binary search principles to locate the desired node.
• Rotations:
o Single Rotations:
▪ Left Rotation (LL Rotation): Used when a node becomes unbalanced due to a
new node being inserted into the left subtree of the left child.
▪ Right Rotation (RR Rotation): Used when a node becomes unbalanced due to
a new node being inserted into the right subtree of the right child.
o Double Rotations:
• Advantages:
o AVL trees provide strict balance, ensuring O(log n) time complexity for insertions,
deletions, and searches.
o Useful for applications requiring frequent insertions and deletions with guaranteed
balanced structures.
• Disadvantages:
o Rotations introduce additional complexity and overhead in maintaining the balance
during insertions and deletions.
• Use Cases:
3. Splay Tree
Splay Trees are self-adjusting binary search trees that move frequently accessed elements closer to
the root to improve access times.
Detailed Explanation:
• Structure:
o A standard binary search tree structure with an additional splay operation that
moves accessed nodes to the root.
• Operations:
o Splaying: Move an accessed node to the root using a series of tree rotations:
▪ Zig (Single Rotation): Performed when the accessed node is a child of the
root.
▪ Zig-Zig (Double Rotation): Performed when the accessed node and its parent
are both left or right children.
▪ Zig-Zag (Double Rotation): Performed when the accessed node is a left child
and its parent is a right child, or vice versa.
o Insertion: Insert a node as in a binary search tree and splay it to the root.
o Deletion: Splay the node to be deleted to the root and remove it.
• Self-Adjusting Nature:
o Frequently accessed elements move closer to the root, reducing access times for
subsequent operations.
• Advantages:
o Simpler than other self-balancing trees as they do not require maintaining balance
factors or additional properties.
• Disadvantages:
o Worst-case time complexity for individual operations can be O(n) if the tree becomes
unbalanced.
• Use Cases:
o Suitable for caches, network routers, and applications with non-uniform access
patterns.
Double Ended Queue (Deque) is a versatile linear data structure that allows insertion and deletion
from both ends.
Detailed Explanation:
• Structure:
• Operations:
• Advantages:
• Disadvantages:
• Applications:
o Undo Mechanisms in Text Editors: Supports adding and removing actions from both
ends of the list.
Doubly Linked Lists are linear data structures where each node contains data and two pointers, one
to the next node and one to the previous node.
Detailed Explanation:
• Structure:
o Each node has three components: data, a pointer to the next node, and a pointer to
the previous node.
• Operations:
o Insertion:
▪ At the beginning: Insert the new node as the new head of the list.
▪ At the end: Insert the new node as the new tail of the list.
▪ At a specified position: Traverse to the position and insert the new node.
o Deletion:
▪ From a specified position: Traverse to the position and remove the node.
o Traversal:
▪ Forward traversal: Traverse the list from the head to the tail using the next
pointers.
▪ Backward traversal: Traverse the list from the tail to the head using the
previous pointers.
• Advantages:
• Disadvantages:
o Increased Memory Usage: Each node requires additional memory for the previous
pointer.
o Complexity: Managing two pointers for each node adds complexity to the
implementation.
• Applications:
o Data Structures: Serve as a foundation for other data structures like deques and
complex linked lists.