1. Home
  2. Explore
  3. Computer Science
  4. Sorting Algorithms Overview

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Sorting Algorithms Overview

  • 34Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Basic Sorting Algorithm
In the basic sorting algorithm, the outer loop variable i starts at
.

34 questions

  1. 1
    In the basic sorting algorithm, the outer loop variable i starts at
    _____
    .
    Hint

    Array indices in C++ begin at this value.

    Answer

    0

  2. 2
    In 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

  3. 3
    To sort in descending order using the basic algorithm, the comparison operator is changed from < to
    _____
    .
    Hint

    The opposite of ascending order.

    Answer
  4. 4
    The basic sorting algorithm uses a temporary variable named
    _____
    to perform swaps.
    Hint

    This variable temporarily holds one value during the swap.

    Answer

    temp

  5. 5
    The header file included to use the rand() function is
    _____
    .
    Hint

    This header provides C standard library functions.

    Answer
  6. 6
    The #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

  7. 7
    In 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

  8. 8
    The 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

  9. 9
    In 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

  10. 10
    Selection sort has a time complexity of
    _____
    .
    Hint

    This is a quadratic time complexity common in simple sorts.

    Answer

    O(n2)O(n^2)O(n2)

  11. 11
    In selection sort, the outer loop runs from i = 0 to i <
    _____
    .
    Hint

    The loop stops before the last element.

    Answer

    n-1

  12. 12
    The swap function in selection sort takes three parameters: the array, index x, and index
    _____
    .
    Hint

    The second index to swap with.

    Answer

    y

  13. 13
    The infinite loop in selection sort was caused by forgetting to increment the loop variable
    _____
    .
    Hint

    This variable controls the outer loop.

    Answer

    i

  14. 14
    In 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

  15. 15
    In 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

  16. 16
    Bubble sort has a time complexity of
    _____
    .
    Hint

    This is the same as selection sort.

    Answer

    O(n2)O(n^2)O(n2)

  17. 17
    The bubbleSort function calls bubbleProcess
    _____
    times.
    Hint

    The number of passes needed to fully sort.

    Answer

    n-1

  18. 18
    In bubble sort, the outer loop runs from i = 0 to i <
    _____
    .
    Hint

    This is the same as many other sorting algorithms.

    Answer

    n-1

  19. 19
    The 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

  20. 20
    Insertion sort assumes that the first
    _____
    elements are already sorted.
    Hint

    This variable represents the current position in the loop.

    Answer

    i

  21. 21
    In insertion sort, the key value is stored from array index
    _____
    .
    Hint

    This is the element to be inserted into the sorted part.

    Answer

    i

  22. 22
    The insert function shifts elements while j >= 0 and a[j] >
    _____
    .
    Hint

    This is the value being inserted.

    Answer

    key

  23. 23
    Insertion sort has a time complexity of
    _____
    .
    Hint

    Like bubble and selection sort, this is a quadratic time algorithm.

    Answer

    O(n2)O(n^2)O(n2)

  24. 24
    In insertion sort, the outer loop starts at i =
    _____
    .
    Hint

    The first element is considered already sorted.

    Answer

    1

  25. 25
    Merge sort uses a
    _____
    function that calls the auxiliary mergeSort function with start and end indices.
    Hint

    This function simplifies the initial call.

    Answer

    wrapper

  26. 26
    The 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

  27. 27
    The midpoint in merge sort is calculated as (start + end) /
    _____
    .
    Hint

    This operator performs division.

    Answer

    2

  28. 28
    The 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

  29. 29
    Merge sort has a time complexity of
    _____
    .
    Hint

    This is faster than quadratic time.

    Answer

    O(nlog⁡n)O(n \log n)O(nlogn)

  30. 30
    After 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

  31. 31
    The buffer in merge sort is deallocated using the
    _____
    keyword.
    Hint

    This keyword frees dynamically allocated memory.

    Answer

    delete

  32. 32
    The sorting algorithms with O(n2)O(n^2)O(n2) time complexity include basic, selection, bubble, and
    _____
    .
    Hint

    Another simple sorting algorithm covered.

    Answer

    insertion

  33. 33
    Merge sort has a time complexity of O(nlog⁡n)O(n \log n)O(nlogn), which is faster than O(O(O(
    _____
    ))) algorithms.
    Hint

    This is a quadratic term.

    Answer

    n^2

  34. 34
    As input size increases, O(n2)O(n^2)O(n2) algorithms grow
    _____
    while O(nlog⁡n)O(n \log n)O(nlogn) algorithms remain relatively fast.
    Hint

    This word describes rapid growth.

    Answer

    exponentially

1 of 34
Question 1 of 34

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent