You are on page 1of 4

Searching Algorithms

Linear Search:

A linear search is the simplest method of searching a data set.

The Method of Linear Search are:


1. Find the length of the data set.
2. Set the 1st value of the set or the counter to 0
3. See what the value is at the counter 0.
4. Check if the number is the same as the number being searched for.
5. If it is matches, output the value has been found.
6. If it doesn’t match, then increase the counter by 1 and go back to step 3
until the number or the item has been found.
7. If all the items have been checked and no match is found, send a message.

Advantages Disadvantages
If the lists were small or medium, the The Linear Search would be slower in
linear search would be faster. This is larger lists as there are more values
because there are less values so that still have to be checked so it
there is less numbers to compare would be longer.
against.
The list does not need to be sorted as
the list does not split in half like
Binary Search and it can still find the
value if it isn’t in order.
The Linear Search is not affected if
there was any insertions or deletions
in the list so the list would be still be
continued to find the value

Linear Search Photo:

Bubble Sort:
Searching Algorithms
A bubble sort starts at the beginning of an array and checks the first item
against the second item.

Methods of Bubble Sort:


 If the first item is greater than the second item, then the algorithm
swaps them.
 If the first item is less than the second item then the algorithm would
keep it the same, and it move onto the third item and compare it with
the second one.
 If the third item is greater than the second item then the algorithm
would make a swap, if not them it would move onto the second one.

Advantages Disadvantages
It is a simple algorithm that can be It can be very slow, sorting all the
implemented on a computer. very large lists of the items.
Efficient ways to check if a list is
already in order.
Doesn’t use too much memory.

Bubble Sort Photo:

Merge Sort:
Searching Algorithms
A merge sort is a more complex sort, but also a highly efficient one.

A merge sort uses a technique called divide and conquer. The list is repeatedly
divided into two until all the elements are separated individually. Pairs of
elements are then compared, placed into order and combined.

Advantages Disadvantages
It is quicker for larger lists; this is Slower comparative to the other sort
because unlike other bubble sorts it algorithms for smaller lists.
doesn’t go through the whole list
several times.
It has a consistent running time, Uses more memory space, to store
carries out different bits with similar the sub elements of the initial split
times in a stage, list.

Merge Sort Photo:

Binary Search:
Searching Algorithms
A Binary Search is an efficient method of searching n ordered list. It will not
work on a list that has been sorted first.

The Method of Binary Search:


1. Start by setting the counter to the middle position in the list.
2, If the value held there is a match, the search ends and an output will be
sent.
3. If the value is at midpoint is less than the value to be found, the list is
divided in half, the lower half will be ignored and the search keeps to the
upper half of the list.
4. If the value is at midpoint is greater than the value to be found, the list is
divided in half, the upper half will be ignored and the search keeps to the
lower half of the list.
5. The search moves to the midpoint of the remaining items. Step 2 to 4 will
repeat and if the value has not been found then a message will be outputted to
the user.

Advantages Disadvantages
It is a simple algorithm. The list has to be sorted before the
algorithm can be run.
Binary Search is much faster. Even though it a simple code people
get it wrong and it makes it harder.

Binary Search Photo:

You might also like