Sorting Algorithms Overview
- 34Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
34 questions
- 1In the basic sorting algorithm, the outer loop variable i starts at_____.
Hint
Array indices in C++ begin at this value.
Answer
0
- 2In the basic sorting algorithm, elements are swapped when array[j] is_____than array[i] to sort in ascending order.
Hint
Think about which value should come first in ascending order.
Answer
less
- 3To sort in descending order using the basic algorithm, the comparison operator is changed from < to_____.
Hint
The opposite of ascending order.
Answer
- 4The basic sorting algorithm uses a temporary variable named_____to perform swaps.
Hint
This variable temporarily holds one value during the swap.
Answer
temp
- 5The header file included to use the rand() function is_____.
Hint
This header provides C standard library functions.
Answer
- 6The #define directive is used to set the maximum array size to_____.
Hint
This value is commonly used as a reasonable upper limit for array size.
Answer
100
- 7In selection sort, the function that finds the index of the smallest element is called_____.
Hint
This helper function locates the minimum element in a range.
Answer
locationOfSmallest
- 8The selection sort function calls the swap function after finding the location of the smallest element using the index_____.
Hint
The function name that provides the index to swap with.
Answer
locationOfSmallest
- 9In the locationOfSmallest function, the variable that stores the index of the smallest element is initially set to_____.
Hint
This is the starting index parameter.
Answer
s
- 10Selection sort has a time complexity of_____.
Hint
This is a quadratic time complexity common in simple sorts.
Answer
O(n2)
- 11In selection sort, the outer loop runs from i = 0 to i <_____.
Hint
The loop stops before the last element.
Answer
n-1
- 12The swap function in selection sort takes three parameters: the array, index x, and index_____.
Hint
The second index to swap with.
Answer
y
- 13The infinite loop in selection sort was caused by forgetting to increment the loop variable_____.
Hint
This variable controls the outer loop.
Answer
i
- 14In bubble sort, the bubbleProcess function compares elements from the_____of the array to the top.
Hint
The opposite of 'top' in this context.
Answer
bottom
- 15In bubble sort, elements are swapped when a[i] is_____than a[i-1] to achieve ascending order.
Hint
Compare the current element with the previous one.
Answer
less
- 16Bubble sort has a time complexity of_____.
Hint
This is the same as selection sort.
Answer
O(n2)
- 17The bubbleSort function calls bubbleProcess_____times.
Hint
The number of passes needed to fully sort.
Answer
n-1
- 18In bubble sort, the outer loop runs from i = 0 to i <_____.
Hint
This is the same as many other sorting algorithms.
Answer
n-1
- 19The bubbleProcess function uses a loop that starts at i = n-1 and decrements until i >_____.
Hint
The loop stops when it reaches the beginning.
Answer
0
- 20Insertion sort assumes that the first_____elements are already sorted.
Hint
This variable represents the current position in the loop.
Answer
i
- 21In insertion sort, the key value is stored from array index_____.
Hint
This is the element to be inserted into the sorted part.
Answer
i
- 22The insert function shifts elements while j >= 0 and a[j] >_____.
Hint
This is the value being inserted.
Answer
key
- 23Insertion sort has a time complexity of_____.
Hint
Like bubble and selection sort, this is a quadratic time algorithm.
Answer
O(n2)
- 24In insertion sort, the outer loop starts at i =_____.
Hint
The first element is considered already sorted.
Answer
1
- 25Merge sort uses a_____function that calls the auxiliary mergeSort function with start and end indices.
Hint
This function simplifies the initial call.
Answer
wrapper
- 26The auxiliary mergeSort function has a base case when start is_____than or equal to end.
Hint
This condition stops recursion when the subarray has 0 or 1 elements.
Answer
greater
- 27The midpoint in merge sort is calculated as (start + end) /_____.
Hint
This operator performs division.
Answer
2
- 28The combine function in merge sort merges two sorted subarrays into a single sorted array using a temporary_____.
Hint
This is a dynamically allocated copy of the subarray.
Answer
buffer
- 29Merge sort has a time complexity of_____.
Hint
This is faster than quadratic time.
Answer
O(nlogn)
- 30After the main while loop in combine, two additional while loops are used to copy remaining elements from the_____subarray.
Hint
This is the temporary array holding the original values.
Answer
buffer
- 31The buffer in merge sort is deallocated using the_____keyword.
Hint
This keyword frees dynamically allocated memory.
Answer
delete
- 32The sorting algorithms with O(n2) time complexity include basic, selection, bubble, and_____.
Hint
Another simple sorting algorithm covered.
Answer
insertion
- 33Merge sort has a time complexity of O(nlogn), which is faster than O(_____) algorithms.
Hint
This is a quadratic term.
Answer
n^2
- 34As input size increases, O(n2) algorithms grow_____while O(nlogn) algorithms remain relatively fast.
Hint
This word describes rapid growth.
Answer
exponentially

Ask anything
We've read this whole study set, so questions about it get the best answers.