Sort and Search Algorithms Flashcards

1
Q

A search algorithm is

A

a set of instructions for finding a specific item of data within a data set.

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

An effective search is

A

one which will always either find the solution or determine that the target data is not present

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

An efficient search will

A

find the solution quickly regardless of its location within the data set

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

two common search algorithms are:

A

Linear search and Binary search

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

Linear search

A

checks each term in a dataset one by one until output is found

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

pros and cons of linear search

A

pro: Very easy to implement

con: Slow on a long list

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

Binary Search

A

Looks at the middle value of a dataset, if that value is greater than the target, repeat on the first half of the data set, if it is less than the target, repeat on the second half of the data set. Stop repeating when target is found or the size of our dataset is zero

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

pros and cons of binary search

A

pro: faster than linear search on a large dataset
cons: Dataset must be sorted before starting

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

which search algorithm only works on sorted lists and which works on unsorted lists

A

sorted: linear search
unsorted: binary search

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

examples of sort algorithms:

A

bubble sort, insertion sort and merge sort

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

A sort algorithm is

A

a set of instructions to arrange a dataset into a particular order.

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

An efficient sort algorithm is

A

one which can sort a dataset in a short time.

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

bubble sort

A

compares the first two items in a dataset and swaps them if they are in the wrong order. This process continues for the rest of the dataset. Repeat the whole process until a pass with no swaps happens.

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

What is a pass?

A

A pass is when every item in a dataset has been tested and the end of the dataset has been reached

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

pros and cons of bubble sort

A

pros: easy to implement, does not use much memory
cons: poor for efficiency

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

insertion sort

A

in a dataset, compare second item with first, swap if necessary. take the third item and compare with second and first item. compare items with the previous items: 2 with 1; 3 with 2 and 1; 4 with 3,2 and 1; 5 with 4,3,2 and 1 etc. repeat until sorted list

17
Q

pros and cons of insertion sort

A

pros: easy to implement, little memory used
cons: not very efficient

18
Q

Merge sort is an example of

A

a divide and conquer algorithm

19
Q

merge sort

A

split lists into lists of size one
merge each pair of sublists
continue merging until there is only one list

20
Q

is merge sort or insertion sort more efficient?

A

merge sort is more efficient than insertion sort