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

Compiled Quizzes with answer key in algo

The document contains quizzes on Selection Sort, Bubble Sort, and Insertion Sort, each with multiple-choice questions assessing understanding of sorting algorithms. Key concepts covered include time complexity, stability, and the mechanics of each sorting method. The quizzes aim to evaluate knowledge of sorting principles and their applications in computer science.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Compiled Quizzes with answer key in algo

The document contains quizzes on Selection Sort, Bubble Sort, and Insertion Sort, each with multiple-choice questions assessing understanding of sorting algorithms. Key concepts covered include time complexity, stability, and the mechanics of each sorting method. The quizzes aim to evaluate knowledge of sorting principles and their applications in computer science.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Selection Sort Quiz

Reported by: Mabalot, Katherine F. & Marcelo, Nicole A.

1. Why is Selection Sort considered good for small datasets?


A. It has a low time complexity for large datasets.
B. It uses minimal memory and is simple to implement.
C. It always produces a stable sort.
D. It performs better than all other sorting algorithms.

2. What determines the time complexity of Selection Sort?


A. The number of swaps performed.
B. The number of comparisons, which is independent of the input order.
C. The size of the largest element in the dataset.
D. The memory required to store the sorted data.

3. What type of data can Selection Sort handle?


A. Only numbers.
B. Only strings.
C. Any data that can be compared, such as numbers, strings, or custom objects.
D. Only pre-sorted data.

4. Why is Selection Sort not considered a stable sorting algorithm?


A. It modifies the relative order of elements with equal keys during sorting.
B. It always uses extra memory to store sorted data.
C. It only works with numerical data.
D. It requires input data to be sorted beforehand.

5. In which scenario is the worst-case performance of Selection Sort observed?


A. When the input is already sorted.
B. When the input is in reverse sorted order.
C. When the input contains duplicate elements.
D. When the input is a mix of sorted and unsorted data.

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.

7. Why is Selection Sort considered an in-place sorting algorithm?


A. It uses additional memory to store the sorted array.
B. It requires no extra memory apart from the input array.
C. It operates by creating new subarrays for sorting.
D. It uses external storage for intermediate results.
8. Is Selection Sort considered a stable sorting algorithm? Why or why not?
A. Yes, because it preserves the relative order of equal elements.
B. No, because it may change the relative order of equal elements.
C. Yes, because it only works with unique keys.
D. No, because it requires extra memory to handle duplicates.

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.

10. What is a key characteristic of Selection Sort regarding comparisons?


A. The number of comparisons depends on the input order.
B. The number of comparisons increases exponentially with the array size.
C. The number of comparisons is the same, regardless of input order.
D. The number of comparisons decreases for sorted data.

11. In a selection sort structure, there is/are?

A. Two separate for loops

B. Three for loops, all separate

C. Two for loops, one nested in the other

D. A for loop nested inside a while loop

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

A.10, 20,15,18 -- 10,15,20,18 -- 10,15,18,20

B.15,20,10,18 -- 15,10,20,18 -- 10,15,20,18 -- 10,15,18,20

C.15,18,10,20 -- 10,18,15,20 -- 10,15,18,20 -- 10,15,18,20

D.15,10,20,18 -- 15,10,18,20 -- 10,15,18,20

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

D.None of the above

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.

14. How many passes/scans will go through a list of 10 elements?

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.

15. Select the appropriate code that performs selection sort.

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

17. What is the disadvantage of selection sort?


a) It requires auxiliary memory
b) As the input size increases, the performance of selection sort decreases.
c) It can be used for small keys
d) It takes linear time to sort the elements

18. What is the best case complexity of selection sort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

19. Which of the following is the correct steps in selection sort?

A. Start with the first element of the array.

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.

D. Repeat until the entire array is sorted.

E. Find the smallest element in the unsorted portion of the array.

a. B, C, A , D, E

b. E, A, C, B, D

c. E, A, B, C, D

d. A, E, C, B, D

20. What is the worst case complexity of selection sort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Quiz: Bubble Sort
Submitted by: Unson, Carl Joshua
Jimenez, Ashley
Rafael, Ibe

Test A: Fill in the blanks


1-2. Bubble sort is the simplest sorting algorithm that works by repeatedly swapping the
adjacent element if they are in wrong order.
A. repeatedly, adjacent
B. adjacent, repeatedly
C. consecutively, congruent
D. congruent, consecutively

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

9-10. Bubble Sort is easy to understand and implement.


A. understand, implement
B. do, implement
C. do, complement
D. understand, compliment

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

Test C. Bubble Sort Sequence

16. Which of the following is the third step in bubble sorting?


A. Evaluate pairs of adjacent elements, comparing each with the next. When a pair is out
of order, swap them.
B. After completing a pass, the largest unsorted element will have moved to its correct
position. Reduce the range of elements that need to be checked in the next iteration.
C. Continue checking and swapping adjacent elements until no further swaps are needed,
indicating that the list is fully sorted.

17. Which of the following is the first step in bubble sorting?


A. Evaluate pairs of adjacent elements, comparing each with the next. When a pair is out
of order, swap them.
B. After completing a pass, the largest unsorted element will have moved to its correct
position. Reduce the range of elements that need to be checked in the next iteration.
C. Continue checking and swapping adjacent elements until no further swaps are needed,
indicating that the list is fully sorted.

18. Which of the following is the second step in bubble sorting?


