0% found this document useful (0 votes)
12 views

algo_improtent

Uploaded by

ranajitbarik2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

algo_improtent

Uploaded by

ranajitbarik2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Based on the provided document, here are some high-probability questions and answers for

2024, extracted and refined for clarity and relevance:

Group A: Multiple Choice Questions

1. Which of the following is asymptotically smallest?


Answer: b)log⁡nb) \log nb)logn
2. Which sorting algorithm has a worst-case time complexity of O(nlog⁡n)O(n \log
n)O(nlogn)?
Answer: a)Merge Sorta) \text{Merge Sort}a)Merge Sort
3. Time complexity of binary search (iteration):
Answer: b)O(log⁡n)b) O(\log n)b)O(logn)
4. What does Prim's algorithm initialize with?
Answer: a)A vertexa) \text{A vertex}a)A vertex
5. A graph is called a tree if:
Answer: c)It is a connected acyclic graph.c) \text{It is a connected acyclic
graph.}c)It is a connected acyclic graph.
6. Time complexity of insertion sort:
Answer: b)Quadraticb) \text{Quadratic}b)Quadratic
7. Hash Table search efficiency:
Answer: c)O(1)c) O(1)c)O(1)
8. Rabin-Karp Algorithm is used for:
Answer: a)String Matchinga) \text{String Matching}a)String Matching
9. Which of the following is a linear data structure?
Answer: a)Arraya) \text{Array}a)Array
10. Dijkstra's algorithm solves:
Answer: d)Single Source Shortest Pathd) \text{Single Source Shortest
Path}d)Single Source Shortest Path

Group B: Short Questions

1. What is Big-Oh (O) notation?


Answer: It provides an upper bound on the running time of an algorithm, representing
the worst-case scenario.
2. Define Dynamic Programming.
Answer: A technique for solving problems by breaking them down into overlapping sub-
problems and solving each sub-problem only once.
3. What is a Spanning Tree?
Answer: A subgraph of a graph that includes all the vertices with the minimum possible
number of edges, forming no cycles.
4. Explain space complexity.
Answer: Space complexity measures the amount of memory an algorithm uses
concerning the size of the input.

Group C: Long Questions

1. Explain the Divide and Conquer algorithm with an example.


Answer: Divide and Conquer splits a problem into sub-problems, solves them
recursively, and combines their results.
Example: Merge Sort divides the array into halves, sorts each half recursively, and
merges the sorted halves.
2. Write and explain the Bubble Sort algorithm.
Answer: Bubble Sort repeatedly steps through the list, compares adjacent elements, and
swaps them if they are in the wrong order.

Algorithm:

o Compare each pair of adjacent elements.


o Swap if necessary.
o Repeat until no swaps are needed.
3. Use Kruskal’s algorithm to find a Minimum Spanning Tree (MST).
Answer: Kruskal’s algorithm selects edges in increasing weight order, adding them to the
MST unless it forms a cycle.

Group A: Multiple Choice Questions (Extended)

11. What is the running time complexity of Heap Sort?


Answer: O(nlog⁡n)O(n \log n)O(nlogn)
12. Floyd-Warshall Algorithm time complexity:
Answer: b)O(V3)b) O(V^3)b)O(V3)
13. LIFO scheme is used in:
Answer: a)Stacka) \text{Stack}a)Stack
14. Time complexity of worst-case Linear Search:
Answer: O(n)O(n)O(n)
15. Which sorting algorithm is stable?
Answer: a)Merge Sorta) \text{Merge Sort}a)Merge Sort
16. What does "collision" mean in hashing?
Answer: c)When multiple elements map to the same bucket in a hash table.c) \text{When
multiple elements map to the same bucket in a hash
table.}c)When multiple elements map to the same bucket in a hash table.
17. What is the balance factor of an AVL tree?
Answer: Difference in heights of the left and right subtrees, which should not exceed 1.
18. In Binary Search Tree (BST), what is in-order traversal?
Answer: Traversing the left subtree, visiting the root, and then traversing the right
subtree.
19. Time complexity of Quick Sort in the worst case:
Answer: O(n2)O(n^2)O(n2)
20. What is Direct Addressing?
Answer: A technique where a value directly maps to its memory location.

