Algorithm And
Sorting
Aung Myint Tun
Presented by
CONTENTS
1. What is Algorithm?
2. Usage of Algorithm.
3. Example of Algorithm with flow chart diagram.
4. What is sorting?
5. One of sorting algorithm(Selection Sort)
Previously…
A program MUST be systematically and
properly designed before coding begins.
This design process results in the
construction of an ALGORITHM
An algorithm is a precise set of instructions that you
follow to solve a problem or complete a task.
We can say that algorithm is:
● A step‐by‐step problem‐solving procedure.
● A sequence of instruction that tell how to solve
a particular problem.
● A set of instruction for solving a problem,
especially on a computer.
● A computable set of steps to achieve a desired
result.
However, most agree that algorithm has something
to do with defining generalized processes to get
“output” from the “input”.
What is an
Algorithm?
Recipes
When you follow a recipe, you follow instructions to complete a task.
The instructions are a step-by-step procedure that need to be followed for your recipe to be
successful.
From Algorithm to Program
● Both are sets of instructions on how to do a task;
● Algorithm:
○ talking to humans, easy to understand
○ in plain (English) language
● Program:
○ talking to computer (compiler)
○ can be regarded as a “formal expression” of an algorithm
From Algorithm to Program
PROGRAM
ALGORITHM
a sequence of instructions
describing how to do a task (or
process)
a set of instructions which
are commands to
computers to perform
specific operations on data
Algorithms in Technology
You use an algorithm to tell a computer what to do.
Everything you can do on a computer is able to happen because an
algorithm has been written for it.
Clicking a mouse, opening a word document and playing a game are
all examples of things that have algorithms.
Digital devices all follow algorithms in order for them to work.
Flowchart Symbol and Description
Name Symbol Description
Lozenge Indicates the starting or ending of flowchart
(start / stop : terminal )
Connector Used to connect break in the flowchart
Parallelelogram Use for input and output operation (data)
Rectangle Indicates any interval operation (process)
Diamond Use for asking questions that can have
either TRUE of FALSE / YES or NO
(decision / selection)
Module Sub solution to solve a part of entire problem
Control flow Shows flow direction
Flowchart Example
Design an algorithm to find the area of a
rectangle
The formulas: area = length * width
Input Process Output
Input variable:
length
width
Processing item:
area
Formula:
area = length x width
Step / Solution algorithm:
get input
calculate area
display output
Output:
area
Start
length, width
calculate area
area
End
Pseudo Code Example
Start
Read length
Read width
Calculate area of a rectangle
Display area of a rectangle
End
Design an algorithm to find the area of a rectangle
The formulas: area = length * width
Input Process Output
Input
variable:
length
width
Processing item:
area
Formula:
area = length x width
Step / Solution
algorithm:
get input
calculate area
display output
Output:
area
Start
Prompt the user to enter a length of a rectangle
Prompt the user to enter a width of a rectangle
Calculate the area of a rectangle
Display the area of a rectangle
End
Start
Input length
Input width
Calculate area of a rectangle
Output area of a rectangle
End
OR
OR
What is
sorting?
Sorting
● Sorting means arranging the elements of an array so that they are placed in
some relevant order which may be either ascending or descending.
● Can be used as a first step for searching the data.
● That is, if A is an array, then the elements of A are arranged in a sorted order
(ascending order) in such a way that A[0] < A[1] < A[2] < … < A[N].
● The practical considerations for different sorting techniques would be:
○ Number of sort key comparisons that will be performed.
○ Number of times the records in the list will be moved.
○ Best, average and worst case performance.
○ Stability of the sorting algorithm where stability means that equivalent
elements or records retain their relative positions even after sorting is
Bubble Sort
Selection Sort Insertion Sort
Types of sorting
Quick Sort Merge Sort
• Selection sort is one of the easiest approaches to sorting.
• It is inspired from the way in which we sort things out in day to
day life.
• It is an in-place sorting algorithm because it uses no auxiliary
data structures while sorting.
Selection Sort
How Selection Sort Work?
Selection Sort
● Suppose the name of the array is A and it has four
elements with the following values:
4 19 1 3
 To sort this array in ascending order, n-1,
i.e. three iterations will be required.
Selection Sort
● Iteration-1
The array is scanned starting from the first to the last element and the element that has the
smallest value is selected. The smallest value is 1 at location 3. The address of element that
has the smallest value is noted and the selected value is interchanged with the first element
i.e.
A[1] and A[3] are swapped
4 19 1 3
1 19 4 3
Selection Sort
● Iteration-2
The array is scanned starting from the second to the last element and the element that has
the smallest value is selected. The smallest value is 3 at location 4. The address of element
that has the smallest value is noted. The selected value is interchanged with the second
element i.e.
A[2] and A[4] are swapped
1 19 4 3
1 3 4 19
Selection Sort
● Iteration-3
The array is scanned starting from the third to the last element and the element that has the
smallest value is selected. The smallest value is 4 at location 3. The address of element that
has the smallest value is noted. The selected value is interchanged with the third element
i.e.
A[3] and A[3] are swapped
1 3 4 19
1 3 4 19
SELECTION SORT
Thank You
Presented By Aung Myint Tun
Do You Have Any Question!

