Back to marketplace

Searching ans Sorting

No description yet. This curated deck is ready for daily study.

Total cards: 24•Content version: v4•Public deck•Updated: 8/1/2026

Card preview (24)

#1
Front (Question)

Search Algorithms

Back (Answer)

• method for finding an item or group of items • Collections could be implicit • Collections could be explicit

#2
Front (Question)

Linear Search

Back (Answer)

• brute force search • list does not have to be sorted • O(n) - where n is len(L)

#3
Front (Question)

Bisection/binary search divide and conquer

Back (Answer)

• list MUST be sorted to give correct answer

#4
Front (Question)

Linear search on a SORTED list

Back (Answer)

• must only look until reach a number greater than e - O(n) - where n is len(L)

#5
Front (Question)

Bisection search

Back (Answer)

• break into smaller version of problems - answer to smaller version is answer to original problem

#6
Front (Question)

Searching a sorted list n is len(L)

Back (Answer)

• linear search => O(n) • binary search => O(log n) (assumes the list is sorted!)

#7
Front (Question)

When to sort first then search?

Back (Answer)

• sort + O(log n) < O(n) -> sort < O(n) - O(log n) • when sorting is less than O(n) -> never true!

#8
Front (Question)

Amortized cost n is len(L)

Back (Answer)

• why bother sorting first • in some cases, may sort list once -> then many searches • AMORTIZE cost of the sort over many searches • SORT + KO(log n) < KO(n) -> for large K, SORT time becomes irrelevant

#9
Front (Question)

Monkey Sort aka bogosort - stupid sort - slowsort - permutation sort - shotgun sort

Back (Answer)

is a random sort, every time through the list get randomly sorted and if lucky it is ordered!

#10
Front (Question)

Monkey Sort - complexity

Back (Answer)

Best case: O(n) where n is len(L) Worst case: O(?) is unbound if really unlucky

#11
Front (Question)

Bubble Sort

Back (Answer)

• Compare consecutive pairs of elements • Swap elements such that smaller is first • Start over when reach end of list • No more swaps = stop

#12
Front (Question)

Bubble Sort - complexity

Back (Answer)

• inner for loop is doing comparisons • out while loop is doing multiple passes until no more swaps O(n2) where n is len(L)

#13
Front (Question)

Selection Sort 1. First step

Back (Answer)

• extract min. element - swap it with element at index 0

#14
Front (Question)

Selection Sort 2. Subsequent step

Back (Answer)

• in remaining sub-list extract min. element - swap it with the element at index 1

#15
Front (Question)

Selection Sort 3. Keep the left portion of the list sorted

Back (Answer)

• at ith step, first i element in list are sorted - all other elements are bigger than first i elements

#16
Front (Question)

Selection Sort - complexity

Back (Answer)

O(n2) where n is len(L)

#17
Front (Question)

Merge Sort

Back (Answer)

Use a divide-and-conquer approach • if list of lenght 0 is 1 - already sorted • if list has more than one element, split into two lists and sort each • merge sorted sublists - look at first element of each, move smaller to wend of result - when one list empty, just copy rest of other list

#18
Front (Question)

Merge Sort - complexity overview

Back (Answer)

• go through two lists, only one pass • compare only smallest elements in each sublist • O(len(left) + len(right) copied elements • O(len(longer list)) comparisons • linear lenght of the lists

#19
Front (Question)

Merge Sort - recursevely

Back (Answer)

• divide list successively into halves - depth-first such that conquer smallest pieces down one branch first before moving to larger pieces

#20
Front (Question)

Merge Sort - complexity 1. at first recursion level

Back (Answer)

• n/2 elements in each list - O(n) + O(n) where n is len(L)

#21
Front (Question)

Merge Sort - complexity 2. at second recursion level

Back (Answer)

• n/4 elements in each list • two merges -> O(n) where n is len(L) Each recursion level is O(n) where n is len(L)

#22
Front (Question)

Merge Sort - complexity 3. dividing list in half

Back (Answer)

with each recursive call: O(log(n)) where n is len(L)

#23
Front (Question)

Merge Sort - complexity

Back (Answer)

O(n log (n)) where n is len(L)

#24
Front (Question)

Sorting Summary n is len(L)

Back (Answer)

bogo sort - randomness, unbound O() bubble sort - O(n2) selection sort - O(n2) - guaranteed the first i elements were sorted merge sort - O(n log(n)) O(n log(n)) is the fastest a sort can be