A. Evaluate pairs of adjacent elements, comparing each with the next. When a pair is out
of order, swap them.
B. After completing a pass, the largest unsorted element will have moved to its correct
position. Reduce the range of elements that need to be checked in the next iteration.
C. Continue checking and swapping adjacent elements until no further swaps are needed,
indicating that the list is fully sorted.
19-20. Which is the correct sequence in Bubble Sorting?
I. Evaluate pairs of adjacent elements, comparing each with the next. When a pair is out
of order, swap them.
II. After completing a pass, the largest unsorted element will have moved to its correct
position. Reduce the range of elements that need to be checked in the next iteration.
III. Continue checking and swapping adjacent elements until no further swaps are needed,
indicating that the list is fully sorted.

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.

a.) second & first c.) third & fourth


b.) first & second d.) fourth & third

3.) ______ second element with the first element and check if the second element is
smaller then ____ them.

a.) swap & Compare c.) Compare & swap


b.) swapping & Comparing d.) Comparing & swapping

4.) Move to the _____ element and compare it with the _____ two elements and put at its
correct position

. a.) third & second c.) first & third


b.) third & first d.) second & third

5.) ______ until the entire _____ is sorted.

a.) Repeat & array c.) Repeating & array


b.) array & Repeat d.) array & Repeating
6.) The ______ time complexity of Insertion Sort occurs when the input array is already
sorted.

a.) best-case c.) average-case


b.) worst-case d.) case-best

7.) The ______ time complexity of Insertion Sort occurs when the input array is in reverse
sorted order.

a.) average-case c.) worst-case


b.) best- case d.) case-worst

8.) Therefore, the best-case time complexity is ______, where n is the number of elements
in the array.

a.) O(N) c.) O(N))


b.) O(N2) d.) O(N2))

9.) Therefore, the worst-case time complexity is _____, where n is the number of elements
in the array.

a.) O(N)) c.) O(N2)


b.) O(N) d.) O(N2))

10.) The _______ time complexity of Insertion Sort is also O(N2).

a.) case-average c.) average-case


b.) best-case d.) worst-case

11.) Although the exact number of comparisons and swaps may vary depending on the
_____, the average-case time complexity remains quadratic.

a.) output c.) display


b.) result d.) input

12.) One of the ______ of Insertion Sort was simple and easy to implement.

a.) disadvantages c.) pros


b.) advantages d.) cons

13.) One of the advantages of Insertion Sort was _____ sorting algorithm.

a.) Unstable c.) Disabled


b.) Stable d.) Able
14.) One of the disadvantages of Insertion Sort was ______ or large lists.

a.) Inefficient c.) Sufficient


b.) Efficient d.) Insufficient

15.) One of the ________ of Insertion Sort was it does not perform well than other,
more advanced sorting algorithms.

a.) advantages c.) cons


b.) disadvantages d.) pros

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?

a.) Insert 1 before 2 c.) Insert 4 before 3


b.) 2 stay on its position d.) Insert 5 before 2

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:

a.) Buckets typically contain small numbers of elements.


b.) Insertion Sort works efficiently on small, partially sorted datasets.
c.) Using Insertion Sort minimizes overhead in sorting each bucket
before combining them back together.
d.) All of the Above
19.) On Insertion Sort that can be Useful when Array is Already Almost Sorted
(Few Inversions), When the list is nearly sorted (with only a few elements out of place),
It minimizes the number of operations, then what should we do for this
example? [1, 2, 3, 5, 4, 6] (only one element 4 needs to be moved).

a.) 2,3,5,4 c.) 3,5,4,6


b.) 1,2,3,4 d.) 2,1,5,4

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:

a.)Insertion Sort performs very efficiently on small subarrays (with size


around 10–20 elements).
b.) Switching to Insertion Sort avoids the overhead of recursion and helps make
the sorting process faster when dealing with small chunks of data.
c.) On timsort It breaks the array into small runs and each run is sorted
using Insertion Sort.
d.) All of the Above

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:

1-5. Give 5 Advantages of Merge Sort

6-10. Give 5 Disadvantages of Merge Sort

Identification:

11. Merge sort uses recursion, which can add extra overhead, particularly for very large arrays.

12. Merge sort does not operate in-place.

13. Merge sort requires additional memory for temporary 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.

16-20. Give the Structure Answer: 6 5 12 10 9 1


Answers:

1-5.

 Time Efficiency (0(n log n))

 Stability

 Consistent Performance

 Works Well with Linked Lists

 Parallelizable

6-10.

 Space Complexity

 Not In-Place

 Slower for Small Arrays

 Recursion Overhead

 Complex Implementation

11. Recursion Overhead

12. Not In-Place

13. Space Complexity

14. Works Well with Linked Lists

15. Stability

16-20.
Quicksort Quiz - Group 5

1. What sorting method does QuickSort use?

A. Divide and Conquer B. Dynamic Programming

C. Backtracking D. Breadth-First Search

2. What is the purpose of selecting a pivot in QuickSort?

A. To sort all elements B. To partition the array around a specific element

C. To merge sorted sub-arrays D. To combine sorted data

3. What is the first step in the QuickSort process?

A. Merging arrays B. Choosing a pivot C. Recursive calls D. Base case check

4. What happens to elements smaller than the pivot in QuickSort?

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

5. What is the main reason QuickSort is efficient on large datasets?

A. It requires no recursion B. It uses divide and conquer to break down problems

C. It only sorts the largest elements D. It does not need a pivot

6. What does the partition function do in QuickSort?

A. Combines all sorted elements B. Rearranges the array around the pivot

C. Finds the largest element D. Merges two sorted arrays

7. In QuickSort, what is the base case for recursion?

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?

A. O(n) B. O(n²) C. O(n log n) D. O(log n)

9. Which pivot choice can cause QuickSort to have a worst-case time complexity of O(n²)?

A. Random pivot B. Median element

C. Last element in a sorted array D. First element in an unsorted array


10. Which partitioning approach is the simplest in terms of tracking smaller elements?

A. Naive partition B. Lomuto partition