Algorithm By AMT.pptx

  • 1.
  • 2.
    CONTENTS 1. What isAlgorithm? 2. Usage of Algorithm. 3. Example of Algorithm with flow chart diagram. 4. What is sorting? 5. One of sorting algorithm(Selection Sort)
  • 3.
    Previously… A program MUSTbe systematically and properly designed before coding begins. This design process results in the construction of an ALGORITHM
  • 4.
    An algorithm isa precise set of instructions that you follow to solve a problem or complete a task. We can say that algorithm is: ● A step‐by‐step problem‐solving procedure. ● A sequence of instruction that tell how to solve a particular problem. ● A set of instruction for solving a problem, especially on a computer. ● A computable set of steps to achieve a desired result. However, most agree that algorithm has something to do with defining generalized processes to get “output” from the “input”. What is an Algorithm?
  • 5.
    Recipes When you followa recipe, you follow instructions to complete a task. The instructions are a step-by-step procedure that need to be followed for your recipe to be successful.
  • 6.
    From Algorithm toProgram ● Both are sets of instructions on how to do a task; ● Algorithm: ○ talking to humans, easy to understand ○ in plain (English) language ● Program: ○ talking to computer (compiler) ○ can be regarded as a “formal expression” of an algorithm
  • 7.
    From Algorithm toProgram PROGRAM ALGORITHM a sequence of instructions describing how to do a task (or process) a set of instructions which are commands to computers to perform specific operations on data
  • 8.
    Algorithms in Technology Youuse an algorithm to tell a computer what to do. Everything you can do on a computer is able to happen because an algorithm has been written for it. Clicking a mouse, opening a word document and playing a game are all examples of things that have algorithms. Digital devices all follow algorithms in order for them to work.
  • 9.
    Flowchart Symbol andDescription Name Symbol Description Lozenge Indicates the starting or ending of flowchart (start / stop : terminal ) Connector Used to connect break in the flowchart Parallelelogram Use for input and output operation (data) Rectangle Indicates any interval operation (process) Diamond Use for asking questions that can have either TRUE of FALSE / YES or NO (decision / selection) Module Sub solution to solve a part of entire problem Control flow Shows flow direction
  • 10.
    Flowchart Example Design analgorithm to find the area of a rectangle The formulas: area = length * width Input Process Output Input variable: length width Processing item: area Formula: area = length x width Step / Solution algorithm: get input calculate area display output Output: area Start length, width calculate area area End
  • 11.
    Pseudo Code Example Start Readlength Read width Calculate area of a rectangle Display area of a rectangle End Design an algorithm to find the area of a rectangle The formulas: area = length * width Input Process Output Input variable: length width Processing item: area Formula: area = length x width Step / Solution algorithm: get input calculate area display output Output: area Start Prompt the user to enter a length of a rectangle Prompt the user to enter a width of a rectangle Calculate the area of a rectangle Display the area of a rectangle End Start Input length Input width Calculate area of a rectangle Output area of a rectangle End OR OR
  • 12.
  • 13.
    Sorting ● Sorting meansarranging the elements of an array so that they are placed in some relevant order which may be either ascending or descending. ● Can be used as a first step for searching the data. ● That is, if A is an array, then the elements of A are arranged in a sorted order (ascending order) in such a way that A[0] < A[1] < A[2] < … < A[N]. ● The practical considerations for different sorting techniques would be: ○ Number of sort key comparisons that will be performed. ○ Number of times the records in the list will be moved. ○ Best, average and worst case performance. ○ Stability of the sorting algorithm where stability means that equivalent elements or records retain their relative positions even after sorting is
  • 14.
    Bubble Sort Selection SortInsertion Sort Types of sorting Quick Sort Merge Sort
  • 15.
    • Selection sortis one of the easiest approaches to sorting. • It is inspired from the way in which we sort things out in day to day life. • It is an in-place sorting algorithm because it uses no auxiliary data structures while sorting. Selection Sort
  • 17.
  • 18.
    Selection Sort ● Supposethe name of the array is A and it has four elements with the following values: 4 19 1 3  To sort this array in ascending order, n-1, i.e. three iterations will be required.
  • 19.
    Selection Sort ● Iteration-1 Thearray is scanned starting from the first to the last element and the element that has the smallest value is selected. The smallest value is 1 at location 3. The address of element that has the smallest value is noted and the selected value is interchanged with the first element i.e. A[1] and A[3] are swapped 4 19 1 3 1 19 4 3
  • 20.
    Selection Sort ● Iteration-2 Thearray is scanned starting from the second to the last element and the element that has the smallest value is selected. The smallest value is 3 at location 4. The address of element that has the smallest value is noted. The selected value is interchanged with the second element i.e. A[2] and A[4] are swapped 1 19 4 3 1 3 4 19
  • 21.
    Selection Sort ● Iteration-3 Thearray is scanned starting from the third to the last element and the element that has the smallest value is selected. The smallest value is 4 at location 3. The address of element that has the smallest value is noted. The selected value is interchanged with the third element i.e. A[3] and A[3] are swapped 1 3 4 19 1 3 4 19
  • 22.
  • 23.
    Thank You Presented ByAung Myint Tun
  • 24.
    Do You HaveAny Question!