2.1 Algorithms Flashcards
Computational thinking
Structuring problems in a way that computers can easily follow
Decomposition
Breaking a problem down into smaller subproblems
Abstraction
Removing or hiding unnecessary details from a problem so that important details can be focused on or more easily understood
Algorithmic thinking
Deciding on the order that instructions are carried out and identifying decisions that need to be made by the computer
Structure diagram
Graphical method of decomposing a problem
-each layer breaks down layer above it into smaller and smaller sub-problems
-root and node
Flowchart
Graphical representation of an algorithm
-line
-process
-subprogram
-input/ output
-decision
-terminal
Flowchart symbols - line, process, subprogram, input/output, decision, terminal
Line - arrow
Process - rectangle
Subprogram - rectangle with two lines
Input/ output - parallelogram
Decision - diamond
Terminal (start/end) - rounded rectangle
Trace table
Tool used to follow each line of an algorithm through step by step
-show contents of each variable after each line has been carried out and any output
Standard searching algorithms
-linear search
-binary search
Linear search
Inspecting each item of the list in turn to check if it is the desired value
-when value is matching, item is found. If not, next item is checked
-inefficient
-works on unsorted data
Binary search
- calculate a mid-point in the data set
- check if that is the item to be found
- if the item to be found is lower than the mid-point, repeat on the bottom half of the data set
- if the item to be found is greater than the mid-point, repeat on the top half of the data set
- repeat until the item is found or only one item left
-discard middle value
-more efficient
-only works on sorted list
Standard sorting algorithms
-bubble sort
-merge sort
-insertion sort
Bubble sort
- Comparing pairs of value
- If two values are in wrong order, swapped
- Repeated for each further pair of values
- When last pair of values has been compared, first pass is complete
- Algorithm repeats until pass has been completed with no swaps occurring - guaranteed to be in order
Insertion sort
Splits the list to be sorted in two parts: sorted side and unsorted side
1. Initially, sorted side contains first item in a list, everything else on the unsorted side
2. first item from unsorted list is inserted to sorted list
3. Repeat until unsorted list has no values
-more efficient
-tricky to code
Merge sort
- Splits data up into individual lists
- Pairs of lists are merged back together in order
- Repeats until there is one merged list
-more efficient - sorts large list of random values in a quicker time
-not best for nearly sorted or small lists
-divide and conquer