2.1 New Flashcards
3 principles of algorithmic thinking
-abstraction
-decomposition
-algorithmic thinking
abstraction
the process of removing unnecessary details of a problem of focus on the important features to implement in a solution
examples of abstraction
map of a bus or train route in a city
decomposition
the process of breaking down a large problem into a set of smaller problems
benefits of decomposition
-smaller problems are easier to solve
-each smaller problem can be solved independently of the others
-smaller problems can be tested independently of the others
-smaller problems can be combine to produce a solution to the full problem
algorithmic thinking
the process of creating step-by-step instructions in order ro produce a solution to a problem
how can you use algorithmic thinking to identify each step
-using abstraction and decomposition
what should you do after identifying each step in algorithmic thinking
a precise set of rules can be created and the problem will be solved
2 common searching algorithms
binary search
linear search
binary search
halving a dataset by comparing the target value with the middle value, going left if smaller, right if bigger until it finds the value or realises it is not there
conditions to perform a binary search
data must be in order
steps a binary search will follow to look for a number
- select the middle number
- check if selected number is equal to the target number
- if searched number is larger discard left half, or if searched number is smaller, discard right half
- repeat until number is found or remaining list size is 1 or 0
linear search
starts with the first value in a dataset and checks every value one at a time until all values have been checked
conditions for a linear search
no conditions, does not have to be in order
steps to perform a linear search
- check the first value
- if the value is equal to the target value, stop
- else move to the next value and check
- repeat until all values have been checked or the vale looking for is not found
advantages of binary search
- fast for large dataset
- efficient for repeated searches
disadvantages of binary searches
- dataset must be in order
- more complex to implement
advantages of linear search
- works on unsorted datasets
- faster on very small datasets
- simple to understand and implement