Sorting Algorithms to Know for AP Computer Science A

5.0(1)
studied byStudied by 39 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/21

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

22 Terms

1
New cards

Bubble Sort

A sorting algorithm that iteratively compares adjacent elements and swaps them if the first is greater than the second.

2
New cards

Best Case Time Complexity of Bubble Sort

O(n), occurs when the list is already sorted.

3
New cards

Average Case Time Complexity of Bubble Sort

O(n^2), occurs in most cases where elements are in random order.

4
New cards

Worst Case Time Complexity of Bubble Sort

O(n^2), happens when the list is sorted in reverse order.

5
New cards

Selection Sort

A sorting algorithm that finds the minimum (or maximum) element from the unsorted portion and swaps it with the first unsorted element.

6
New cards

Time Complexity of Selection Sort

O(n^2) for all cases, which makes it inefficient for large datasets.

7
New cards

Space Efficiency of Selection Sort

An in-place algorithm that requires no additional memory.

8
New cards

Insertion Sort

A sorting algorithm that builds the sorted list by inserting elements into their correct position one at a time.

9
New cards

Best Case Performance of Insertion Sort

O(n) when the input list is already sorted.

10
New cards

Average Case Complexity of Insertion Sort

O(n^2) when elements are in random order.

11
New cards

Merge Sort

A divide and conquer sorting algorithm that recursively divides the list into halves and merges sorted sublists.

12
New cards

Guaranteed Time Complexity of Merge Sort

O(n log n) in all cases (best, average, worst).

13
New cards

Stability of Merge Sort

Maintains the relative order of equal elements, making it a stable sorting algorithm.

14
New cards

Quick Sort

A sorting algorithm that selects a pivot and partitions the list around it, sorting elements recursively.

15
New cards

Average Case Time Complexity of Quick Sort

O(n log n), occurs with a good choice of pivots.

16
New cards

Worst Case Time Complexity of Quick Sort

O(n^2), occurs if the pivot is the smallest or largest element.

17
New cards

In-Place Sorting in Quick Sort

Requires minimal extra memory, making it more space-efficient compared to merge sort.

18
New cards

Unstable Sorting Algorithm

Quick Sort is an unstable algorithm as it does not preserve the relative order of equal elements.

19
New cards

Gradual Reduction in Bubble Sort

With each pass, the number of elements to compare decreases as the last elements become sorted.

20
New cards

Shifting Elements in Insertion Sort

During insertion, larger elements are shifted one position to the right to accommodate the current element.

21
New cards

Space Complexity of Merge Sort

Requires O(n) additional space for temporary storage when merging.

22
New cards

Sorted/Unsorted Division in Selection Sort

Expands the sorted portion of the list by moving the boundary after each minimum element is swapped.