Algorithms Quiz - CBSE Class 12 Computer Science
Free practice quiz: Algorithms (CBSE Class 12 Computer Science). 10 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 10 questions freeSample questions
What is the time complexity of linear search?
- O(1)
- O(log n)
- O(n)
- O(n^2)
Show answer
Answer: C. O(n)
Linear search checks each element one by one, resulting in a time complexity of O(n).
Which sorting algorithm has a worst-case time complexity of O(n^2)?
- Merge Sort
- Quick Sort
- Heap Sort
- Bubble Sort
Show answer
Answer: D. Bubble Sort
Bubble Sort has a worst-case time complexity of O(n^2) when the input is reverse sorted.
Explain the difference between recursive and iterative algorithms.
- Recursive algorithms use loops, while iterative algorithms use function calls.
- Recursive algorithms use function calls, while iterative algorithms use loops.
- Both are the same.
- None of the above.
Show answer
Answer: B. Recursive algorithms use function calls, while iterative algorithms use loops.
Recursive algorithms solve a problem by breaking it down into smaller subproblems of the same type, while iterative algorithms use loops to repeat a block of code.
Describe Dijkstra's algorithm and its application.
- Finds the shortest path in an unweighted graph
- Finds the shortest path in a weighted graph with negative edges
- Finds the shortest path in a weighted graph with non-negative edges
- Finds the minimum spanning tree in a graph
Show answer
Answer: C. Finds the shortest path in a weighted graph with non-negative edges
Dijkstra's algorithm is used to find the shortest paths from a single source node to all other nodes in a graph with non-negative edge weights.
Explain Amortized Analysis and give an example.
- Analyzing the average case complexity
- Analyzing the worst-case complexity
- Analyzing the average time complexity over a sequence of operations
- Analyzing the best-case complexity
Show answer
Answer: C. Analyzing the average time complexity over a sequence of operations
Amortized analysis considers the average time complexity of a sequence of operations, even if some individual operations are expensive.