Group B: Short Questions (Extended)

1. Difference between Path and Cycle in Graphs:


o Path: A sequence of edges where no vertex is repeated.
o Cycle: A path that starts and ends at the same vertex without repeating any other
vertex.
2. Explain Prim’s Algorithm:
Answer: Prim’s algorithm builds the Minimum Spanning Tree (MST) by starting from an
arbitrary vertex and adding the smallest edge that connects a new vertex.
3. What is the significance of Sorting Stability?
Answer: A stable sorting algorithm maintains the relative order of records with equal
keys.
4. What is Greedy Method?
Answer: An algorithmic approach that makes locally optimal choices at each step,
aiming to find the global optimum.
5. Why is space complexity important?
Answer: It helps in understanding the memory usage of an algorithm and ensures it can
run efficiently within available system resources.
6. What is Omega Notation (Ω\OmegaΩ)?
Answer: It provides a lower bound on the running time of an algorithm, representing the
best-case scenario.

Group C: Long Questions (Extended)

1. Explain Rabin-Karp Algorithm for String Matching:


Answer:
o Uses hashing to find patterns in a text efficiently.
o Compares the hash of the pattern with substrings of the text.
o If hashes match, confirms by direct comparison.
Complexity: Average O(n+m)O(n + m)O(n+m), Worst O(nm)O(nm)O(nm).
2. Write and Explain Recursive Binary Search Algorithm:
Answer:
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)

Explanation:

o Recursively divides the array into two halves.


o Reduces the problem size at each step, achieving O(log⁡n)O(\log n)O(logn)
complexity.
3. Explain Bellman-Ford Algorithm with an Example:
Answer:
o Solves the single-source shortest path problem for graphs with negative weights.
o Iterates V−1V-1V−1 times (where VVV is the number of vertices), relaxing all
edges in each iteration.
o Detects negative weight cycles.
Complexity: O(VE)O(VE)O(VE).
4. Explain Divide and Conquer with Merge Sort:
Answer:
o Divide: Split the array into two halves.
o Conquer: Sort each half recursively.
o Combine: Merge the sorted halves.
Complexity: O(nlog⁡n)O(n \log n)O(nlogn).
5. Write Kruskal’s Algorithm for Minimum Spanning Tree:
Steps:
o Sort edges by weight.
o Use a Union-Find/Disjoint-Set data structure to avoid cycles.
o Add edges to the MST until all vertices are connected.
Complexity: O(Elog⁡E)O(E \log E)O(ElogE).

Group A: Multiple Choice Questions (Further Extended)

21. What is the time complexity of a randomized QuickSort in the average case?
Answer: O(nlog⁡n)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(log⁡n)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(log⁡n)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.

Group B: Short Questions (Further Extended)

1. Define Collision in Hashing.


Answer: A collision occurs when two different keys hash to the same index in a hash
table.
2. Explain the advantages of Linked List representation over Arrays in Binary Trees.
Answer:
o Dynamic size adjustment.
o No memory wastage as only required nodes are created.
o Easier insertion and deletion compared to arrays.
3. What is Linear Time Sorting?
Answer: Sorting algorithms like Counting Sort, Radix Sort, or Bucket Sort that have a
time complexity of O(n)O(n)O(n) under certain conditions.
4. What is Space Complexity?
Answer: The amount of memory an algorithm requires relative to the input size.
5. What is a Stable Sorting Algorithm?
Answer: A sorting algorithm is stable if it preserves the relative order of records with
equal keys.
6. Explain Dijkstra's Algorithm's Key Features.
Answer:
o Finds the shortest path from a single source to all vertices.
o Works for graphs with non-negative edge weights.
o Uses a priority queue to pick the smallest distance vertex at each step.
Group C: Long Questions (Further Extended)

1. Write and Explain the Algorithm for Selection Sort:


Steps:
o Find the smallest element in the array and swap it with the first element.
o Repeat for the rest of the array.
Complexity:
o Best, Worst, Average Case: O(n2)O(n^2)O(n2).
2. Explain Dynamic Programming with an Example (e.g., Fibonacci Numbers):
Answer:
o Uses overlapping subproblems and memoization.
o Example: Fibonacci numbers.
Recursive Formula: F(n)=F(n−1)+F(n−2)F(n) = F(n-1) + F(n-
2)F(n)=F(n−1)+F(n−2).
Complexity: O(n)O(n)O(n).
3. Explain Merge Sort Algorithm in Detail:
Answer:
o Divide: Split the array into two halves.
o Conquer: Recursively sort the halves.
o Combine: Merge sorted halves.
Complexity:
o Time: O(nlog⁡n)O(n \log n)O(nlogn)
o Space: O(n)O(n)O(n)
4. Write the Bellman-Ford Algorithm for Shortest Path:
Steps:
o Initialize distances from the source to all vertices as infinite, except the source
itself.
o Relax all edges V−1V-1V−1 times.
o Check for negative weight cycles.
Complexity:
o Time: O(V⋅E)O(V \cdot E)O(V⋅E)
o Space: O(V)O(V)O(V)
5. Explain Kruskal’s Algorithm in Detail:
Steps:
o Sort edges in ascending order of weight.
o Add edges to MST if they don’t form a cycle.
o Use Union-Find to check for cycles.
Complexity:
o Time: O(Elog⁡E)O(E \log E)O(ElogE)

Extra Key Concepts for 2024


1. Time Complexities to Remember:
o Bubble Sort: O(n2)O(n^2)O(n2)
o Merge Sort: O(nlog⁡n)O(n \log n)O(nlogn)
o Heap Sort: O(nlog⁡n)O(n \log n)O(nlogn)
o Quick Sort (Worst): O(n2)O(n^2)O(n2), (Average): O(nlog⁡n)O(n \log
n)O(nlogn)
2. Graph Terminology:
o Path: A sequence of edges connecting vertices.
o Cycle: A path that starts and ends at the same vertex.
o Directed Acyclic Graph (DAG): No cycles, all edges directed.
3. Sorting Algorithms & Stability:
o Stable: Merge Sort, Bubble Sort, Insertion Sort.
o Unstable: Quick Sort, Heap Sort.
4. Important Hashing Techniques:
o Chaining: Store multiple elements in a single index via a linked list.
o Open Addressing: Resolve collisions by probing.
5. Tree Properties:
o Binary Tree: At most two children per node.
o Binary Search Tree (BST): Left child < parent < right child.
o AVL Tree: Self-balancing BST.

Group A: Top Multiple-Choice Questions

1. Which sorting algorithm is the fastest on average for large datasets?


Answer: b)QuickSortb) Quick Sortb)QuickSort
2. What is the time complexity of Kruskal’s Algorithm?
Answer: b)O(Elog⁡E)b) O(E \log E)b)O(ElogE)
3. What is the worst-case time complexity of Merge Sort?
Answer: a)O(nlog⁡n)a) O(n \log n)a)O(nlogn)
4. A circuit that does not repeat vertices is called:
Answer: b)APathb) A Pathb)APath
5. What is the time complexity of a binary search?
Answer: b)O(log⁡n)b) O(\log n)b)O(logn)
6. What is the process of resolving collisions in Hashing by using linked lists called?
Answer: a)Chaininga) Chaininga)Chaining
7. Which traversal is used in Depth-First Search (DFS)?
Answer: a)Pre−orderTraversala) Pre-order Traversala)Pre−orderTraversal
8. Which algorithm is used to find the shortest path in a weighted graph with no
negative weights?
Answer: b)Dijkstra’sAlgorithmb) Dijkstra’s Algorithmb)Dijkstra’sAlgorithm
9. In an AVL tree, the balance factor must lie between:
Answer: −1-1−1 and 111
10. What is the significance of Big-O notation?
Answer: It provides the upper bound on the running time of an algorithm.
11. Which of the following sorting algorithms is stable?
Answer: a)MergeSorta) Merge Sorta)MergeSort
12. What does a hash table provide in the best-case scenario?
Answer: c)O(1)c) O(1)c)O(1) search efficiency.
13. What is the worst-case time complexity of Quick Sort?
Answer: c)O(n2)c) O(n^2)c)O(n2)
14. What is the main advantage of a linked list over an array in representing a binary
tree?
Answer: Dynamic memory allocation and no need for a predefined size.
15. What is a Directed Acyclic Graph (DAG)?
Answer: A directed graph with no cycles.

