SlideShare a Scribd company logo
1 of 11
Download to read offline
Understanding Algorithm
and techniques in
programming at IDE level.
Author: Farrukh Ishaq
Algorithm
• An algorithm (pronounced AL-go-rith-um) is a procedure or formula
for solving a problem, based on conducting a sequence of specified
actions.
• An algorithm has a statement which are lead from an input of a
problem to an output as a solution
• The word algorithm derives from the name of the mathematician,
Mohammed ibn-Musa al-Khwarizmi, who was part of the royal court
in Baghdad and who lived from about 780 to 850.
Some Sorting Algorithm
• Bubble Sort
• Merge Sort
• Insert Sort
• Quick Sort
• Selection Sort
5 44 17 22 2 18 54 84
int[] list;
5 44 17 22 2 18 54 84
0 1 2 3 4 5 6 7
Index [] list
Bubble Sort 5 44 17 22 2 18 54 84
int[] list;
5 44 17 22 2 18 54 84
0 1 2 3 4 5 6 7
Index [] list
Sort starts
from left.
int[] list;
Left element
>
Right element
Swap
END
Use Right
element as
Left
TRUE
Ascending
Order int[] list;
FALSE LOOP
Right
Element <
Left
Element;
Return;
Else
IF
5 44 17 22 2 18 54 84
5 44 17 22 2 18 54 84
44 > 17 then Swap
5 4417 22 2 18 54 84
2 175 18 22 44 54 84
Return list[];
BigO(n^2)
Middle = List[]/2
Left=Middle
Right = L-length.ist
Merge Sort 5 44 17 22 2 18 54 84
5 44 17 22 2 18 54 84
0 1 2 3 4 5 6 7
5 44 17 22 2 18 54 84
5 44 17 22 2 18 54 84
5 > 44 then Swap
2 175 18 22 44 54 84
Return list[];
5 2217 44 2 18 54 84
2 5 17 18 22 44 54 84
Index [] list
Sort starts
from left.
int[] list;
Right[]
END
L.Left
element >
R.Right
TRUE
swap
Ascending
Order int[] list;
FALSE
Left[] || Right[]; Return;
Else
IF
Left[]
BigO(n log n)
Divide and conquer
BigO Notation Table
f(n) Name
1 Constant
Log n Logarithmic
N Linear
N log n Log Linear
N2 Quadratic
N3 Cubic
2n Exponential
BigO
• BigO will provide an explanation about the procedure which has been or which
will be required to complete a certain task.
• BigO is a notation used for programmer to analyses an Algorithm. The statement
which is used to describe BigO is as follow.
Brute Force
• It is a programming technique which means trying all the probabilities
which an algorithm may offer.
• An example is a PADLOCK which has a set of numbers to unlock the
chain, if a user doesn’t know the right code it has to loop all the
probabilities.
SWITCH
Case 1:
Case 2:
Break
switch(expression)
{ case value : //
Statements break; //
optional case value : //
Statements break; //
optional // You can have any number of case statements.
default : //
Optional //
Statements }
Some Search Algorithm
• Linear Search
• Binary Search
• Interpolation
Search
• Hash Table
5 44 17 22 2 18 54 84
int[] list;
5 44 17 22 2 18 54 84
0 1 2 3 4 5 6 7
Index [] list
Binary Search BigO(log n)
Divide and conquer
Middle = List[]/2
Left=Middle
Right = L-length.ist
5 44 17 22 2 18 54 84
5 44 17 22 2 18 54 84
0 1 2 3 4 5 6 7
2 175 18 22 44 54 84Merge Sort Return.
Index [] list
Sort starts
from left.
int[] list;
END
L.Left
element >
R.Right
TRUE
swap
Ascending
Order int[] list;
FALSE
Left[] || Right[]; Return;
Else
IF
Search
# 22
Transform and conquer
List[]/2
Left[] Right[]
Found
#
Return
index
2 175 18 22 44 54 84
Lower-bond upper-bond
22
Index [] list
0 1 2 3 4 5 6 7
Found at 5th position
Test Your Self
What is the worst-case complexity of the each of the following code fragments?
1.Two loops in a row:
for (i = 0; i < N; i++) { sequence of statements } // loop n
for (j = 0; j < M; j++) { sequence of statements } // loop m
How would the complexity change if the second loop went to N instead of M?
2.A nested loop followed by a non-nested loop:
for (i = 0; i < N; i++) // loop n
{
for (j = 0; j < N; j++) { sequence of statements } // loop n (NESTED LOOP)
}
for (k = 0; k < N; k++) { sequence of statements } // loop m
BigO(n+m)
BigO(n^2+m)

