2.1.3 Flashcards

1
Q

what are the different searching algorithms?

A

-linear search
-binary search

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

linear search

A

starts with the first item in a list and compares them to the search criteria one after the other

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

pros of linear search

A

-good on small lists
-simple to code
-doesn’t need to be ordered

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

cons of linear search

A

-takes a while on large lists
-has to go through entire list

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

binary search

A

values in the list have to be ordered and compares the middle value to the data

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

pros of binary search

A

-good on large lists
-doesn’t have many loops

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

cons of binary search

A

-only works on ordered lists
-more complicated to code
-lists need reordering every time a new item is added

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

what are the different sorting algorithms?

A

-bubble sort
-insertion sort
-merge sort

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

bubble sort

A

goes through a list repeatedly, making comparisons between pairs of adjacent items and then swapping elements in the wrong order

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

pros of bubble sort

A

-simple to write the code for
-simple to understand
-doesn’t need much memory

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

cons of bubbles sort

A

-slowest way to sort a list

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

insertion sort

A

each item is taken in turn, compared to the items in a sorted list and placed in the correct position

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

pros of insertion sort

A

-simpler to code than merge sort
-useful for small lists
-faster than bubble sort

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

cons of insertion sort

A

-not effective with large lists

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

merge sort

A

splits large lists into individual lists by breaking them down, sorting them and then merging them back together in one large list

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

pros of merge sort

A

-fastest sorting algorithm
-best option for long lists

17
Q

cons of merge sort

A

-more complicated to code
-may use twice the memory size of the list