Sorting and Runtimes

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/39

flashcard set

Earn XP

Description and Tags

445 final review

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

40 Terms

1
New cards

Towers of Hanoi Runtime

2^(N-1) or O(2^N)

2
New cards

Insertion/Selection sort key instruction

The element selected to be compared and sorted to the others

3
New cards

Insertion sort worst case

O(N²)

4
New cards

Insertion sort average case

O(N²)

5
New cards

Insertion sort worst sorted order NORMALLY

Reverse sorted

6
New cards

Insertion sort worst sorted order LINKED LIST

Sorted

7
New cards

Selectionsort best/worst/average case

O(N²)

8
New cards

Bubblesort worst case runtime

O(N²)

9
New cards

InsertionSort best case runtime

O(N)

10
New cards

ShellSort runtime

O(N^(3/2))

11
New cards

MergeSort runtime

O(nlogn)

12
New cards

QuickSort runtime

O(nlogn)

13
New cards

Quicksort worst case runtime

O(N²)

14
New cards

Sorting algorithm that starts at second element and puts it in the correct place based on the first element. Then it does the third element, then the fourth, then the nth element until sorted

Insertion Sort

15
New cards

Sorting algorithm compares adjacent items two at a time until sorted

Bubble Sort

16
New cards

Sorting algorithm finds the smallest element from the unsorted portion continuously and then swaps it with the first element in the unsorted portion

Selection Sort

17
New cards

Sorting algorithm recursively divides array into subarrays, then sorts the subarrays and combines them together one by one

Merge sort

18
New cards

Sorting algorithm chooses a pivot then sorts the algorithms with items smaller on the left and larger on the right. Then each side is recursively sorted

Quick Sort

19
New cards

Sorting algorithm chooses a gap size and sorts items that are a gap size apart. Reduce gap and do it again. Do insertion sort when gap is 1

ShellSort

20
New cards

Is quicksort stable?

No

21
New cards

is MergeSort stable?

Yes

22
New cards

Is MergeSort or QuickSort better for sorting Objects?

MergeSort

23
New cards

RadixSort runtime

O(KN)

24
New cards

What does the K represent in RadixSort runtime

K = max string length

25
New cards

What does N represent in RadixSort runtime?

N = length of the array

26
New cards

Sorting algorithm that begins with rightmost element and puts them into bins, then adds them back to the array based on their compared order.

RadixSort

27
New cards

What are the requirements to use RadixSort?

Elements must be a Fixed Length

Elements must be digit-accessible

28
New cards

What makes a good hashing function?

Utilizes all parts of the key

Exploit all differences of the key

Utilize the full address space of the hash address

29
New cards

Brute force runtime

O(N) normal case
O(MN) worst case (unlikely)

30
New cards

Rabin-Karp runtime

O(N) (LSV very likely not gaurenteed)

O(MN) worst case (LSV version, very unlikely)

31
New cards

Boyer-Moore runtime

mismatched char heuristic leads to O(N/M) best case SUBLINEAR!! and O(MN) worst case

second heuristic guarantees O(N) worst case

32
New cards

Explain Boyer-Moore first heuristic

First character mis-match, skip to next possible location. (EX: if “f” does not appear in pattern, skip to position after the “f”)

33
New cards

Explain the second heuristic in Boyer-Moore algorithm

If part of the pattern matched, then you encounter a mismatch, check if the part that already matched appears elsewhere (the suffix)

34
New cards

How do you “push” in an Array Stack

Add to the end of logical array

35
New cards

How do you “push” in an LinkedList Stack

Push to the front, and Pop from the front

36
New cards

How many levels are there in MergeSort? How much work is required for each?

O(logN) levels with O(N) work

37
New cards

name the methods in Iterator<T>

hasNext, next, and remove

38
New cards

How do we implement iterators?

Make them a private inner class within your ADT

39
New cards

What is the double hashing formula?

(h1(K) + (num of attempts) * h2(K)) mod (size of table)

40
New cards

Load factor formula (how full the table is)

N/M