C. Hoare’s partition D. Randomized partition

11. Which QuickSort partitioning method is fastest when partitioning from both ends of an array?

A. Naive partition B. Lomuto partition

C. Hoare’s partition D. Last-element partition

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

C. When the pivot is the median D. When using a large dataset

14. Which pivot selection method is often preferred to avoid QuickSort’s worst-case time
complexity?

A. First element B. Last element C. Random element D. Sorted element

15. What type of time complexity does QuickSort typically achieve on average?

A. O(n²) B. O(log n) C. O(n) D. O(n log n)

16. Which partition method creates a copy of the array and uses O(n) extra space?

A. Naive partition B. Lomuto partition C. Hoare’s partition D. Tail recursion

17. It depends on recursion depth Which type of partitioning in QuickSort does not rely on extra
arrays?

A. Naive partition B. Lomuto partition C. Hoare’s partition D. Base-case partition

18. How is the pivot element positioned in each partitioned sub-array?

A. At the start B. At the end

C. In its correct position in the sorted array D. At the middle


19. Which of the following is an advantage of QuickSort?

A. It requires a lot of extra memory to sort the data

B. It is cache-friendly as it works on the same array without copying data

C. It can sort numbers, but not other types of data

D. It is slower than other algorithms for large data sets

20. Why is QuickSort important in theoretical computer science?

A. It helps analyze worst-case time complexity

B. It is used for real-time applications only

C. It contributes to understanding average-case complexity and developing new techniques

D. It has no significant impact on theoretical research

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.

1. What is Heap Sort?


A. A recursive sorting algorithm that uses merge operations.
B. A comparison-based sorting algorithm that uses a binary heap.
C. A sorting algorithm based on partitioning the dataset.
D. A string sorting algorithm.

2. What data structure does Heap Sort rely on?


A. Linked List
B. Binary Heap
C. Stack
D. Graph

3. Which heap property does a Max Heap satisfy?


A. Parent nodes are greater than or equal to their child nodes.
B. Parent nodes are less than or equal to their child nodes.
C. Parent nodes are equal to their child nodes.
D. Parent nodes are randomly ordered.

4. What is the time complexity of Heap Sort in all cases?


A. O(n²)
B. O(n log n)
C. O(log n)
D. O(1)

5. What does "heapify" do?


A. Converts an unsorted array into a sorted one.
B. Restores the heap property of a binary heap.
C. Merges two heaps into one.
D. Divides the heap into sorted and unsorted parts.

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.

7. What is the first step in Heap Sort?


A. Sort the array in ascending order.
B. Build a max heap from the array.
C. Swap all elements in the array.
D. Divide the array into two subarrays.
Heap Sort Quiz
Reported by : Franco, Gamueda, & Sioc.

8. Which type of sorting algorithm is Heap Sort considered?


A. Stable
B. Unstable
C. Recursive
D. External

9. Why is Heap Sort considered memory-efficient?


A. It requires no extra memory beyond the input array.
B. It uses a separate array for the sorted elements.
C. It compresses the dataset before sorting.
D. It stores elements in a linked list.

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]

12. Which step is NOT part of the Heap Sort process?


A. Build a max heap.
B. Swap the root with the last element.
C. Heapify the array.
D. Merge two heaps.

13. Why is Heap Sort considered inefficient compared to Merge Sort?


A. It has higher constants in its time complexity.
B. It uses more memory.
C. It is recursive.
D. It is stable.

14. What is the memory complexity of Heap Sort?


A. O(1)
B. O(n log n)
C. O(n)
D. O(n²)

15. How does Heap Sort handle unsorted data?


A. Converts it into a Min Heap.
B. Converts it into a Max Heap.
Heap Sort Quiz
Reported by : Franco, Gamueda, & Sioc.

C. Rearranges it in ascending order.


D. Deletes all elements except the largest one.

16. Heap sort is ____ as the constants are higher compare to merge sort

A. Simplicity

B. Costly

C. Unstable

D. Inefficient

17. Heap sort is ___. It might rearrange the relative order.

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

20. Which is NOT a Disadvantage of Heap Sort

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

2. When was Cycle Sort first published?

A) 1956
B) 1963
C) 1971
D) 1980

Answer: B) 1963

3. What type of sorting algorithm is Cycle Sort?

A) In-place and unstable


B) Out-of-place and stable
C) In-place and stable
D) Out-of-place and unstable

Answer: A) In-place and unstable

4. What is the main focus of Cycle Sort?

A) Minimizing the number of swaps


B) Minimizing the number of writes
C) Sorting quickly
D) Using extra memory

Answer: B) Minimizing the number of writes

5. What is the space complexity of Cycle Sort?

A) O(n)
B) O(1)
C) O(n^2)
D) O(log n)

Answer: B) O(1)

6. What is a disadvantage of Cycle Sort?

A) It requires extra memory


B) It has high time complexity
C) It is too simple
D) It is a stable algorithm

Answer: B) It has high time complexity

7. Which algorithm is better for large datasets than Cycle Sort?

A) MergeSort
B) QuickSort
C) Bubble Sort
D) Selection Sort

Answer: B) QuickSort

8. What makes Cycle Sort unique?

A) It minimizes the number of swaps


B) It uses extra memory
C) It is stable
D) It sorts randomly

Answer: A) It minimizes the number of swaps

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

Answer: B) Small range of values

10. What is the worst-case time complexity of Cycle Sort?

A) O(n log n)
B) O(n)
C) O(n^2)
D) O(n^3)

Answer: C) O(n^2)

11. In Cycle Sort, a cycle refers to:

A) A set of elements in their final sorted position


B) A group of elements in the same position in the unsorted array
C) A group of elements that need to be swapped
D) Elements that do not need to be moved

