SECTION 5 - Algorithms Flashcards
Three key techniques for computational thinking
Decomposition, abstraction, algorithmic thinking
Decomposition
Breaking a complex problem into smaller problems, and solving each one individually.
Abstraction
Focusing only on important pieces of information from the program and ignoring the specific details that are not important.
Algorithmic thinking
A logical way of getting from problem to solution. Algorithm can be reused and used to solve other similar problems.
Pseudocode
Mixture of English and programming language to show steps that program takes.
What is flowchart symbol for start/stop?
Oval
What is flowchart symbol for input/output?
Parallelagram
What is flowchart symbol for processes?
Box
What is flowchart symbol for decision?
Diamond
Binary search process
- Find middle item in ordered list
- If this is item, stop search.
- If not, compare middle item with item you are looking for.
- If it is after middle item, remove first half of list. If it is before middle item, remove second half of list.
- Repeat until item is found.
Linear search process
- Look at first item of list.
- If this item, stop search.
- If not repeat 1-2 until item is found
Bubble sort process
- Look at first 2 items, if in correct order, nothing will happen but if they are in incorrect order, they will be swapped.
- Move on to next pair of items and repeat 1.
- Repeat 3 until end of list is reached - called one pass. DO NOT INCLUDE LAST NUMBER IN NEXT PASS as it will now in correct place.
- Repeat passes until list is ordered.
Pros of bubble sort
- Simple algorithm
- Efficient way to check if list is already in order
- Does not use a lot of memory
Cons of bubble sort
- Inefficient
- Due to being inefficient, it cannot cope with large lists
Merge sort process
- Split list in half into 2 subsists. Second sub list should start at the middle item.
- Repeat 1 until all sub lists only contain 1 item
- Merge pairs of sublist, so each one has twice as many items. Each time sublist is merged, sort items in correct order
- Repeat 3 until all items are ordered.
Pros of merge sort
- More efficient that bubbe, insertion sort
- Consistent running time
Cons of merge sort
- Slower that other sorts for short lists
- Even list already ordered, carries out same slow process
- Uses more memory
Insertion sort process
- Looks at second item in list
- Compares to items before and inserts items before into correct order
- Repeat 2 for every other item until last item is inserted correctly
Pros of insertion sort
- Very quick at checking if list is already ordered
- Intuitive way of sorting, can be easily coded
- Copes well with small lists
Cons of insertion sort
- Does not cope well with large lists