Section 4 - Algorithms Flashcards
what are the 3 key techniques for computational thinking?
decomposition
algorithmic thinking
abstraction
what is decomposition?
breaking down a complex problem into smaller problems and solving each 1 individually
what is abstraction?
picking important bits of information from a problem, ignoring the specific details that don’t matter
what is algorithmic thinking?
a logical way of getting from the problem to the solution. if the steps you take follow an algorithm then they can be reused and adapted to solve similar problems in the future
what does pseudocode do?
it should follow a similar structure to programming language
it should show an algorithms steps without going into to much detail.
what are the advantages of pseudocode?
it is quick to write and can be easily converted to any programming language
how to carry out a binary search?
- find middle item in list
- if the item is the target, stop the search
- if not, compare target to middle item.
if it is too high get rid of 2nd half of list
if too low get rid of 1st half of list - repeat steps 1 - 3 until item is found or until the list is gone then tell the user it is not in the list
what does a binary search do?
it finds items in an ordered list
what does a linear search do?
it checks each item in a list until it finds it or it has checked every item
how to carry out a linear search?
- look at 1st item and compare with target
- if this item is the target stop the search
- if not, look at next item
- repeat steps 2 - 3 until the item is found or every item has been checked
what are the advantages of a binary search over a linear search?
it is more efficient
it generally takes less steps than linear
it is suitable for large lists
what are the advantages of a linear search over a binary search?
it is much simpler
it can be used on any type of list, it doesn’t have to be ordered
usually used on small lists because it is inefficient
what does a bubble sort do?
it is used to sort an unordered list, it is simple but can take a while
how to carry out a bubble sort?
- compare first 2 items in list
- if they are in the right order do nothing if not swap them
- move to next pair (2 and 3) repeat step 2
- repeat step 3 until the end of the list, the last item is now in the right place so don’t include it in the next “pass”
- repeat steps 1-4 until there is no swaps in a pass
what are the pros of bubble sorts?
simple algorithm, ca be easily implemented on a computer
its an efficient way to check if a list is in order because only 1 pass needs to be done
it doesn’t use much memory because all the sorting is done using the original list