More Related Content

What's hot

What's hot (19)

Day 1 Chapter 1 Unit 1
Day 1 Chapter 1 Unit 1Day 1 Chapter 1 Unit 1
Day 1 Chapter 1 Unit 1
 
Applications of Stack
Applications of StackApplications of Stack
Applications of Stack
 
Bakery Algorithm
Bakery Algorithm Bakery Algorithm
Bakery Algorithm
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
 
COMPUTER PROGRAMMING UNIT 1 Lecture 4
COMPUTER PROGRAMMING UNIT 1 Lecture 4COMPUTER PROGRAMMING UNIT 1 Lecture 4
COMPUTER PROGRAMMING UNIT 1 Lecture 4
 
Algorithmic problem solving
Algorithmic problem solvingAlgorithmic problem solving
Algorithmic problem solving
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
 
Joins
JoinsJoins
Joins
 
COMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax AnalysisCOMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax Analysis
 
COMPILER DESIGN AND CONSTRUCTION
COMPILER DESIGN AND CONSTRUCTIONCOMPILER DESIGN AND CONSTRUCTION
COMPILER DESIGN AND CONSTRUCTION
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
 
Day 3 chapter 2 unit 1
Day 3 chapter 2 unit 1Day 3 chapter 2 unit 1
Day 3 chapter 2 unit 1
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Fundamental of Algorithms
Fundamental of Algorithms Fundamental of Algorithms
Fundamental of Algorithms
 
Assignment
AssignmentAssignment
Assignment
 
175035 cse lab-05
175035 cse lab-05 175035 cse lab-05
175035 cse lab-05
 
vhdl exp-5
vhdl exp-5vhdl exp-5
vhdl exp-5
 
C after correction
C after correctionC after correction
C after correction
 
Lecture8 syntax analysis_4
Lecture8 syntax analysis_4Lecture8 syntax analysis_4
Lecture8 syntax analysis_4
 

Similar to Learn about algorithm

