Professional Documents
Culture Documents
Part I - Bubble Sort and Linear Search
Part I - Bubble Sort and Linear Search
NOTE – PART I
Algorithms
❖ There are some pre-defined algorithms already available for us to be used in our
programs.
❖ Some of them are Sorting Algorithms and Search Algorithms.
Sorting Algorithms
Sorting Algorithms are used to sort (arrange) a set of data according to a specific order.
Examples:
• Numeric data can be sorted according to their numeric value (ascending / descending).
• String (mostly non-numeric) data can be sorted according to the alphabetic order
(ascending/descending).
Examples:
• It is much easier to find a student in the register if the student names are sorted
according to the alphabetical order or according to the ascending order of their
student IDs numbers.
• It is much easier to search for a particular number within a set of numbers if the
numbers are sorted.
Bubble Sort
❖ Bubble Sort is the easiest sorting algorithm that works by repeatedly switching the
adjacent data elements if they are in the wrong order.
❖ Each pair of data will be compared with each other to decide whether to swap (switch)
with each other or not.
❖ Comparison depends on the order of the elements that we are considering.
Example:
Please read the textbook example from page 14 to 19.
Linear Search
❖ Linear search algorithms are a sequential search algorithm that starts the searching
process from the first value of the set of data until the end of the data set.
❖ The data element we are looking for may or may not be found within the data set.
Example:
Please read the textbook note in page 13. An example will be given and explained in the
class.