Answer: B) A group of elements in the same position in the unsorted array

12. After placing an element in its correct position, what does Cycle Sort do next?

A) Ends the process


B) Continues with the next element
C) Swaps the element with the next one
D) Moves to a new cycle

Answer: B) Continues with the next element

13. Cycle Sort is an in-place algorithm. What does this mean?

A) It needs extra memory to sort


B) It sorts elements without using extra memory
C) It sorts only small arrays
D) It requires a recursive approach

Answer: B) It sorts elements without using extra memory

14. What type of algorithm is Cycle Sort?

A) Recursive
B) Iterative
C) Divide-and-conquer
D) Randomized

Answer: B) Iterative

15. How does Cycle Sort minimize writes to memory?

A) By writing every time an element is compared


B) By only writing when an element is out of place
C) By sorting elements multiple times
D) By using extra memory for each element

Answer: B) By only writing when an element is out of place

16. Why is Cycle Sort rarely used on large datasets?

A) It requires extra memory


B) It has high time complexity
C) It is too simple
D) It is a stable sorting algorithm

Answer: B) It has high time complexity

17. What is the best-case time complexity of Cycle Sort?

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

Answer: A) Arrays with a small range of values

19. A key disadvantage of Cycle Sort is:

A) It requires large amounts of memory


B) It is inefficient for large datasets
C) It uses a lot of swaps
D) It is not stable

Answer: B) It is inefficient for large datasets

20. How does Cycle Sort find the correct position for each element?

A) By comparing the element with every other element


B) By guessing the correct position
C) By moving elements to their correct position in cycles
D) By sorting the array multiple times

Answer: C) By moving elements to their correct position in cycles


LINEAR SEARCH QUIZ

1. What is the main idea behind Linear Search?


a) It sorts the list before searching.
b) It checks each element one by one until the target is found.
c) It divides the list into smaller parts.
d) It uses binary search to find the target.
Answer: b) It checks each element one by one until the target is found.

2. What is the best case time complexity for Linear Search?


a) O(n)
b) O(log n)
c) O(1)
d) O(n²)
Answer: c) O(1)

3. What happens if Linear Search doesn’t find the target?


a) It returns the target index.
b) It stops searching.
c) It returns -1.
d) It gives an error.
Answer: c) It returns -1.

4. What is the worst-case time complexity of Linear Search?


a) O(1)
b) O(log n)
c) O(n)
d) O(n²)
Answer: c) O(n)

5. Linear Search works on:

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.

6. What is the first step in Linear Search?


a) Compare the element with the target.
b) Start at the first element of the list.
c) Return the target index.
d) Repeat until the target is found.
Answer: b) Start at the first element of the list.

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)

8. In which case is Linear Search most efficient?


a) When the list is sorted.
b) When the list is unsorted and small.
c) When the list has millions of elements.
d) When the target is always the last element.
Answer: b) When the list is unsorted and small.

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)

10. What is one advantage of Linear Search?


a) It requires additional memory.
b) It works only with sorted lists.
c) It is simple and easy to implement.
d) It is faster than binary search for large datasets.
Answer: c) It is simple and easy to implement.

11. What is a disadvantage of Linear Search?


a) It requires sorting before searching.
b) It works only on sorted lists.
c) It is inefficient for large datasets.
d) It uses additional memory.
Answer: c) It is inefficient for large datasets.

12. Which of the following best describes Linear Search?


a) A search method that divides the list into halves.
b) A search method that checks every element until a match is found.
c) A search method that uses recursion.
d) A search method that requires the list to be sorted.
Answer: b) A search method that checks every element until a match is found.

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

14. What happens if the target is found in Linear Search?


a) The algorithm stops and returns the target.
b) The algorithm checks the entire list again.
c) The index of the target is returned.
d) The algorithm throws an error.
Answer: c) The index of the target is returned.

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

16. What is the space complexity of Linear Search?


a) O(1)
b) O(n)
c) O(log n)
d) O(n²)
Answer: a) O(1)

17. Which of the following is a real-world example of Linear Search?


a) Searching for a name in a sorted phone book.
b) Finding a guest's name in an unsorted guest list.
c) Finding the median of a sorted list.
d) Searching for a file in a directory with thousands of files.
Answer: b) Finding a guest's name in an unsorted guest list.

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.

19. When is Linear Search less effective than Binary Search?


a) When the list is sorted.
b) When the list is small.
c) When the target is near the end.
d) When the target is at the beginning.
Answer: a) When the list is sorted.

20. What is the most time-consuming scenario for Linear Search?


a) The target is the first element.
b) The target is the middle element.
c) The target is the last element or not present.
d) The list is sorted.
Answer: c) The target is the last element or not present.

PRANSES 5
Binary Search - Quiz | Nicandro & Nasiba

1. What is Binary Search?


A. A search algorithm for unsorted arrays.
B. A search algorithm for sorted arrays by dividing the search interval in half.
C. A sorting algorithm.
D. An algorithm for searching linked lists.
Answer: B

---

2. Which type of dataset is Binary Search best suited for?


A. Unsorted datasets.
B. Dynamic datasets.
C. Sorted and static datasets.
D. Linked lists.
Answer: C

---

3. What is the first step in Binary Search?


A. Compare the first element with the target.
B. Start with the middle element of the array.
C. Sort the array.
D. Compare the last element with the target.
Answer: B

---

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

---

5. What is the time complexity of Binary Search in the best case?


A. O(n)
B. O(log n)
C. O(1)
D. O(n^2)
Answer: C

---

6. Which of the following is NOT a benefit of Binary Search?


A. Fast with fewer comparisons.
B. Works on unsorted datasets.
C. Predictable performance.
D. Low space complexity when iterative.
Answer: B

---

7. Which search is better for unsorted datasets?


A. Binary Search
B. Linear Search
C. Quick Sort
D. Hashing
Answer: B

---

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

---

9. What is the time complexity of Binary Search in the worst case?


A. O(1)
B. O(log n)
C. O(n)
D. O(n log n)
Answer: B

---

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

---

13. Which real-life scenario is similar to Binary Search?


A. Reading a book from start to end.
B. Finding a word in a dictionary.
C. Searching for a needle in a haystack.
D. Collecting coins in random order.
Answer: B

---

14. What is a major disadvantage of Binary Search?


A. It requires fewer comparisons.
B. It is predictable.
C. It only works on sorted datasets.
D. It works on arrays with random access.
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

---

16. What happens when Binary Search is implemented recursively?


A. It uses O(log n) space.
B. It uses O(1) space.
C. It uses O(n) space.
D. It doesn't use any additional space.
Answer: A

---

17. Which data structure is Binary Search unsuitable for?


A. Arrays
B. Stacks
C. Linked Lists
D. Trees
Answer: C

---

18. Which of the following is a con of Binary Search?


A. Low space complexity.
B. Setup overhead for sorting unsorted data.
C. Requires fewer comparisons.
D. Predictable performance.
Answer: B

---

19. What is the base case for terminating Binary Search?


A. When the target is larger than all elements.
B. When the target equals the middle element.
C. When the array is empty.
D. When the array is sorted.
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:

Sasi, Cudel, Celestial

1. What type of search algorithm is Fibonacci Search?

a) Linear search b) Interpolation search

c) Divide-and-conquer search d) Greedy search

2. Fibonacci Search is most efficient for which type of data?

a) Unsorted data b) Sorted data

c) Random data d) Small data sets only

3. What is the time complexity of Fibonacci Search in the worst case?

a) O(n) b) O(log n)

c) O(n log n) d) O(√n)

4. Fibonacci Search is most similar to which of the following algorithms?

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

6. What is the initial step in Fibonacci Search?

a) Calculate the middle element

b) Find the smallest Fibonacci number greater than or equal to the array size

c) Divide the array into equal halves

d) Use hashing to locate the element

7. Which of the following is true about Fibonacci Search compared to Binary Search?

a) Fibonacci Search does not require division operations

b) Fibonacci Search requires more comparisons

c) Binary Search is always faster

d) Fibonacci Search is easier to implement

8. Fibonacci Search is particularly useful for which type of systems?

a) Systems with expensive division operations

b) Systems with limited memory


c) Systems with floating-point calculations

d) Systems that require random access frequently

9. What is the main advantage of Fibonacci Search over Binary Search?

a) Faster runtime

b) Requires fewer computations for partitioning

c) Better performance for large data

d) Easier to parallelize

10. In Fibonacci Search, how do you adjust the search window after a comparison?

a) Double the search window

b) Shift by the Fibonacci number two places before the current one

c) Divide the array into three parts

d) Repeat the search from the beginning

11. What is the best case time complexity of Fibonacci Search?

a) O(1)

b) O(n)

c) O(log n)

d) O(n²)

12. When is Fibonacci Search less efficient than Binary Search?

a) For small datasets

b) When division operations are inexpensive

c) When data is unsorted

d) When searching in linked lists

13. Fibonacci Search works best with:

a) Static arrays

b) Dynamic arrays

c) Linked lists

d) Graphs

14. Which of the following scenarios would NOT benefit from Fibonacci Search?

a) Searching in large sorted arrays

b) Searching in unstructured, unsorted data

c) Systems with no division operations

d) Searching on hardware with limited resources

15. What happens if the element being searched is not found in the array?

a) Return the middle element

b) Return the first element

c) Return -1 or an indicator of failure

d) Keep reducing the window until one element remains


16. Which of the following represents the Fibonacci sequence?

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

17. What happens if the array size is not a Fibonacci number?

a) The search fails

b) Padding with dummy values is done

c) The algorithm divides the array into equal halves

d) It uses binary search instead.

18. Which Fibonacci number is typically used to split the array?

a) F(n)

b) F(n-1)

c) F(n+1)

d) F(n/2)

19. What type of algorithm design does Fibonacci Search follow?

a) Dynamic programming

b) Greedy algorithm

c) Brute force

d) Graph traversal

20. Why is Fibonacci Search rarely used in modern applications?

a) It is too complex

b) Binary search is slower

c) Modern hardware can handle division operations efficiently

d) It cannot handle large datasets


Quiz: Dijkstra’s Algorithm

1. What is Dijkstra's algorithm used for?

a) Sorting numbers

b) Finding the shortest path in a graph

c) Generating random numbers

d) Solving linear equations

Answer: b) Finding the shortest path in a graph

2. What type of graphs can Dijkstra's algorithm be applied to?

a) Only undirected graphs

b) Only weighted graphs with non-negative weights

c) Any graph with negative weights

d) Graphs with self-loops

Answer: b) Only weighted graphs with non-negative weights

3. What data structure is commonly used in Dijkstra's algorithm to find the next
closest vertex?

a) Stack

b) Queue

c) Priority Queue (or Min-Heap)

d) Linked List

Answer: c) Priority Queue (or Min-Heap)

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.

b) Vertices are processed in alphabetical order.

c) The vertex with the largest distance from the source is processed first.

d) Vertices are processed in a random order.


Answer: a) The vertex with the smallest distance from the source is processed first.

5. In Dijkstra's algorithm, what is initialized to infinity (\( \infty \)) at the start?

a) The distance of all nodes from the source

b) The weights of the edges

c) The adjacency list

d) The source node distance

Answer: a) The distance of all nodes from the source

