Algorithms Flashcards

1
Q

Flowchart symbols

A

curved rectangle = start/end
rectangle = instruction
diamond = decision
linked by arrowed lines

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

Bubble sort

A

compare adjacent terms

1) start at beginning of the list. Pass through the list and compare adjacent values. For each pair of values:
- if they are in order, leave them
- if they are not in order, swap them
2) when you get to the end of the list, repeat step 1
3) when a pass is completed without any swap,s the list is in order

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

Algorithm =

A

a defined, finite sequence of instructions used to solve a problem

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

Quick sort algorithm

A
  • select pivots and split items into sub-lists
    1) choose the item at the midpoint of the list to be the first point (round up 0.5(n+1) so right if even)
    2) Write down all the items that are less than the pivot in a sublist whilst keeping their order
    3) Write down/add the pivot
    4) Wrote down the remaining items (those greater than the pivot) in a sublist
    5) Apply steps 1 to 4 to each sublist
    6) when all items have been chosen as pivots, stop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Points on quick sort

A

Number of pivots could double at each path. 2^(n-1) n paths

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

Points on bubble sort

A

Maximum number of passes = n-1 as after each pass you exclude a number from the end
Max number of swaps/comparisons = 0.5n(n-1) as first pass has (n-1) comparisons and final pass has (n-(n-1)) comparisons

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

Compare the relative efficiency of sorting algorithms by

A

comparing the number of comparisons and swaps that are made to sort the same list of numbers

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

First fit decreasing algorithm

A

place items in the first possible bin from largest to smallest item

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

Full bin packing algorithm

A

find combinations of items that will fill a bin

any remaining items are packed using the first fit algorithm

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

Pro and con of full bin algorithm

A

pro: usually a good solution
con: large numbers make it difficult to do

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

Con of first fit decreasing algorithm

A

must be sorted first before first fit algorithm applied so requires more computation

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