This is a sequential algorithm which start at
the beginning of the list and moves through
one item at a time until it finds a match or
gets to the end of the list
This is an example of brute force
algorithm as it only uses row
computing power to do the task
This is not very efficient way of finding the answer
For the list on the left with 7 items of data the best case would
be the first item there is a match. However the worst case
would be the last item in the list. The average would be 7 + 1 /
2 = 4 item in the list.
For a binary search the data
mush be sorted first into
ascending order. This search
method uses a divide and
conquer method to find
items.
1. Select the median
2. Compare it with the
search item 3. If it is lower
than discard the median
and the higher items or if
it is higher than discard
the median and the lower
items. 4. Recalculate the
new median 5. Repeat until
the item has been found
Comparing linear and binary searches
Binary searches are more
efficient than a linear search but
the list has to be sorted first
Decomposition and Abstraction
Decomposition
Breaking a problem doing into a list of
sub problems, so that it is easier to solve
a problem.
Abstraction
Identify the essential elements that must be included within a program e.g. for a dice throw within a
game you would need to generate a random number between 1 and 6.
Must also identify, input, outputs and processing needed within a solution
Sorting algorithms
Bubble sort
https://www.youtube.com/watch?v=RT-hUXUWQ2I
A bubble sort starts at the begging
of the list and compares each value
with the one next to it
This process is repeats via a Pass until
the list has been sorted into
ascending or descending order
Merge sort
https://www.youtube.com/watch?v=Pr2Jf83_kG0
1- break the list into 2, then
repeat until you have a list of 1
item
2 - reassemble the list in the
same way as you broke it apart,
by comparing each value
putting the flower value first
3 - compare the first vale of each
list putting the smaller value first
in the new joint list
4 - Combine the list in the same
way to form a sorted list