Sorting algorithms

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/44

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

45 Terms

1
New cards

Bubble sort (idea)

Repeatedly compare adjacent items and swap if out of order; after each pass, the largest unsorted item “bubbles” to the end.

2
New cards

Bubble sort (one pass)

Scan left→right doing neighbor comparisons/swaps; after the pass, the last position is correct.

3
New cards

Bubble sort (stop early)

If a full pass makes 0 swaps, the list is already sorted—stop.

4
New cards

Bubble sort (time)

Worst/avg: O(n^2). Best (already sorted + early-stop): O(n).

5
New cards

Bubble sort (space)

O(1) extra space (in-place).

6
New cards

Bubble sort (stable?)

Yes—equal elements keep their relative order (with standard adjacent-swap version).

7
New cards

Selection sort (idea)

Repeatedly select the smallest element from the unsorted portion and swap it into the next position.

8
New cards

Selection sort (one pass)

Find minimum in indices i..end, swap with index i.

9
New cards

Selection sort (time)

Best/avg/worst: O(n^2) comparisons (always scans remaining items).

10
New cards

Selection sort (space)

O(1) extra space (in-place).

11
New cards

Selection sort (stable?)

Not necessarily (swapping the min can reorder equals).

12
New cards

Insertion sort (idea)

Build a sorted left portion by taking the next element and inserting it into the correct position (shifting larger items right).

13
New cards

Insertion sort (key operation)

Shift items right until the insertion spot is found, then place the key there.

14
New cards

Insertion sort (time)

Worst/avg: O(n^2). Best (already sorted): O(n).

15
New cards

Insertion sort (space)

O(1) extra space (in-place).

16
New cards

Insertion sort (stable?)

Yes—commonly stable (shifts preserve order of equals).

17
New cards

Merge sort (idea)

Divide the list into halves until single elements, then merge sorted halves back together.

18
New cards

Merge sort (merge step)

Combine two sorted lists by repeatedly taking the smaller front element.

19
New cards

Merge sort (time)

Best/avg/worst: O(n log n).

20
New cards

Merge sort (space)

O(n) extra space (typical array/list implementation).

21
New cards

Merge sort (stable?)

Yes—stable if merge prefers left element on ties.

22
New cards

Merge sort (pattern)

Divide-and-conquer: split → solve subproblems → combine.

23
New cards

Quick sort (idea)

Pick a pivot, partition into < pivot and > pivot, then recursively sort partitions.

24
New cards

Quick sort (partition)

Rearrangement step that moves items so left side < pivot and right side > pivot (pivot ends in its final spot).

25
New cards

Quick sort (time)

Avg: O(n log n). Worst (bad pivots): O(n^2). Best: O(n log n).

26
New cards

Quick sort (space)

In-place partitioning is O(1) extra array space, but recursion stack is typically O(log n) avg (O(n) worst).

27
New cards

Quick sort (stable?)

Not stable in standard in-place versions.

28
New cards

Quick sort (pivot choice)

Better pivot choices (random/median-of-three) reduce chance of worst-case partitions.

29
New cards

Binary search (requirement)

Array/list must be sorted (ascending or descending consistently).

30
New cards

Binary search (idea)

Check the middle element; eliminate half the remaining range each step.

31
New cards

Binary search (mid formula)

mid = (low + high) // 2 (integer division).

32
New cards

Binary search (update rules)

If target < A[mid], set high = mid-1; if target > A[mid], set low = mid+1; if equal, found.

33
New cards

Binary search (time)

O(log n) comparisons.

34
New cards

Binary search (space)

O(1) extra space iterative; O(log n) recursion stack if recursive.

35
New cards

Binary search (not found)

If low > high, the search range is empty → target is not in the list.

36
New cards

In-place (definition)

Uses only constant extra memory (O(1)) beyond the input storage.

37
New cards

Stable sort (definition)

Equal keys keep the same relative order they had in the original input.

38
New cards

Pass (sorting)

A single full sweep/iteration of the main outer loop that places at least one element into its final position.

39
New cards

Comparison sort (definition)

Sorting method that determines order solely by comparing elements (bubble/selection/insertion/merge/quick).

40
New cards

When to use insertion sort

Great for small lists or nearly-sorted data; low overhead.

41
New cards

When to use merge sort

Great when you need guaranteed O(n log n) time and stability; common for linked lists/external sorting.

42
New cards

When to use quick sort

Fast in practice for arrays with good pivots; common default in many libraries (variants).

43
New cards

Bubble vs selection (main difference)

Bubble swaps neighbors repeatedly; Selection finds a min and swaps once per pass.

44
New cards

Insertion vs selection (main difference)

Insertion shifts to insert one key into sorted left side; Selection picks the min and swaps.

45
New cards

Merge vs quick (main difference)

Merge split+merge needs extra memory but guaranteed O(n log n); Quick partitions in-place but worst-case O(n^2).