algo_improtent
algo_improtent
Algorithm:
Explanation:
21. What is the time complexity of a randomized QuickSort in the average case?
Answer: O(nlogn)O(n \log n)O(nlogn)
22. What is the worst-case time complexity of Prim's algorithm (adjacency matrix
representation)?
Answer: b)O(V2)b) O(V^2)b)O(V2)
23. What does Big-O Notation represent?
Answer: a)An asymptotic upper bound of a function.a) \text{An asymptotic upper bound
of a function.}a)An asymptotic upper bound of a function.
24. What is the time complexity of an AVL tree insertion operation?
Answer: O(logn)O(\log n)O(logn)
25. What is meant by a cut vertex in a graph?
Answer: A vertex whose removal increases the number of connected components in the
graph.
26. Which traversal method is used for Depth-First Search (DFS)?
Answer: a)Preorder traversala) \text{Preorder traversal}a)Preorder traversal
27. What is the maximum height of an AVL tree with nnn nodes?
Answer: O(logn)O(\log n)O(logn)
28. How many rotations are required to balance an AVL tree during insertion?
Answer: At most 222 rotations.
29. What is the process where two rotations are required to balance a tree called?
Answer: Double Rotation (Left-Right or Right-Left).
30. What is the main characteristic of a directed acyclic graph (DAG)?
Answer: c)It has no cycles and is directed.c) \text{It has no cycles and is
directed.}c)It has no cycles and is directed.
python
Copy code
def binary_search(arr, low, high, key):
if low > high:
return -1
mid = (low + high) // 2
if arr[mid] == key:
return mid
elif arr[mid] < key:
return binary_search(arr, mid + 1, high, key)
else:
return binary_search(arr, low, mid - 1, key)
1. Graph Algorithms:
o BFS: O(V+E)O(V+E)O(V+E), shortest path for unweighted graphs.
o DFS: Used for detecting cycles, topological sorting.
2. Sorting Algorithms:
o Bubble Sort (Stable, O(n2)O(n^2)O(n2)).
o Quick Sort (Unstable, O(nlogn)O(n \log n)O(nlogn) average).
o Merge Sort (Stable, O(nlogn)O(n \log n)O(nlogn)).
3. Tree Traversals:
o Preorder, Inorder, Postorder for Binary Trees.
4. Hashing Techniques:
o Open Addressing: Linear Probing, Quadratic Probing.
o Collision Resolution: Chaining.
5. Complexities to Remember:
o Insertion Sort: O(n2)O(n^2)O(n2).
o Binary Search: O(logn)O(\log n)O(logn).
o Dijkstra's Algorithm: O(V2)O(V^2)O(V2) (matrix) or O(E+VlogV)O(E + V
\log V)O(E+VlogV) (heap).