(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting
Fadhil Ismail
 

Similar to Learn about algorithm (20)

Counting Sort
Counting SortCounting Sort
Counting Sort
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
 
14-sorting (3).ppt
14-sorting (3).ppt14-sorting (3).ppt
14-sorting (3).ppt
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
 
Quick sort
Quick sortQuick sort
Quick sort
 
Sorting
SortingSorting
Sorting
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
 
Algorithm By AMT.pptx
Algorithm By AMT.pptxAlgorithm By AMT.pptx
Algorithm By AMT.pptx
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
 
Quick sort
Quick sortQuick sort
Quick sort
 
Basic Sorting algorithms csharp
Basic Sorting algorithms csharpBasic Sorting algorithms csharp
Basic Sorting algorithms csharp
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Chapter 14 Searching and Sorting
Chapter 14 Searching and SortingChapter 14 Searching and Sorting
Chapter 14 Searching and Sorting
 
Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structure
 
Cis435 week01
Cis435 week01Cis435 week01
Cis435 week01
 
Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...
 
16-sorting.ppt
16-sorting.ppt16-sorting.ppt
16-sorting.ppt
 
Algorithms lecture 3
Algorithms lecture 3Algorithms lecture 3
Algorithms lecture 3
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting
 

Recently uploaded

Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Lisi Hocke
 

Recently uploaded (20)

Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
Encryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key ConceptsEncryption Recap: A Refresher on Key Concepts
Encryption Recap: A Refresher on Key Concepts
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 

Learn about algorithm

  • 1. Understanding Algorithm and techniques in programming at IDE level. Author: Farrukh Ishaq
  • 2. Algorithm • An algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem, based on conducting a sequence of specified actions. • An algorithm has a statement which are lead from an input of a problem to an output as a solution • The word algorithm derives from the name of the mathematician, Mohammed ibn-Musa al-Khwarizmi, who was part of the royal court in Baghdad and who lived from about 780 to 850.
  • 3. Some Sorting Algorithm • Bubble Sort • Merge Sort • Insert Sort • Quick Sort • Selection Sort 5 44 17 22 2 18 54 84 int[] list; 5 44 17 22 2 18 54 84 0 1 2 3 4 5 6 7 Index [] list
  • 4. Bubble Sort 5 44 17 22 2 18 54 84 int[] list; 5 44 17 22 2 18 54 84 0 1 2 3 4 5 6 7 Index [] list Sort starts from left. int[] list; Left element > Right element Swap END Use Right element as Left TRUE Ascending Order int[] list; FALSE LOOP Right Element < Left Element; Return; Else IF 5 44 17 22 2 18 54 84 5 44 17 22 2 18 54 84 44 > 17 then Swap 5 4417 22 2 18 54 84 2 175 18 22 44 54 84 Return list[]; BigO(n^2)
  • 5. Middle = List[]/2 Left=Middle Right = L-length.ist Merge Sort 5 44 17 22 2 18 54 84 5 44 17 22 2 18 54 84 0 1 2 3 4 5 6 7 5 44 17 22 2 18 54 84 5 44 17 22 2 18 54 84 5 > 44 then Swap 2 175 18 22 44 54 84 Return list[]; 5 2217 44 2 18 54 84 2 5 17 18 22 44 54 84 Index [] list Sort starts from left. int[] list; Right[] END L.Left element > R.Right TRUE swap Ascending Order int[] list; FALSE Left[] || Right[]; Return; Else IF Left[] BigO(n log n) Divide and conquer
  • 6. BigO Notation Table f(n) Name 1 Constant Log n Logarithmic N Linear N log n Log Linear N2 Quadratic N3 Cubic 2n Exponential
  • 7. BigO • BigO will provide an explanation about the procedure which has been or which will be required to complete a certain task. • BigO is a notation used for programmer to analyses an Algorithm. The statement which is used to describe BigO is as follow.
  • 8. Brute Force • It is a programming technique which means trying all the probabilities which an algorithm may offer. • An example is a PADLOCK which has a set of numbers to unlock the chain, if a user doesn’t know the right code it has to loop all the probabilities. SWITCH Case 1: Case 2: Break switch(expression) { case value : // Statements break; // optional case value : // Statements break; // optional // You can have any number of case statements. default : // Optional // Statements }
  • 9. Some Search Algorithm • Linear Search • Binary Search • Interpolation Search • Hash Table 5 44 17 22 2 18 54 84 int[] list; 5 44 17 22 2 18 54 84 0 1 2 3 4 5 6 7 Index [] list
  • 10. Binary Search BigO(log n) Divide and conquer Middle = List[]/2 Left=Middle Right = L-length.ist 5 44 17 22 2 18 54 84 5 44 17 22 2 18 54 84 0 1 2 3 4 5 6 7 2 175 18 22 44 54 84Merge Sort Return. Index [] list Sort starts from left. int[] list; END L.Left element > R.Right TRUE swap Ascending Order int[] list; FALSE Left[] || Right[]; Return; Else IF Search # 22 Transform and conquer List[]/2 Left[] Right[] Found # Return index 2 175 18 22 44 54 84 Lower-bond upper-bond 22 Index [] list 0 1 2 3 4 5 6 7 Found at 5th position
  • 11. Test Your Self What is the worst-case complexity of the each of the following code fragments? 1.Two loops in a row: for (i = 0; i < N; i++) { sequence of statements } // loop n for (j = 0; j < M; j++) { sequence of statements } // loop m How would the complexity change if the second loop went to N instead of M? 2.A nested loop followed by a non-nested loop: for (i = 0; i < N; i++) // loop n { for (j = 0; j < N; j++) { sequence of statements } // loop n (NESTED LOOP) } for (k = 0; k < N; k++) { sequence of statements } // loop m BigO(n+m) BigO(n^2+m)