Year 1 - Decision Flashcards

1
Q

1.1 How can algorithms be written?

A

Code, flowcharts, or a set of instructions

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

1.1 What can be used to implement an algorithm?

A

A trace table

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

1.2 What does the shape of each box in a flowchart tell you about the function?

A

Oval - Start/End
Rectangle - Instruction
Diamond - Decision

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

1.3 Describe a bubble sort

A

Compare adjacent items in a list:
- If they are in order, leave them
- If they are not in order, swap them
- After the first pass, the last item will be in the correct place
- When a pass is completed with no swaps, the sort is complete

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

1.3 What is the expression for the maximum number of comparisons in a bubble sort?

A

(n(n -1))/2

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

1.4 Describe quick sort

A

Select a pivot and split the items into 2 sub-lists:
- One contains the items less than the pivot
- The other contains the items greater than the pivot
- Select further pivots from within each sub-list and repeat the process

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

1.5 What are the 3 bin packing algorithms? Describe them

A

First-fit: Items in order listed, place each item in the first available bin

First-fit descending: Sort into descending order, then apply the first-fit algorithm

Full-bin: Use inspection to select items that will fill a bin first. Remaining items packed with first-fit

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

1.5 What are the advantages and disadvantages of first-fit?

A

+ve - Quick to implement

-ve - Unlikely to lead to an optimal solution

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

1.5 What are the advantages and disadvantages of first-fit descending?

A

+ve - Usually an optimal solution, easy to implement

-ve - May not find optimal solution, takes a long time

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

1.5 What are the advantages and disadvantages of full-bin?

A

+ve - Usually an optimal solution

-ve - Difficult especially when numbers are large/awkward

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

1.6 What is the order of an algorithm?

A

If an algorithm has order f(n), then increasing the size of the problem from n to m will increase the run time by a factor of approximately f(m)/f(n)

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

1.6 What order does bubble sort have? Explain how you get this

A

A list has n items, the first pass will require (n-1) comparisons, a second pass will require (n-2) comparisons, in the worse case this continues, the total number of comparisons would be:
1+2+3+…+(n-3)+(n-2)+(n-1) = (1/2)(n-1)n = (1/2)n^2 - (1/2)n

Since this is a quadratic expression, bubble sort is taken to have quadratic order

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

1.6 What are the rules for linear, quadratic, and cubic order?

A

If the size of a problem is increased by some factor k then:
- an algorithm of linear order will take approximately k times as long to complete

  • an algorithm of quadratic order will take approximately k^2 times as long to complete
  • an algorithm of quadratic order will take approximately k^3 times as long to complete
How well did you know this?
1
Not at all
2
3
4
5
Perfectly