1 - Algortihms Flashcards

1
Q

Define algorithm.

A

Finite sequence of step-by-step instructions carried out to solve a problem.

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

How do you represent an algorithm?

A

Flow chart or trace table.

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

What does an oval represent?

A

Start/end.

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

What does a rectangle represent?

A

Instruction.

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

What does a diamond represent?

A

Decision.

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

How do you sort an unordered list?

A

Bubble sort or quick sort.

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

How do you do a bubble sort algorithm?

A

.Start at top and work left to right comparing 2 adjacent items - swap if not in order.
.When at the end of the working list the final number is in it’s final position - no longer in the working list.
.Repeat step 1 if any passes made.
.Finished if no swaps made in a pass.

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

How do you do quick sort?

A

.Choose midpoint (middle right) as pivot.
.Write all items less than in same order as a sub-list.
.Write pivot.
.Write remaining items in a sub-list.
.Repeat.
.Stop when all items have been a pivot.

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

What could happen to the pivots at each pass in a quick sort?

A

Could double.

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

What are the three bin packing algorithms?

A

First-fit, first-fit decreasing and full bin.

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

How do you find the lower bound?

A

Add all values and divide by max each bin holds - optimal solution.

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

How do you do first-fit? What are the advantages/disadvantages?

A

.Take in order given.
.Place in first available bin starting at bin 1.
.A - Quick.
.D - Not good solution.

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

How do you do first-fit decreasing? What are the advantages/disadvantages?

A

.Sort into descending order.
.Apply first-fit.
.A - Good solution, easy.
.D - Not optimal solution.

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

How do you do full bin? What are the advantages/disadvantages?

A

.Observe and find combinations which fill a bin - pack them first.
.Use first-fit for remaining.
.A - Good solution.
.D - Difficult.

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

Define order/complexity of an algorithm.

A

How changes in size affect run time/completion. If an algorithm has order f(n) the increasing size to m will increase run time by factor f(m)/f(n) approximately.

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

What order does bubble sort have?

A

Quadratic.

17
Q

What happens if a program of linear order increases by factor k?

A

k times as long to complete.

18
Q

What happens if a program of quadratic order increases by factor k?

A

k^2 times as long to complete.

19
Q

What happens if a program of cubic order increases by factor k?

A

k^3 times as long to complete.