6. What is the first step in Dijkstra’s algorithm?

a) Update all node distances to the source

b) Add all vertices to the priority queue

c) Initialize the source distance to 0

d) Traverse all edges in the graph

Answer: c) Initialize the source distance to 0

7. Dijkstra's algorithm will not work correctly if the graph contains:

a) Positive edge weights

b) Zero-weight edges

c) Negative edge weights

d) Cycles

Answer: c) Negative edge weights

8. Why does Dijkstra’s algorithm guarantee the shortest path?

a) It explores nodes in increasing order of their distance from the source.

b) It explores all possible paths in the graph.

c) It always uses a breadth-first search approach.

d) It revisits each node multiple times.


Answer: a) It explores nodes in increasing order of their distance from the source.

9. What happens to a vertex once it is "visited" in Dijkstra’s algorithm?

a) Its shortest path is finalized and will not change.

b) It is removed from the graph.

c) It is added back into the priority queue.

d) Its distance is reset to infinity.

Answer: a) Its shortest path is finalized and will not change.

10. What is the primary limitation of Dijkstra’s algorithm?

a) It does not work with graphs containing negative weight edges.

b) It is too slow for small graphs.

c) It cannot handle graphs with cycles.

d) It works only for unweighted graphs.

Answer: a) It does not work with graphs containing negative weight edges.

11. Why is Dijkstra’s algorithm slow for large graphs?

a) It cannot process many edges

b) It has high time complexity

c) It skips vertices

d) It uses random paths

Answer: b) It has high time complexity

12. What type of application commonly uses Dijkstra’s algorithm?

a) GPS and navigation systems

b) Sorting algorithms

c) Social media apps

d) Image recognition systems

Answer: a) GPS and navigation systems

13. How does Dijkstra’s algorithm choose the next node to process?
a) Randomly

b) By smallest distance from the source

c) By largest distance from the source

d) By alphabetical order

Answer: b) By smallest distance from the source

14. What happens if a graph has disconnected components when using Dijkstra’s
algorithm?

a) It finds a path anyway

b) It processes only connected components

c) It outputs an error

d) It stops immediately

Answer: b) It processes only connected components

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

17. Who developed the Dijkstra’s Algorithm

a) Edsger W. Dijkstra

b) Arthur N. Dijkstra

c) Dijkstra Armstrong

d) Adolf Dijkstra

Answer: a) Edsger W. Dijkstra


18. What year did the Dijkstra’s algorithm developed

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

20. What application uses the Dijkstra’s Algorithm

a) Google Maps

b) Canva

c) Telegram

d) Tiktok

Answer: a)Google Maps


Bellman-Ford Algorithm Quiz

1. What is the primary difference between the Bellman-Ford algorithm and


Dijkstra’s algorithm?

A. Bellman-Ford only works with positive edge weights


B. Bellman-Ford works with negative edge weights, while
Dijkstra’s does not
C. Dijkstra’s works with negative cycles, while Bellman-Ford
does not D. Bellman-Ford is faster than Dijkstra’s

2. What type of graphs cause both Bellman-Ford and Dijkstra’s to fail?

A. Graphs with positive weights


B. Graphs with cycles
C. Graphs with negative cycles
D. Graphs with self-loops

3. Why does Dijkstra’s fail with negative edge weights?

A. It doesn’t iterate enough times


B. It only considers outgoing edges
C. It uses a greedy approach
D. It doesn’t track negative weights

4. In Bellman-Ford, how many iterations are required to find the shortest path?

A. Number of vertices (V)


B. V – 1 iterations
C. Number of edges (E)
D. E – 1 iterations

5. What happens if there are more than V – 1 edges in a path?

A. The algorithm terminates early


B. A cycle is detected
C. The algorithm fails
D. The path weight becomes infinite

6. What is the purpose of updating along all edges in each iteration of


Bellman-Ford? A. To find cycles in the graph
B. To guarantee shortest paths
C. To remove negative weights
D. To reduce time complexity
7. What is the initial distance set for the starting node in Bellman-Ford?

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

9. What happens if no updates occur during an iteration?

A. The algorithm stops early


B. The algorithm restarts
C. The algorithm detects a cycle
D. The algorithm skips the next iteration

10.What is a “simple path” in the context of Bellman-Ford?

A. A path with no repeated vertices


B. A path with no negative weights
C. A path with minimal edges
D. A path with no outgoing edges

11.What is guaranteed after completing V – 1 iterations in Bellman-Ford?

A. Detection of negative cycles


B. The shortest path to all nodes
C. The fastest runtime
D. The longest path

12.What kind of graph does Bellman-Ford operate on?

A. Directed, weighted graphs


B. Undirected, unweighted graphs
C. Directed, unweighted graphs
D. Undirected, weighted graphs
13.How does Bellman-Ford handle negative edges differently from Dijkstra’s?

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

14.Why does Bellman-Ford not use a greedy approach?

A. It processes all edges in every iteration


B. It skips edges with negative weights
C. It prioritizes nodes with larger distances
D. It terminates after one iteration

15.What factor affects the number of iterations needed in Bellman-Ford?

A. The number of edges in the graph


B. The number of vertices in the graph
C. The order in which edges are visited
D. The size of negative weights

16-20 (Answer the following question based on the picture provided)


16. What is the distance of vertex Z after the first iteration?
a) 8
b) 5
c) ∞
d) 9

17. Which edge causes the distance of X to update in the second


iteration?

a) A → V
b) Z → X
c) W → X
d) X → Z

18. What is the shortest distance to vertex Y after the second


iteration?

a) 9
b) 6
c) 7
d) 8

19. What does the Bellman-Ford algorithm check for after completing |V| - 1
iterations?