Group B: Most Important Short Questions

1. Explain the difference between Path and Cycle in Graphs.


Answer:
o Path: A sequence of edges where no vertex is repeated.
o Cycle: A path that starts and ends at the same vertex without repeating any other
vertex.
2. Define Dynamic Programming.
Answer: A technique for solving problems by breaking them into overlapping
subproblems and solving each subproblem only once, often using memoization.
3. What is Collision in Hashing?
Answer: A situation where two or more keys hash to the same index in a hash table.
4. What is the balance factor in AVL Trees?
Answer: The difference in height between the left and right subtrees of a node, which
must lie between -1 and 1.
5. What is a Stable Sorting Algorithm?
Answer: An algorithm that preserves the relative order of records with equal keys.
6. Why is Binary Search efficient?
Answer: It divides the search space in half with each step, achieving O(log⁡n)O(\log
n)O(logn) time complexity.
7. What is Big Theta (Θ\ThetaΘ) Notation?
Answer: It provides a tight bound on the running time, representing both the upper and
lower limits of an algorithm's complexity.
8. Explain the significance of Prim’s Algorithm.
Answer: Prim’s Algorithm builds a Minimum Spanning Tree by starting with a single
vertex and adding the smallest edge connecting a new vertex.
9. What is Space Complexity?
Answer: The amount of memory an algorithm uses relative to the size of the input.
10. What is Hashing?
Answer: A technique to map data to specific locations in memory using a hash function
for efficient data retrieval.
Group C: Long Questions

1. Explain Merge Sort with an example.


Answer:
o Divide: Split the array into two halves.
o Conquer: Recursively sort the halves.
o Combine: Merge sorted halves into a single sorted array.
Complexity:
o Time: O(nlog⁡n)O(n \log n)O(nlogn)
o Space: O(n)O(n)O(n)
2. Write and Explain Recursive Binary Search Algorithm.
Answer:

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)

Complexity: O(log⁡n)O(\log n)O(logn)

3. Explain Kruskal’s Algorithm with an example.


Answer:
o Sort edges by weight.
o Use Union-Find to avoid cycles.
o Add edges to the MST until all vertices are connected.
Complexity: O(Elog⁡E)O(E \log E)O(ElogE)
4. Write the Bellman-Ford Algorithm for Single Source Shortest Path.
Answer:
o Initialize distances to infinity, except the source vertex.
o Relax all edges V−1V-1V−1 times.
o Detect negative weight cycles.
Complexity: O(V⋅E)O(V \cdot E)O(V⋅E)
5. Describe Divide and Conquer Strategy with an Example.
Answer:
o Divide: Break the problem into subproblems.
o Conquer: Solve the subproblems recursively.
o Combine: Merge the solutions.
Example: Merge Sort.
6. Explain the Rabin-Karp String Matching Algorithm.
Answer:
o Uses a rolling hash function to find patterns.
o Compares the hash of the pattern with substrings in the text.
o If hash matches, directly compare the strings.
Complexity: Average O(n+m)O(n + m)O(n+m), Worst O(nm)O(nm)O(nm).
7. Discuss Dynamic Programming with an Example.
Answer:
Example: Fibonacci Numbers.
Recursive formula: F(n)=F(n−1)+F(n−2)F(n) = F(n-1) + F(n-2)F(n)=F(n−1)+F(n−2)
Complexity: O(n)O(n)O(n) with memoization.

Additional Critical Topics for 2024

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(nlog⁡n)O(n \log n)O(nlogn) average).
o Merge Sort (Stable, O(nlog⁡n)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(log⁡n)O(\log n)O(logn).
o Dijkstra's Algorithm: O(V2)O(V^2)O(V2) (matrix) or O(E+Vlog⁡V)O(E + V
\log V)O(E+VlogV) (heap).

You might also like