Searching and sorting Flashcards

1
Q

what are the 2 search methods

A

linear
binary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how does linear search work

A

goes through each item in the list and checks to see if it is the right one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how does binary search work

A

finds the middle item in the list
checks if it is the item
compare to see if the item you are looking for is higher or lower than the middle item
remove the unused half of the list
repeat process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what are 3 benefits of linear search

A

simpler
does not need to be sorted
works well on small lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a disadvantage of linear search

A

not as efficient

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what are 2 advantages of binary search

A

efficient
work well on large lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what are 2 disadvantages of binary search

A

require list to be sorted
more complex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what are the 3 sorting algorithms in order of efficiency

A

bubble
insertion
merge

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how does bubble sort work

A

look at 2 items at a time, and will swap them if they are in the wrong order. will keep doing this process until there is a pass that has no swaps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what are the 2 pros of bubble sort

A

it’s simple
doesn’t use a lot of memory as sorting is done using the original list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is a cons of bubble sort

A

inefficient and slow

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how does merge sort work

A

keep splitting a large list until a lot of sublists with 1 item in each are made
merge and order the sublists back together until you have one list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what are 1 pros of merge sort

A

very quick and efficient

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what are 3 cons of merge sort

A

slower for small lists
uses a lot of memory
complex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

how does insertion sort work

A

goes through each item and puts them in the right place using the first item in the list as a starting point

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what are 2 pros of insertion sort

A

simple
doesn’t require a lot of memory