Chapter 1 Algorithms Flashcards

1
Q

Definition of an Algorithm

A

An algorithm is a FINITE sequence of operations
To carry out a procedure or solve a problem

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

What are the three things an algorithm MUST BE

A

1) UNAMBIGOUS
- the program should never have to make a choice at any point, based on conditions it must be sble to know what to do

2) DETERMINISITIC
- can’t have probabilities of going down paths (no chance involved)

3) FINITE
- CAN NOT LOOP FOREVER , must have some end and stop

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

What is the most typical problem with an algorithm if they say there is one

A

It’s not finite, it loops forever most likely

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

Algorithm flowchart shaped and meaning

Kite rectangle circle parallelogram

A

Circle = start stop

Parallelogram = input or output (variable or text)

Rectangle = common (add x+y)

Kite = IF STATEMENT ! Decision

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

How to make and fill out a TRACE TABLE

A

make a table with all variables as column headings, along with a PRINT column

  • then for each time you go down a line in the code, go down a row

Keep doing this and fill it out

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

How to try work out what an algorithm is trying to do once yiu traced it out

A

Look at print column and try find a pattern, like fibonacci or mean etc

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

What does algorithmic complexity describe

A

Describes the EFFICIENCY OF THE ALGORITHM
- some algorithms can achieve same thing with less steps, you rather take this as it tskes less power

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

Big O notation what does it show

What case scenario does it show

A

It represents complexity, and shows the steps needed when an algorithm SCALES UP

  • for any algorithm it represents the WORSE case scenario
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain how Big O works and what mean by worse case scenario

A

Example complexity of algorithm is O(N2)
For 10 commands, it takes a time of 5 seconds
And yiu make it 20 commands, the time will increase to 20 seconds, increases by a factor of 4!

2) now this is the worse case scenario , so like if the algorithm had to do the most steps each time , not necessarily gonna take this much time

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

Worse case scenario again

A

Bubble sort best case could be order n but worse case order n 2

So big O Notation takes the WORSE one

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

What complexity is the algorithm typically if there is a COUNTER VARIABLE

A

This will be O(N)

This because the time is proportional to the counter, increase counter increase time linearly

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