Algorithms Flashcards

1
Q

What are the 3 steps to ‘Bubble sort’?

A
  1. Start at the beginning of the list. Pass though the list & compare values. If 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 swaps, the list is ordered
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 6 steps to ‘Quick sort’?

A
  1. Choose the item in the middle of the list as 1st pivot
  2. Write down all the items that are less than the pivot, keeping them in order, into a sub-list
  3. Write down the pivot
  4. Write down the items that are greater than the pivot, keeping them in order, into a sub-list
  5. Apply step 1-4 to each sub-list
  6. When all have been chosen as pivots, STOP
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What do you have to do before a binary search?

A

Order the list

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

What are the 3 steps to do a ‘binary search’?

A
  1. Select the middle item
    n+1 / 2
  2. If T is before M it can’t be in second half of list so it is discarded. If T is after M it can’t be in the first half of list so it is discarded
  3. Repeat 1-2 to remaining list until T is found
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 3 bin packing algorithms?

A
  1. First-fit
  2. First-fit decreasing
  3. Full-bin
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the 2 steps to do a ‘first-fit’ bin sort?

A
  1. Take the items in order given

2. Place each item into 1at available bin. Start from bin 1 each time

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

What is 1 strength and 1 weakness of the first-fit algorithm

A

Strength:
- Quick

Weakness:
- Not likely to lead to a good solution

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

What are the 2 steps to do a ‘first-fit decreasing’ bin sort?

A
  1. Reorder the items so that they are in decreasing order

2. Apply he first-fit algorithm

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

What is 1 strength and 1 weakness of a ‘first-fit decreasing’ algorithm?

A

Strength:

  • Easy to do
  • Usually get good solution

Weakness:
- May not get optimal solution

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

What are the 2 steps to do a ‘full-bin’ bin sort?

A
  1. Use observation to find combination of items that will fill a bin
  2. Any remaining items are packed using ‘first-fit’ algorithm
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is 1 strength and 1 weakness of ‘full-bin’ algorithm?

A

Strength:
- Usually get good solution

Weakness:
- Difficult to do

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