Algorithms - 2.1 Flashcards
What are the 3 key techniques for computational thinking?
Decomposition
Abstraction
Algorithmic thinking
What is decomposition (2)?
Breaking a complex problem down into smaller problems
Solving each one individually
What is abstraction (2)?
Picking out the important details from a problem
Ignoring the specific details
What is algorithmic thinking (2)?
A logical way of getting the answer to a problem
Sequence of instructions which are followed step-by-step
What are the different searches?
Binary search
Linear search
What is an algorithm?
Set of instructions for solving a problem
What are the different ways an algorithm can be written?
Pseudocode
Flowcharts
What is pseudocode (4)?
Not an actual programming language but follows a similar structure
Clearly shows an algorithm’s steps without worrying about the finer details of a programming language e.g. syntax
Quick to write
Easily converted
What is a flowchart (2)?
Used to represent an algorithm
Can represent sequences, selections and interations
What does a flowchart do (4)? How is it presented (2)?
Shows the data that is input and output
Shows the processes
Shows the decisions
Shows the repetitions
Arrows show the flow of control, each shape has a different function
What are the 5 different shapes and functions?
Start/stop - beginning or end of program = box with rounded corners (terminals)
Inputs/outputs - anything that’s put into or taken out of the algorithm = parallelogram
Processes - general instructions, calculations = rectangle
Decisions - yes/no = diamond
Sub program - reference to other flowcharts = box with lines
What are the searching algorithms?
Binary search
Linear search
When is a binary search used? How is it performed (4)?
With an ordered list
1. Look for middle term (n+1/2)
2. If this is the wanted item stop the search
3. If not, compare the middle value and see if it comes before or after the wanted item. If before remove second half if after remove first half
4. Repeat steps 1-4 with smaller list
How is a linear search done?
Looks at each time on the list, stops when it’s found the term or has checked every item
1. Look at first item
2. If this is the item then stop the search
3. If not look at the next item
4. Repeat steps 2 - 3 until item is found or every item is checked
Pros (2) & cons (1) of binary search:
More efficient
Suitable for larger lists
List needs to be ordered