Decision Maths: 1. Algorithms Flashcards

1
Q

How do you carry out a Quick Sort Algorithm

A

You select a pivot and split the items into two sub-lists - those less than the pivot and those greater than the pivot:

  1. Choose the item at the midpoint of the list to be the first pivot (if there’s an even number of items, choose to the right of the middle)
  2. Write down all the items that are less than the pivot, keeping their order, in sub-list.
  3. Write down the pivot
  4. Write down the remaining items (those greater than the pivot) in a sub list
  5. Apply steps 1 to 4 to each sub-list
  6. When all the items have been chosen as pivots, stop. Write ‘Sort Complete’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Order of an Algorithm

A

The order of an algorithm is described as a function of its size. If an algorithm has an order f(n), then increasing the size of the problem from n to m will increase the run time if the algorithm by a factor of approximately f(m)/f(n).

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

How are Orders Displayed (e.g a Quadratic Order or a Cubic Order)

A

Order n^2
(Quadratic Order)

Order n^3
(Cubic order)

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

If an algorithm has order n^2, what will be the effect of increasing the size of the problem from 10 to 20?

A

Order n^2
(Quadratic Order)

20/10 = 2

2^2 = 4

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

If an algorithm has order n^3, what will be the effect of increasing the size of the problem from 10 to 20?

A

Order n^3
(Cubic Order)

20/10 = 2

2^3 = 8

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

What should you do as a Bubble Sort develops

A

As the bubble sort develops, it is helpful to consider the original list as being divided into a working list, where comparisons are made, and a sorted list containing the items that are in their final positions. To start with, all items are in the working list.

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

Method to perform a Bubble Sort

A
  1. Start that the beginning of the working list and move from left to right comparing adjacent items.
    a) If they are in order, leave them
    b) If they are not in order, swap them.
  2. When you get to the end of the working list, the last item will be in its final position. This item is then no longer in the working list.
  3. If you have made some swaps in the last pass, repeat step 1.
  4. When a pass is completed without any swaps, every item in it’s final position and the list is in order.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the 3 Bin-Packing Algorithms

A
  • First-Fit Algorithm
  • First-Fit Decreasing Algorithm
  • Full-Bin Algorithm
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Method for the First-Fit Algorithm and how does it work

A

Method:
1. Take the items in the given order
2. Place each item in the first available bin that can take it. Start from bin 1 each time.

  • The first-fit algorithm works by considering items in the order they are given.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Advantage(s) and Disadvantage(s) of the First-Fit Algorithm

A

Advantages:
- It is quick to implement

Disadvantages:
- It is not likely to lead to a good solution

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

Method for the First-Fit Decreasing Algorithm and how does it work

A

Method:
1. Sort the items so that they are in descending order.
2. Apply the first-fit algorithm to get the reordered list.

  • The first fit decreasing algorithm requires the items to be in descending order before applying the algorithm.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Advantage(s) and Disadvantage(s) of the First-Fit Decreasing Algorithm

A

Advantages:
- You usually get a fairly good solution
- It is easy to implement

Disadvantages:
- You may not get an optimal solution

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

Method for the Full-Bin Packing Algorithm and how does it work

A

Method:
1. Use observation to find combinations of items that will fill a bin. Pack these items first.
2. Any remaining items are packed using the first-fit algorithm.

  • Full bin packing uses inspection to select items that will combine to fill bins. Remaining items are packed using the first-fit algorithm.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Advantage(s) and Disadvantage(s) of the Full-Bin Packing Algorithm

A

Advantages:
- You usually get a good solution

Disadvantages:
- It is difficult to do, especially when the numbers are plentiful and awkward.

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