Compiled Quizzes with answer key in algo
Compiled Quizzes with answer key in algo
6. How does Selection Sort place elements into their correct positions?
A. By shifting elements instead of swapping them.
B. By directly swapping the smallest unsorted element with the first element of the unsorted
portion.
C. By recursively dividing the dataset into smaller portions.
D. By merging multiple sorted subsets.
9. How does Selection Sort organize the input array during sorting?
A. By dividing it into a sorted and unsorted portion.
B. By creating multiple subarrays.
C. By first sorting the largest elements and then the smallest.
D. By swapping elements randomly until sorted.
12. What are the correct intermediate steps of the following data set when it is being sorted
with the Selection sort? 15,20,10,18
13. How many passes (or "scans") will there be through a list being sorted using a selection
sort?
A.Array_size*2
B.Array_size+1
C.Array_size-1
Explanation
In a selection sort, each pass involves finding the minimum element from the unsorted part of the
list and swapping it with the first element of the unsorted part. After each pass, the sorted part of
the list increases by one element. Since there are a total of array_size elements in the list, it will
take array_size-1 passes to sort the entire list.
A.11
B.9
C.20
D.25
Explanation
Since there are 10 elements in the list, each pass/scan will go through one element. Therefore,
there will be a total of 10 passes/scans. However, the question is asking for the number of
passes/scans, not the number of elements. Therefore, the correct answer is 9, as the first
pass/scan is not counted.
a. b.
c. d.
16. What is the advantage of selection sort over other sorting techniques?
a) It requires no additional storage space
b) It is scalable
c) It works best for inputs which are already sorted
d) It is faster than any other sorting technique
B. Move the boundary between the sorted and unsorted portions one step forward.
C. Swap the smallest element with the first element of the unsorted portion.
a. B, C, A , D, E
b. E, A, C, B, D
c. E, A, B, C, D
d. A, E, C, B, D
3-4. This algorithm is not suitable for large data sets as its average and worst-case time
complexity are quite high.
A. small, best
B. medium-sized, worse
C. large, worst
D. large, worse
5-6. The time complexity of bubble sort is O(n ²) in the worst-case scenario and the space
complexity of the bubble sort is O(1).
A. O(n ²) and O(1).
B. O(1) and O(n ²)
C. o(n ²) and O(n ²)
D. O(n ²) and o(n ²)
7-8. Bubble sort only needs a constant amount of additional space during the sorting process.
A. changing, before
B. constant, after
C. constant, during
D. small, during
Test B: Modified True or False. If the statement is false, choose the letter of the correct
answer.
11. Linear Sort does not require any additional memory space. False, Linear - Bubble
A. True
B. False, Linear – Bubble
C. False, Linear – Merge
12. It is an unstable sorting algorithm, meaning that elements with the same key value maintain
their relative order in the sorted output. False, unstable - stable
A. True
B. False, unstable – constant
C. False, unstable – stable
13. Bubble sort has a time complexity of O (n ²) which makes it very fast for large data sets.
False, fast - slow
A. True
B. False, fast – slow
C. False, fast – accurate
14-15. Bubble sorting is comparison-based sorting complexity, which means that it requires a
comparison operator to determine the relative order of elements in the input data set. It can limit
the effectivity of the algorithm in certain cases. False, complexity – algorithm & effectivity –
efficiency
A. True
B. False, complexity – algorithm & effectivity – efficiency
C. False, complexity – efficient & effectivity – complexity
A. III – I – II
B. I – II – III
C. II – III – I
Insertion Sort Quiz
Reported by: Pagatpatan, Alvin & Prestado, Cydryc
Multiple Choice
1.) Insertion sort is a simple sorting algorithm that works by iteratively inserting each
element of an ________ into its correct position in a _______ of the list.
a.) unsorted list & sorted portion c.) sorted portion & unsorted list
b.) unsorted portion & sorted list d.) sorted list & unsorted portion
2.) We start with _____ element of the array as ____ element in the array is assumed to
be sorted.
3.) ______ second element with the first element and check if the second element is
smaller then ____ them.
4.) Move to the _____ element and compare it with the _____ two elements and put at its
correct position
7.) The ______ time complexity of Insertion Sort occurs when the input array is in reverse
sorted order.
8.) Therefore, the best-case time complexity is ______, where n is the number of elements
in the array.
9.) Therefore, the worst-case time complexity is _____, where n is the number of elements
in the array.
11.) Although the exact number of comparisons and swaps may vary depending on the
_____, the average-case time complexity remains quadratic.
12.) One of the ______ of Insertion Sort was simple and easy to implement.
13.) One of the advantages of Insertion Sort was _____ sorting algorithm.
15.) One of the ________ of Insertion Sort was it does not perform well than other,
more advanced sorting algorithms.
16.) When the list is Small or Nearly Sorted on Insertion Sort, For an array of size 5
such as [2,1,4,3,5], What should we do first?
17.) When Simplicity and Stability are Important, If you’re sorting a list of tuples where
each tuple represent a name and a score, and you want to sort primarily by score
while keeping names in their original order when scores are equal, what should we
do on this example? [(John, 3), (Jane, 2), (Doe, 3)].
a.) [(John, 3),(John, 3)] would not maintain c.) [(John, 3),(John, 2)] maintain the order
b.) [(John, 3),(John, 3)] maintain the order d.) [(John, 3),(John, 2)] would not maintain
18.) When the Insertion sort used as a subroutine in Bucket Sort, the array is first
divide into several subarrays (buckets). These subarrays (buckets) are
typically sorted individually. Insertion Sort is often used to sort each bucket because:
20.) When the Insertion sort was used on Hybrid Sorting Algorithms (E.G., INTROSORT,
TIMSORT), When sorting large datasets recursively, some Hybrid
Sorting Algorithms (such as IntroSort or TimSort) switch to Insertion Sort
when the subarrays reach a certain threshold size. This is because:
ANSWER KEY:
MULTIPLE CHOICE:
1.) a
2.) a
3.) c
4.) b
5.) a
6.) a
7.) c
8.) a
9.) c
10.) c
11.) d
12.) b
13.) b
14.) a
15.) b
16.) a
17.) b
18.) d
19. )c
20.) d
WMerge Sort Questioner with Answer:
Enumeration:
Identification:
11. Merge sort uses recursion, which can add extra overhead, particularly for very large arrays.
14. Merge sort does not require random access to the data.
15. If two elements have the same value, they will retain their original relative order in the sorted arrays.
1-5.
Stability
Consistent Performance
Parallelizable
6-10.
Space Complexity
Not In-Place
Recursion Overhead
Complex Implementation
15. Stability
16-20.
Quicksort Quiz - Group 5
A. They are placed to the right of the pivot B. They are placed to the left of the pivot
C. They are sorted into a new array D. They are swapped with larger elements
A. Combines all sorted elements B. Rearranges the array around the pivot
A. When there are two elements left B. When all elements are sorted
C. When there is only one element in a sub-array D. When the pivot is at the start of the array
8. What kind of time complexity can QuickSort have in the best case?
9. Which pivot choice can cause QuickSort to have a worst-case time complexity of O(n²)?
11. Which QuickSort partitioning method is fastest when partitioning from both ends of an array?
12. What happens to elements greater than the pivot after partitioning?
A. They are placed to the left of the pivot B. They are placed to the right of the pivot
C. They are moved to the start of the array D. They remain unsorted
13. It works faster with minimal memory usage in which scenario is QuickSort’s worst-case time
complexity likely to occur?
A. When the pivot is chosen randomly B. When the array is already sorted
14. Which pivot selection method is often preferred to avoid QuickSort’s worst-case time
complexity?
15. What type of time complexity does QuickSort typically achieve on average?
16. Which partition method creates a copy of the array and uses O(n) extra space?
17. It depends on recursion depth Which type of partitioning in QuickSort does not rely on extra
arrays?
Answer Key:
1. A 11. C
2. B 12. B
3. B 13. B
4. B 14. C
5. B 15. D
6. B 16. A
7. C 17. B
8. C 18. C
9. C 19. B
10. B 20. C
Prepared by:
Guliban, Lindsay Marie F.
Gutierrez, Zyan S.
Ubalde, Jansen M.
Heap Sort Quiz
Reported by : Franco, Gamueda, & Sioc.
6. How does Heap Sort handle the largest element in the heap?
A. Moves it to the root of the heap.
B. Swaps it with the last element of the heap.
C. Deletes it from the heap.
D. Leaves it in its current position.
10. What happens after the root element of the heap is swapped with the last element?
A. The heap is sorted.
B. The heap is heapified, excluding the swapped element.
C. The heap size increases.
D. The heap becomes a Min Heap.
11. Sort the array [7, 2, 9, 4, 1] using Heap Sort. What is the sorted array?
A. [7, 9, 4, 2, 1]
B. [9, 7, 4, 2, 1]
C. [1, 2, 4, 7, 9]
D. [2, 4, 7, 9, 1]
16. Heap sort is ____ as the constants are higher compare to merge sort
A. Simplicity
B. Costly
C. Unstable
D. Inefficient
A. Simplicity
B. Unstable
C. Stability
D. Limbics
18. Heap sort is ______because of the high constants in the time complexity
A. Simplicity
B. Time Complexity
C. Inefficient
D. Efficiency
19. It is simpler to understand than other equally efficient sorting algorithms because it does
not use advanced computer science concepts such as recursion.
A. Simplicity
B. Limbics
C. Bouquet
D. Efficiency
A. Costly
B. Inefficient
C. Limbics
D. Unstable
Cycle Sort Quiz – Group 7
Submitted by: Puducay, Yron Pedrasa & Rebayla, Steven O.
1. Who developed the Cycle Sort algorithm?
A) W. D. Jones
B) John von Neumann
C) Donald Knuth
D) Alan Turing
Answer: A) W. D. Jones
A) 1956
B) 1963
C) 1971
D) 1980
Answer: B) 1963
A) O(n)
B) O(1)
C) O(n^2)
D) O(log n)
Answer: B) O(1)
A) MergeSort
B) QuickSort
C) Bubble Sort
D) Selection Sort
Answer: B) QuickSort
9. Cycle Sort works best with arrays that have a: A) Large range of values
B) Small range of values
C) Random order
D) Many duplicates
A) O(n log n)
B) O(n)
C) O(n^2)
D) O(n^3)
Answer: C) O(n^2)
12. After placing an element in its correct position, what does Cycle Sort do next?
A) Recursive
B) Iterative
C) Divide-and-conquer
D) Randomized
Answer: B) Iterative
A) O(n log n)
B) O(n)
C) O(n^2)
D) O(1)
Answer: C) O(n^2)
18. Which type of arrays does Cycle Sort perform best on?
A) Arrays with a small range of values
B) Arrays with large values
C) Arrays that are already sorted
D) Arrays with many duplicates
20. How does Cycle Sort find the correct position for each element?
PRANSES 1
LINEAR SEARCH QUIZ
a) Only sorted lists.
b) Only unsorted lists.
c) Both sorted and unsorted lists.
d) Only lists with numbers.
Answer: c) Both sorted and unsorted lists.
7. If the target is at the last position in the list, what is the time complexity of Linear Search?
a) O(1)
b) O(n)
c) O(log n)
d) O(n²)
Answer: b) O(n)
9. What is the time complexity of Linear Search when the target is somewhere in the middle?
a) O(1)
b) O(n)
PRANSES 2
LINEAR SEARCH QUIZ
c) O(log n)
d) O(n²)
Answer: b) O(n)
13. In the worst case, if the target is not in the list, how many elements does Linear Search
check?
a) 1
b) n
c) log n
d) n/2
PRANSES 3
LINEAR SEARCH QUIZ
Answer: b) n
15. Which time complexity is better for large datasets: Linear Search or Binary Search?
a) Linear Search
b) Binary Search
c) Both are equally efficient
d) Neither is efficient
Answer: b) Binary Search
PRANSES 4
LINEAR SEARCH QUIZ
18. What happens when Linear Search reaches the end of the list without finding the target?
a) It starts the search over again.
b) It returns the target index.
c) It returns -1.
d) It throws an exception.
Answer: c) It returns -1.
PRANSES 5
Binary Search - Quiz | Nicandro & Nasiba
---
---
---
4. What happens if the target is smaller than the middle element in Binary Search?
A. The search narrows to the left half.
B. The search narrows to the right half.
C. The search is complete.
D. The algorithm terminates.
Answer: A
---
---
---
---
8. Why is Binary Search faster than Linear Search for large datasets?
A. Binary Search divides the search space in half at each step.
B. Binary Search compares all elements sequentially.
C. Binary Search is recursive.
D. Binary Search uses additional space.
Answer: A
---
---
10. What must be true about the array for Binary Search to work?
A. It must be sorted.
B. It must be unsorted.
C. It must have unique elements.
D. It must contain only integers.
Answer: A
---
11. In Binary Search, if the middle element equals the target, what happens?
A. The algorithm narrows the search space.
B. The search is successful.
C. The algorithm continues searching.
D. The search starts from the end.
Answer: B
---
12. What does the space complexity of Binary Search depend on?
A. The number of comparisons.
B. The size of the array.
C. Whether it’s iterative or recursive.
D. The target value.
Answer: C
---
---
---
15. How does Binary Search compare to Linear Search for small datasets?
A. Binary is always better.
B. Linear can be simpler and faster.
C. Binary is unsuitable.
D. Both perform equally.
Answer: B
---
---
---
---
---
20. How does Binary Search perform in dynamic datasets?
A. Best choice.
B. Performs equally as Linear Search.
C. Inefficient due to frequent sorting requirements.
D. Cannot be implemented.
Answer: C
Fibonacci Search
Group 10
Members:
a) O(n) b) O(log n)
a) Binary Search
b) Linear Search
c) Jump Search
d) Hashing
5. In Fibonacci Search, which mathematical sequence is used to determine the partition points?
a) Prime numbers
b) Lucas sequence
c) Fibonacci sequence
d) Harmonic series
b) Find the smallest Fibonacci number greater than or equal to the array size
7. Which of the following is true about Fibonacci Search compared to Binary Search?
a) Faster runtime
d) Easier to parallelize
10. In Fibonacci Search, how do you adjust the search window after a comparison?
b) Shift by the Fibonacci number two places before the current one
a) O(1)
b) O(n)
c) O(log n)
d) O(n²)
a) Static arrays
b) Dynamic arrays
c) Linked lists
d) Graphs
14. Which of the following scenarios would NOT benefit from Fibonacci Search?
15. What happens if the element being searched is not found in the array?
a) 2, 4, 6, 8, 10
b) 1, 3, 6, 10, 15
c) 1, 1, 2, 3, 5, 8, 13...
d) 1, 2, 4, 8, 16
a) F(n)
b) F(n-1)
c) F(n+1)
d) F(n/2)
a) Dynamic programming
b) Greedy algorithm
c) Brute force
d) Graph traversal
a) It is too complex
a) Sorting numbers
3. What data structure is commonly used in Dijkstra's algorithm to find the next
closest vertex?
a) Stack
b) Queue
d) Linked List
4. What determines the order in which vertices are processed in Dijkstra’s algorithm?
a) The vertex with the smallest distance from the source is processed first.
c) The vertex with the largest distance from the source is processed first.
5. In Dijkstra's algorithm, what is initialized to infinity (\( \infty \)) at the start?
b) Zero-weight edges
d) Cycles
Answer: a) It does not work with graphs containing negative weight edges.
c) It skips vertices
b) Sorting algorithms
13. How does Dijkstra’s algorithm choose the next node to process?
a) Randomly
d) By alphabetical order
14. What happens if a graph has disconnected components when using Dijkstra’s
algorithm?
c) It outputs an error
d) It stops immediately
15. What happens when Dijkstra’s algorithm encounters a node with a smaller path
than previously found?
a) It updates the node’s distance
b) It stops processing
c) It deletes the node from the graph
d) It ignores the node
Answer: a) It updates the node’s distance
16. What is an optimal data structure for Dijkstra’s algorithm when using a priority
queue?
a) Array
b) Binary heap
c) Stack
d) Queue
Answer: b) Binary heap
a) Edsger W. Dijkstra
b) Arthur N. Dijkstra
c) Dijkstra Armstrong
d) Adolf Dijkstra
a) 1965
b) 1956
c) 1966
d) 1966
Answer: b) 1956
19. Dijkstra’s algorithm is a computer science algorithm that finds the shortest path
between ______ in a weighted graph.
a) lines
b) curves
c) nodes
d) circles
Answer: c) nodes
a) Google Maps
b) Canva
c) Telegram
d) Tiktok
4. In Bellman-Ford, how many iterations are required to find the shortest path?
A. Infinity
B. 1
C. Zero
D. One
8. What is the initial distance set for all nodes except the starting node?
A. Zero
B. 1
C. Infinity
D. One
A. It ignores them
B. It considers them in every iteration
C. It converts them to positive weights
D. It removes them from the graph
a) A → V
b) Z → X
c) W → X
d) X → Z
a) 9
b) 6
c) 7
d) 8
19. What does the Bellman-Ford algorithm check for after completing |V| - 1
iterations?
a) Alan Turing and John von Neumann b) Robert Floyd and Stephen Warshall c) Donald Knuth
and Edsger Dijkstra d) Richard Bellman and Claude Shannon
a) Single-source shortest path b) All-pairs shortest path c) Minimum spanning tree d) Traveling
salesman
6. What is the primary advantage of the Floyd-Warshall algorithm over the Bellman-Ford
algorithm?
a) It ignores them b) It flags them and stops execution c) It uses them to find shorter paths d) It
converts them to positive cycles
a) When you need the shortest path from a single source to all other nodes b) When you need
the shortest path between all pairs of nodes c) When you have a graph with only positive
weights d) When the graph is sparse
11. How does the Floyd-Warshall algorithm improve its estimates of the shortest paths?
a) By iterating through each pair of vertices only once b) By considering each vertex as an
intermediate point c) By using a divide-and-conquer approach d) By randomly selecting paths
and refining them
a) It cannot handle graphs with negative weights b) It is inefficient for graphs with a large
number of vertices c) It only works for undirected graphs d) It cannot find the shortest path
between a specific pair of nodes
13. Which of the following is a correct initialization step for the Floyd-Warshall
algorithm?
a) Set the distance between all pairs of vertices to infinity b) Set the distance between a vertex
and itself to zero c) Set the distance between adjacent vertices to one d) Set the distance
between non-adjacent vertices to negative infinity
14. How does the Floyd-Warshall algorithm handle graphs with negative edge weights
but no negative cycles?
a) It fails to find the shortest paths b) It successfully computes the shortest paths c) It only works
for positive edge weights d) It needs additional preprocessing
a) Updating the adjacency list b) Checking for the existence of a negative cycle c) Updating the
shortest path estimate for each pair of vertices d) Adding new vertices to the graph
16. In terms of space complexity, what is the main requirement of the Floyd-Warshall
algorithm?
17. What is the role of the intermediate vertex in the Floyd-Warshall algorithm?
19. Which other algorithm can be combined with the Floyd-Warshall algorithm to handle
more complex scenarios?
20. How does the Floyd-Warshall algorithm detect negative cycles in a graph?
a) By examining the diagonal of the distance matrix for negative values b) By checking for
cycles of even length c) By using a separate cycle detection algorithm d) By counting the
number of edges in each cycle
ANSWER KEY
Here are the answers to the quiz along with their rationale:
Answer: b) 1962
Rationale: The algorithm was independently discovered in 1962 by Robert Floyd and Stephen
Warshall.
Answer: d) O(V^3)
Rationale: The algorithm involves three nested loops, each iterating over all vertices, resulting
in O(V^3) complexity.
9. Which data structure is primarily used to store intermediate results in the
Floyd-Warshall algorithm?
10. In which scenario would you prefer using the Floyd-Warshall algorithm
over Dijkstra's algorithm?
Answer: b) When you need the shortest path between all pairs of nodes
Rationale: Floyd-Warshall computes all-pairs shortest paths, while Dijkstra is used for
single-source shortest paths.
11. How does the Floyd-Warshall algorithm improve its estimates of the
shortest paths?
Answer: c) Updating the shortest path estimate for each pair of vertices
Rationale: At each iteration, the algorithm updates the distance matrix by considering
intermediate vertices.
Answer: c) O(V^2)
Rationale: The algorithm uses a distance matrix of size V x V.
Answer: a) By examining the diagonal of the distance matrix for negative values
Rationale: A negative value on the diagonal indicates a negative cycle involving that vertex.
A. Robert B. Dial
B. Edsger Dijkstra
C. Alan Turing
D. John von Neumann
Answer: A
A. Priority queue
B. Stack
C. Buckets
D. Binary heap
Answer: C
A. Node
B. Edge
C. Bucket
D. Edging
Answer: B
DIAL’S ALGORITHM QUIZ
6. What is a bucket in Dial's Algorithm used for?
A. Storing all graphs
B. Grouping vertices by their current distances
C. Representing the maximum range of edge weights
D. Storing processed dictionaries
Answer: B
7. In Dial's Algorithm, what is the initial distance of all vertices except the source?
A. Zero
B. One
C. Negative infinity
D. Infinity
Answer: D
8. What does the term "relaxation" mean in the context of shortest path algorithms?
A. O(n)
B. O(nW)
C. O(n2)
D. O(m)
Answer: B
DIAL’S ALGORITHM QUIZ
11. What is the time complexity of Dial's Algorithm?
A. O(n2)
B. O(n+m)
C. O(n log n)
D. O(m log n)
Answer: B
14. How does Dial's Algorithm handle large edge weights efficiently?
15. What does the "addEdge" function do in the Python implementation of Dial's
Algorithm?
17. What is the main difference between Dijkstra's Algorithm and Dial's Algorithm?
18. Which function removes and returns the first element from a list in Python?
A. .append()
B. .pop()
C. .remove()
D. .clear()
Answer: B
A. Sorting integers
B. Calculating shortest paths in road networks with small edge weights
C. Generating random numbers
D. Encrypting data
Answer: B
20. Why is Dial's Algorithm unsuitable for graphs with large edge weight ranges?
d = (1,1) = 2
d = (2,2) = 7
d = (3,7) = 10
d = (4,10) = 12