DSA Quiz 5 with correct answers 100% 2026
DSA Quiz 5 with correct answers 100% 2026 Bubble Sort - Correct Answer Sorting Algorithm: Compare two elements together. If the leftmost element is smaller than the rightmost, swap positions. Else, continue on. Stop when an element is in the position it is supposed to be. - Correct Answer How can we improve the previous sorting algorithm? Bubblesort: n(n-1) / 2 comparisons, 0 to n(n-1)/2 swaps (pairwise) Improved Bubble Sort: n-1 to pair wise comparisons, 0 to pairwise swaps. - Correct Answer What is the #comps and @swaps for the Bubble Sort? How about the improved Bubble Sort? Selection Sort - Correct Answer Sorting Algorithm: Look throughout the list, found out where the smallest and largest elements are, swap their position until the whole array is sorted. Check for when the input is already in sorted order and doesn't need anymore comparisons, thereby saving swaps. - Correct Answer How might we be able to improve the Selection Sort? Selection Sort: Pairwise comparisons, 0 to n-1 swaps. Improved Selection: n-1 to pairwise comparisons, 0 to n-1 swaps. - Correct Answer What is the comparisons and swap complexity of Selection Sort? How about the improved selection sort? Insertion Sort - Correct Answer Sorting Algorithm: Compare a value with items starting at the end of a sorted subarray. Shift with all items larger than the value. Stop when current item is smaller than the value. Use the binary search to find out where the item needs to be inserted into. - Correct Answer How can Insertion Sort be improved? Insertion Sort: n-1 to pairwise comparisons, 0 to pairwise comparisons Improved Insertion Sort: (n-1) / 2 to n(n-1) comparisons, 0 to n-1 swaps. - Correct Answer What is the comparisons and swap complexity of Insertion Sort? How about the improved insertion sort? Merge Sort - Correct Answer Sorting Algorithm: Split array into two subarrays until we have multiple subarrays of one. Merge them back together in ascending order. Quicksort - Correct Answer Use partition and pivoting in order to sort a list quickly. Search and compare elements from one end of a list to another until you are successful in finding a match or unsuccessful - Correct Answer How does a sequential search work? Eagerly advancing and eagerly stopping, eagerly checking is considered better because we are more likely to be advancing than stopping, ergo we are reducing the number of comparisons we need to make. - Correct Answer What are the two different approaches to sequential searching? Which one is considered better? Eagerly advancing: Best case, 2, next best case, 3, worst case n+1, average case (n+1) / 2. This applies for both successful and unsuccessful cases. Eagerly stopping (unsuccessful): Best case, 1, worst case 2n-1, average n-1 Successful: Best case 2, worst case 2n, average case n. - Correct Answer Show the difference in computational time between eagerly advancing sequential search and eagerly stopping
Document information
- Uploaded on
- March 26, 2026
- Number of pages
- 3
- Written in
- 2025/2026
- Type
- Exam (elaborations)
- Contains
- Questions & answers