lecture Transform and Conquer
lecture Transform and Conquer
•Database lookups
• AVL Tree:
• Balances the tree by ensuring that the height difference
(balance factor) between the left and right subtrees of any node
is at most 1.
• Uses rotations (single or double) to maintain balance after
insertions or deletions.
• Operations: O(logn).
• Red-Black Tree:
• Balances the tree using color properties and ensures no path
from the root to a leaf is more than twice as long as any other.
• Allows slightly more imbalance than AVL trees but performs
fewer rotations.
• Operations: O(logn).
• B-Tree:
• A generalization of a binary search tree that allows nodes to
have more than two children.
• Often used in databases and file systems due to its efficient
handling of large blocks of data.
• Operations: O(logn).
Splay Tree:
•A self-adjusting tree that moves recently accessed elements
closer to the root for faster access in future operations.
•Not strictly balanced but maintains O(logn) amortized
complexity.
Uses of Balanced Search Trees
Steps :
Time Complexity:
O(n+k)
Where n is the number of elements.
k is the range of values.
Space Complexity:
Space: O(n+k)
Radix Sort
Time Complexity:
•Best, Average, Worst: O(n⋅d)
Space Complexity:
•Space: O(n+k)
Bucket Sort
Best Case:
Worst Case:
Average Case:
Time Complexity:
Insertion: O(logn).
Deletion: O(logn).
Heap Sort
Steps:
1.Build a max-heap.
•Time Complexity:
•Space Complexity:
Handling Collisions:
•Iterate the list, finding the minimum element in the unsorted part.
•Swap found minimum element with first element of the unsorted part.
Time Complexity:
performance.
Bubble Sort