a) Maximum weight cycle


b) Negative weight cycles
c) The shortest path to the source
d) Whether all vertices are reachable

20. What is the final shortest distance to vertex W?


a) 10
b) 9
c) 11
d) 8
Floyd-Warshall Algorithm Quiz

1. Who are the creators of the Floyd-Warshall algorithm?

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

2. In what year was the Floyd-Warshall algorithm independently developed by its


creators?

a) 1957 b) 1962 c) 1970 d) 1984

3. What problem does the Floyd-Warshall algorithm solve?

a) Single-source shortest path b) All-pairs shortest path c) Minimum spanning tree d) Traveling
salesman

4. Which of the following is NOT a typical application of the Floyd-Warshall algorithm?

a) GPS navigation b) Communication networks c) Routing packets in a network d) Image


compression

5. The Floyd-Warshall algorithm is an example of which programming technique?

a) Greedy algorithms b) Divide and conquer c) Dynamic programming d) Backtracking

6. What is the primary advantage of the Floyd-Warshall algorithm over the Bellman-Ford
algorithm?

a) It handles negative weights b) It solves all-pairs shortest paths instead of single-source


shortest path c) It is faster in all scenarios d) It is easier to implement

7. How does the Floyd-Warshall algorithm handle negative cycles in a graph?

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

8. What is the time complexity of the Floyd-Warshall algorithm?

a) O(V + E) b) O(V log V) c) O(V^2) d) O(V^3)

9. Which data structure is primarily used to store intermediate results in the


Floyd-Warshall algorithm?

a) Adjacency list b) Adjacency matrix c) Priority queue d) Stack


10. In which scenario would you prefer using the Floyd-Warshall algorithm over Dijkstra's
algorithm?

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

12. What is a key limitation of the Floyd-Warshall algorithm?

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

15. Which step is repeated in each iteration of the Floyd-Warshall algorithm?

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?

a) O(V) b) O(V + E) c) O(V^2) d) O(V^3)

17. What is the role of the intermediate vertex in the Floyd-Warshall algorithm?

a) It connects non-adjacent vertices directly b) It serves as a possible connection point to


improve paths c) It only affects paths that include negative weights d) It helps in converting
undirected graphs to directed graphs
18. In which field is the Floyd-Warshall algorithm particularly useful for analyzing
connection strengths?

a) Astronomy b) Social network analysis c) Image processing d) Quantum computing

19. Which other algorithm can be combined with the Floyd-Warshall algorithm to handle
more complex scenarios?

a) Kruskal's algorithm b) Prim's algorithm c) Dijkstra's algorithm d) A* algorithm

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:

1. Who are the creators of the Floyd-Warshall algorithm?

Answer: b) Robert Floyd and Stephen Warshall


Rationale: The Floyd-Warshall algorithm is named after its creators, Robert Floyd and Stephen
Warshall, who independently contributed to its development.

2. In what year was the Floyd-Warshall algorithm independently developed


by its creators?

Answer: b) 1962
Rationale: The algorithm was independently discovered in 1962 by Robert Floyd and Stephen
Warshall.

3. What problem does the Floyd-Warshall algorithm solve?

Answer: b) All-pairs shortest path


Rationale: The Floyd-Warshall algorithm efficiently computes the shortest paths between all
pairs of vertices in a weighted graph.
4. Which of the following is NOT a typical application of the Floyd-Warshall
algorithm?

Answer: d) Image compression


Rationale: The algorithm is used in networking and routing applications but has no direct
application in image compression.

5. The Floyd-Warshall algorithm is an example of which programming


technique?

Answer: c) Dynamic programming


Rationale: It uses dynamic programming principles to iteratively improve the shortest path
estimates.

6. What is the primary advantage of the Floyd-Warshall algorithm over the


Bellman-Ford algorithm?

Answer: b) It solves all-pairs shortest paths instead of single-source shortest path


Rationale: The Floyd-Warshall algorithm handles all-pairs shortest paths, while Bellman-Ford
focuses on single-source shortest paths.

7. How does the Floyd-Warshall algorithm handle negative cycles in a


graph?

Answer: b) It flags them and stops execution


Rationale: The algorithm identifies negative cycles by checking the diagonal of the distance
matrix for negative values.

8. What is the time complexity of the Floyd-Warshall algorithm?

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?

Answer: b) Adjacency matrix


Rationale: An adjacency matrix is used to store and update the shortest path distances
between all pairs of vertices.

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: b) By considering each vertex as an intermediate point


Rationale: The algorithm iteratively refines path estimates by treating each vertex as a
potential intermediate vertex.

12. What is a key limitation of the Floyd-Warshall algorithm?

Answer: b) It is inefficient for graphs with a large number of vertices


Rationale: Its O(V^3) time complexity makes it impractical for very large graphs.

13. Which of the following is a correct initialization step for the


Floyd-Warshall algorithm?

Answer: b) Set the distance between a vertex and itself to zero


Rationale: The algorithm initializes the distance of a vertex to itself as 0 and uses given edge
weights for adjacent vertices.
14. How does the Floyd-Warshall algorithm handle graphs with negative
edge weights but no negative cycles?

Answer: b) It successfully computes the shortest paths


Rationale: The algorithm can handle graphs with negative weights, provided there are no
negative cycles.

15. Which step is repeated in each iteration of the Floyd-Warshall


algorithm?

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.

16. In terms of space complexity, what is the main requirement of the


Floyd-Warshall algorithm?

Answer: c) O(V^2)
Rationale: The algorithm uses a distance matrix of size V x V.

17. What is the role of the intermediate vertex in the Floyd-Warshall


algorithm?

Answer: b) It serves as a possible connection point to improve paths


Rationale: Each vertex is considered as an intermediate point to optimize path lengths.

