algorithms Flashcards

1
Q

what is abstraction

A

the process of removing unnecessary details and including only relevant details

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

what does decomposition mean

A

breaking a complex problem down into smaller more manageable parts

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

what is a binary search (explain in-depth)

A

1) calculate midpoint in data set
2) check if that is the item to be found :
if not
3)if the item to be found is lower than the midpoint, repeat on the left half of the data set
4)if the item to be found is greater than the mid-point, repeat on the right half of the data set
5) repeat until the item is found or there are no items left to check

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

what does a binary search require

A

requires items to be in order

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

what does a binary search require

A

requires items to be in order

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

binary search is better because

A

its faster/more efficient

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

what does a linear search not require?

A

the data set to be in order

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

what does a linear search do (in depth)

A

starts from the beginning of a data set, each item is checked in turn to see if it is the one being searched for

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

bubble sort does what…(in depth)

A

it sorts an unordered list of items
compares each item with the next one and swaps them if they are out of order

the algo finishes when no more swaps need to be made
(it bubbles up the largest/smallest item to the end of the list

it is the most inefficient sorting algo but easiest to implement

popular for small data sets

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

bubble sort example (very long winded)

A

smallest to largest
6,4,5,2,3,1
first, check 6 and 4, 4 is smaller than 6 so swap places
4,6,5,2,3,1
now check 6 and 5, 5 is smaller so swap
4,5,6,2,3,1
now check 6 and 2, 2 is smaller so swap
4,5,2,6,3,1
check 6 n 3, 3 is smaller
4,5,2,3,6,1
check 6 and 1, 1 smaller
4,5,2,3,1,6
first pass done, but 6 is at the end, so 2nd pass needed

4,5,2,3,1,6
4,2,5,3,1,6
4,2,3,5,1,6
4,2,3,1,5,6

2nd pass done
3rd pass, we ignore 5 and as they are sorted
4,2,3,1,5,6
2,4,3,1,5,6
2,3,4,1,5,6
2,3,1,4,5,6
4th pass, ignore 4 5 6
2,3,1,4,5,6
2,1,3,4,5,6
5th
2,1,3,4,5,6
now all we need to do is swap 2 and 1
1.2.3.4.5.6

this is bubble sort.

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

insertion sort

A

the insertion sort inserts each item into its correct position in a data set one at a time

it is useful for small data sets

useful for insertings items into an already sorted list

usually replaced by more efficient sorting algorithms for large data sets

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

merge sort

A

creates two or more identical sub problems from the largest problem and solves them individually

combines their solutions to solve the bigger problem

data set repeatedly split in half
until each item is in its own list

adjacent lists are then merged back together

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