You are on page 1of 3

Topic 01 – Problem Solving: Algorithms

NOTE – PART I

Data Structures and Algorithms


What is an Algorithm?
❖ An algorithm is a set of steps caried out to do a specific task.
❖ We have already used Flow Charts and Pseudocode to design several algorithms during
last few weeks.

What are Data Structures?


❖ Data Structures are ways of storing temporary data in a computer program.
❖ Data Structures can be used in program designs (Flow Charts and Pseudocode) as well
as in the actual computer programs written in programming languages.
❖ There are simple data storage elements like variables and more complex data storage
elements like arrays and records involved in a program.
❖ Suitable Data Structure to be used in a computer program must be selected depending
on each situation.

What is the relationship between Data Structures and


Algorithms?
We must use one or more Data Structures to store data when we are designing Algorithms.

Monday, October 3, 2022 Page 1 of 3


Topic 01 – Problem Solving: Algorithms
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).

What is the purpose of sorting data?


It is much easier to search a value within a set of data if that set of data are sorted
according to a specific order.

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.

Some of the popular Sorting Algorithms:


1. Bubble sort.
2. Merge sort.
3. Quick sort.

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.

Monday, October 3, 2022 Page 2 of 3


Topic 01 – Problem Solving: Algorithms
NOTE – PART I
Search Algorithms
❖ Search algorithms are used to efficiently search for a specific data element within a set
of data.
❖ The set of data that we are using can be sorted or unsorted. But it is much easier if the
set of data are sorted.

Some of the popular Search Algorithms:


1. Linear search.
2. Binary search.
3. Jump search.

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.

Monday, October 3, 2022 Page 3 of 3

You might also like