Sorting is very important, it enables us to carry out efficient binary searches on large databases.
Bubble Sorting
¢Start at the
beginning of the list.
¢Compare each pair of
items.
¢If they are not in
order swap them.
¢Work through the list
n-1 times.
A working example would be like this:
Insertion Sort
In an Insertion Sort
each element in turn is inserted into it’s correct place in the sorted list.
Advantage
- Faster than bubble sort
Disadvantage
- More complex to code
A worked example is shown below:
The next element to
be inserted into the correct place is shown in red. The sorted part of the list is green.


No comments:
Post a Comment