18. In which field is the Floyd-Warshall algorithm particularly useful for


analyzing connection strengths?

Answer: b) Social network analysis


Rationale: It helps analyze connectivity and influence in social network graphs.

19. Which other algorithm can be combined with the Floyd-Warshall


algorithm to handle more complex scenarios?
Answer: c) Dijkstra's algorithm
Rationale: Combining Floyd-Warshall with Dijkstra can help solve specific pathfinding
problems more efficiently.

20. How does the Floyd-Warshall algorithm detect negative cycles in a


graph?

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.

Let me know if you need further clarifications!


DIAL’S ALGORITHM QUIZ

Quiz on Dial's Algorithm

1. Who invented Dial's Algorithm?

A. Robert B. Dial​
B. Edsger Dijkstra​
C. Alan Turing​
D. John von Neumann​
Answer: A

2. What is the main purpose of Dial's Algorithm?

A. To find the shortest paths in a graph with negative edge weights​


B. To find the shortest paths in a graph with non-negative edge weights and a small weight
range​
C. To sort data efficiently​
D. To traverse a graph in breadth-first order​
Answer: B

3. Dial's Algorithm uses which of the following data structures?

A. Priority queue​
B. Stack​
C. Buckets​
D. Binary heap​
Answer: C

4. What is the main advantage of Dial's Algorithm over Dijkstra's Algorithm?

A. It works with negative edge weights​


B. It has a simpler implementation​
C. It is faster for graphs with small range weights​
D. It uses less memory​
Answer: C

5. Which of these terms refers to a connection between two vertices in a graph?

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. Increasing the edge weight​


B. Updating the shortest known distance to a vertex​
C. Skipping the current vertex​
D. Removing vertices from the graph​
Answer: B

9. Which of the following is NOT an application of Dial's Algorithm?

A. Route planning in transportation networks​


B. Gaming and AI pathfinding​
C. Sorting numbers in ascending order​
D. Telecommunication network optimization​
Answer: C

10. What is the space complexity of Dial's Algorithm?

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

12. What does the term "source vertex" mean?

A. A vertex with the smallest weight​


B. The starting point for finding the shortest paths.​
C. The vertex with no outgoing edges​
D. A vertex that is not connected to the graph​
Answer: B

13. What is the main drawback of Dial's Algorithm?

A. It cannot handle graphs with non-negative weights​


B. Dial’s algorithm is only applicable when the range of the edge weights is small.​
C. It is slower than Dijkstra's Algorithm for all graphs​
D. It cannot be implemented in Python​
Answer: B

14. How does Dial's Algorithm handle large edge weights efficiently?

A. By splitting weights into smaller ranges​


B. By increasing the number of buckets​
C. By converting the graph into a smaller equivalent graph​
D. It does not handle large edge weights efficiently​
Answer: D

15. What does the "addEdge" function do in the Python implementation of Dial's
Algorithm?

A. Removes an edge from the graph​


B. Adds an edge between two vertices with a given weight​
C. Deletes a vertex from the graph​
D. Updates the shortest path in the graph​
Answer: B
DIAL’S ALGORITHM QUIZ
16. How does Dial's Algorithm handle vertices with the same distance from the source?

A. Places them in the same bucket​


B. Ignores all but one vertex​
C. Places them in separate buckets​
D. Processes them in reverse order​
Answer: A

17. What is the main difference between Dijkstra's Algorithm and Dial's Algorithm?

A. Dial's Algorithm uses a priority queue​


B. Dial's Algorithm uses buckets instead of a priority queue​
C. Dial's Algorithm works for graphs with negative weights​
D. Dial's Algorithm is slower for small graphs​
Answer: B

18. Which function removes and returns the first element from a list in Python?

A. .append()​
B. .pop()​
C. .remove()​
D. .clear()​
Answer: B

19. Which of the following is a valid application of Dial's Algorithm?

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?

A. It cannot handle non-integer weights​


B. It becomes slower due to the large number of buckets required​
C. It fails to calculate the shortest path accurately​
D. It uses a priority queue​
Answer: B
Group 15: MultiStage Graph: (Antido,Baste,Reovoca)
QUIZ
TEST I. MULTIPLE CHOICE
1. What is a directed, weighted graph in which the nodes can be divided into a set of stages?
A. Multistage Graph
B. Dynamic programming
C. Path
D. Data
2. What should we find from source to destination?
A. Data
B. Path
C. Time Complexity
D. Cost
3. What is dynamic programming?
A. A computer programming technique.
B. A directed graph where vertices are partitioned
C. The problem finding path with minimum cost from source to sink.
4. Symbol for COST?
A. [d]
B. [i]
C. [j]
D. [p]
5. Usually has to do with finding the maximum and minimum range of the algorithmic query.
A. Multistage graph
B. Dynamic programming
C. Simple greedy method

TEST II. ENUMERATION


1-4: various strategies that we can apply in multi-stage graph.
- BRUTE FORCE
- SIMPLE-GREEDY METHOD
- DYNAMIC PROGRAMMING
- DIJKSTRA’S ALGORITHM
5-8: best options that we should find in dynamic programming.
- COST
- MINIMUM
- DATA
- PATH
9-10: write one advantage and disadvantage of multistage graph.
(Advantage)
- Implementation
- Efficiency
(Disadvantage)
- Space
- Interpretation

Test III. Find the shortest path.


V 1 2 3 4 5 6 7 8 9 10 11 12
COST 16 7 9 18 15 7 5 7 4 2 5 0
d 2/3 7 6 8 8 10 10 10 12 12 12 12

d = (1,1) = 2

d = (2,2) = 7

d = (3,7) = 10

d = (4,10) = 12

You might also like