T6 - Computational Thinking/ Searching/ sorting algorithms Flashcards
Algorithms
set of instructions for solving a problem or completing a task
Abstraction
involves removing unnecessary detail from a problem so that you can focus on the essential components
Algorithmic thinking
– an approach to solving problems by the use of algorithms (sequences of steps that lead to a solution)
Structure diagram
– a hierarchical diagram that shows how a problem is broken down into sub-sections/sub-tasks
Decomposition
- involves breaking down a large problem into smaller sub-problems
Then the sub-problems can be broken down further until each small task is manageable
Advantages of decomposition
- easier to solve
-reusable
-saving development time
A structure diagram
is used to show how a problem is broken down
Linear search:
requires checking through each item in the list, one by one
very slow
Don’t have to be sorted
Binary search:
List must be sorted
Examine the middle one first
the size of the list is halved each time an item is examined
The data sets could be sorted as follows:
Count order (which will be the same as the rank order)
Alphabetical order
Reverse alphabetical or count order
The bubble sort:
Start with the leftmost item
Compare this item with the one next to it
If the one next to it is less, swap the items
Repeat for all the other items
At the end of one pass through the list, the largest item is at the end of the list
Repeat the process until the items are sorted
Bubble sort - saving data:
When data is swapped, it is saved to a temporary variable
Then it is copied from the variable
Insertion sort:
sorts one data item at a time
One item is taken from the list, and placed in the correct position
This is repeated until there are no more unsorted items
Faster than bubble sort
Merging two lists:
Read item from list A; Read item from list B
Write smaller to output list.
Read next item from the list that held the smaller value
Repeat until all items written to output list
Merge sort pros:
More efficient than bubble sort and insertion sort