Chapter 1 Algorithms Flashcards
Definition of an Algorithm
An algorithm is a FINITE sequence of operations
To carry out a procedure or solve a problem
What are the three things an algorithm MUST BE
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
What is the most typical problem with an algorithm if they say there is one
It’s not finite, it loops forever most likely
Algorithm flowchart shaped and meaning
Kite rectangle circle parallelogram
Circle = start stop
Parallelogram = input or output (variable or text)
Rectangle = common (add x+y)
Kite = IF STATEMENT ! Decision
How to make and fill out a TRACE TABLE
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 to try work out what an algorithm is trying to do once yiu traced it out
Look at print column and try find a pattern, like fibonacci or mean etc
What does algorithmic complexity describe
Describes the EFFICIENCY OF THE ALGORITHM
- some algorithms can achieve same thing with less steps, you rather take this as it tskes less power
Big O notation what does it show
What case scenario does it show
It represents complexity, and shows the steps needed when an algorithm SCALES UP
- for any algorithm it represents the WORSE case scenario
Explain how Big O works and what mean by worse case scenario
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
Worse case scenario again
Bubble sort best case could be order n but worse case order n 2
So big O Notation takes the WORSE one
What complexity is the algorithm typically if there is a COUNTER VARIABLE
This will be O(N)
This because the time is proportional to the counter, increase counter increase time linearly