Chapter 1 algorithms Flashcards

1
Q

Algorithm.

A

A set of instructions which, if carried out correctly, will solve a problem

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

Bubble sorts order is

A

Quadratic

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

Max number of comparisons

A

n(n-1) / 2

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

How to do the bubble sort

A

Adjacent numbers are compared eg 1 and. 2. They are swapped if in wrong order. The second and third number is now compared. After first pass, last number will be correctly positioned and so on. Algorithm stops when a pass provides no swaps

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

Pro of bubble sort

A

Simple to implement
efficent for small lists

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

Cons of bubble sort

A

Extremely inefficient for big lists

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

How to do quick sort

A

Find middle number which becomes the pivot and circle it. If sorting in ascending order, write all numbers smaller than the pivot to the left of the pivot, in the same order. And write all numbers larger than the pivot to the right, keeping same order. The pivot is now fixed. Repeat this for all new sublists created until all numbers are fixed or sublists contain only 1 number.

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

Aim of bin packing

A

Pack items of diff lengths into a minimum number of bins

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

3 types of bin packing

A

First fit
First fit decreasing
Full bins

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

Lower bound

A

Is not always possible

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

Lower bound helps us find

A

Minimum amount of bins

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

Pros of first fit

A

Efficent
Straight forward

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

Cons of first fit

A

Wasted space

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

Pros of first fit decreasing

A

More space used
Pack big ones first

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

Cons of first fit decreasing

A

Spends time ordering first

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

Pros of full bin

A

Quick no ordering

17
Q

Cons of full bin

A

Hard to find combination
Not good for large number of items

18
Q

Order

A

Tells us how the size of a problem will affect its run time (completion time)

19
Q

Efficiency

A

Measure of the run time often proportional to the number of operations

20
Q

Linear order

A

Take k times as long

21
Q

Quadratic order

A

Will take k2 as long

22
Q

Cubic order

A

Will take k3 as long