02 Section 4 - Algorithms Flashcards
What are the three key techniques for computational thinking?
Decomposition
Abstraction
Algorithmic thinking
Define decomposition:
Breaking a complex problem down into smaller problems and solving each one individually
Define abstraction:
Picking out the important bits of information from the problem, ignoring the specific details that don’t matter
Define Algorithmic thinking:
A logical way of getting from the problem to the solution. If the steps you take to solve a problem follow an algorithm then they can be reused and adapted to solve similar problems in the future
What is pseudocode?
Not an actual programming language but it should follow a similar structure and roughly read like one
-shows the algorithm’s steps, without worrying about the specific syntax of a programming language
What are the features of pseudocode?
- quick to write
- can be easily converted into any programming language
- different ways to write pseudocode, priority is that the person reading it can follow and understand it
What are aspects and rules to follow for pseudocode?
- VARIABLES -are named at the start
- INDENTATION -makes it more readable
- USE CAPITAL LETTERS FOR COMMAND AND KEY WORDS (e.g. PRINT, IF, ELSE, INPUT…)
What is the symbol used for start/stop for flow diagrams?
The beginning and end of the algorithm are put into boxes with rounded corners
What is the symbol used for inputs/outputs for flow diagrams?
Anything that is put into or taken out of the algorithm goes into a parallelogram box`
What is the symbol used for processes for flow diagrams?
General instructions, processes and calculations go in rectangular boxes
What is the symbol used for decisions for flow diagrams?
Decisions, often a ‘yes’ or ‘no’ question, are put in diamond boxes
What is the symbol used for sub routines for flow diagrams?
Sub routines are like sub programs, they reference other flow diagrams
-a rectangle with extra lines at either end (splitting it up into a small vertical rectangle, a large horizontal rectangle then another small vertical rectangle)
What is the symbol used for showing directions for flow diagrams?
Arrows connect boxes and show the direction you should follow. Some boxes might have multiple arrows coming in or going out of them
What are the different ways you can write algorithms?
Pseudocode
Flow diagrams
What are the three ways which a program can be written or features that they can contain?
Sequence
Selection
Iteration
What is sequence?
When there is only one way from start to end
What is selection?
When there are multiple ways to get from start to stop
What is iteration?
When a program contains a loop that allows you to repeat a task
What does a binary search do?
A binary search looks for items in an ordered list
How do you find the middle item of a list?
(n + 1) / 2
-in a list of n items
What is a binary search algorithm?
1) find the middle item in an ordered list
2) if this is the item you’re looking for, stop the search you have found it
3) if not, compare the item you’re looking for to the middle item. If it comes before the middle item get rid of the second half of the list, if it comes after get rid of the first half of the list
4) you’ll be left with a list half the size of the original list, repeat steps 1-3 on the smaller list until you find the item you are looking for
What does a linear search do?
A linear search checks every item in an unordered list to see if it’s the correct one, it stops either when it finds the item or has checked every item
What is a linear search algorithm?
1) look at the first item in the unordered list
2) if this is the item you’re looking for, stop the search
3) if not look at the next item in the list
4) repeat steps 2-3 until you find the item that you’re looking for or you have checked every item
What are the pros and cons of linear search?
PROS
-simpler
-can be used on any type of list (no order needed)
-easy to code
CONS
-less efficient (worst case scenario, checking every item in list)
-not suitable for larger lists