SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Discrete Mathematics And it’s Applications
Algorithms
Group # 01
BSIT-3rd –B-Morning
Members
 Muhammad Waqar Munir
 Rehan Ali
 Farooq Shah
 Jahanzaib Shahid
 Muhammad Hammad
Algorithms Methodology:
 Construct a model that translates the
problem into a mathematical context
 Build a method that will solve the
general problem using the model
 Ideally, we need a procedure that
follows a sequence of steps that leads
to the desired answer, such a
sequence is called an Algorithm.
History:
The term Algorithm is a corruption of the
name Al-Khowarizmi (mathematician of the
9th century)
Algorithms
 What is an algorithms?
An Algorithm is a finite set of precise instructions for performing a
computation or for solving a problem.
• Finding the Maximum Element in a Finite
Sequence
procedure max(a1, a2, . . . , an: integers)
max := a1
for i := 2 to n
if max < ai then max := ai
return max{max is the largest element}
Properties of algorithms:
 Inputfrom a specified set.
 Outputfrom a specified set (solution)
 Correctness of output for every possible input.
 Definiteness of evert step in the computation
 Effectiveness of each calculation step and
 Generality for a class of problems.
Searching Algorithms
 The problem of locating an element in an ordered list occurs in
many contexts. For instance, a
 program that checks the spelling of words searches for them in a
dictionary, which is just an
 ordered list of words. Problems of this kind are called searching
problems.
THE LINEAR SEARCH
The first algorithm that we will present is called the linear search,
or sequential search, algorithm.
• ALGORITHM For The Linear Search
procedure linear search(x: integer, a1, a2, . . . , an: distinct
integers)
i := 1
while (i ≤ n and x = ai )
i := i + 1
if i ≤ n then location := i
else location := 0
return location{location is the subscript of the term that equals
x, or is 0 if x is not found}
THE BINARY SEARCH
Some Instructions:
• if the
terms are numbers, they are listed from smallest to largest
• if they are words, they are listed
in lexicographic, or alphabetic, order
can be used when the list has terms occurring in order of
increasing size.
Binary Search
 May only b used on a sorted array.
 Eliminates one half of the elements after each comparison.
 Locate the middle of the array.
 Compare the value at that location with the search key.
 If they are equal-done.
 Otherwise, decide which half of the array contains the search key.
 Repeat the search on that half of the array and ignore the other half.
 The search continues until the key is matched or no elements remain to be
sorted.
• ALGORITHM For The Binary Search
procedure binary search (x: integer, a1, a2, . . . , an:
increasing integers)
i := 1{i is left endpoint of search interval}
j := n {j is right endpoint of search interval}
while i < j
m := (i + j)/2
if x > am then i := m + 1
else j := m
if x = ai then location := i
else location := 0
return location{location is the subscript i of the term ai
equal to x, or 0 if x is not found}
Sorting
 Goal
“Ordering the elements”
for example, sorting the list 7,2,1,4,5,9
produces the list 1,2,4,5,7,9.
Similarly, sorting of list d, h, c, a, f
produces a, c, d, f, h.
BUBBLE SORT
The bubble sort is one of the simplest
sorting algorithms, but not one of the most
efficient. It puts a list into increasing order by
successively comparing adjacent elements,
interchanging them if they are in the wrong
order.
The Bubble Sort algorithm looks at the pairs of entries in the
array, and swaps their order if needed.
Algorithms
• ALGORITHM For The Bubble Sort
procedure bubble sort(a1, . . . , an : real numbers with n ≥ 2)
for i := 1 to n − 1
for j := 1 to n − i
if aj > aj+1 then interchange aj and aj+1
{a1, . . . , an is in increasing order}
INSERTION SORT
• The insertion sort is a simple sorting
algorithm, but it is usually not the most
efficient.
• To sort a list with n elements,
• insertion sort begins with the second
element.
• ALGORITHM For Insertion Sort
procedure insertion sort(a1, a2, . . . , an:
real numbers with n ≥ 2)
for j := 2 to n
i := 1
while aj > ai
i := i + 1
m := aj
for k := 0 to j − i − 1
aj−k := aj−k−1
ai := m
{a1, . . . , an is in increasing order}
Greedy Algorithms
• to find a solution to the given problem that either
minimizes or maximizes the value of some
parameter
• one of the simplest approaches often leads to a
solution of an optimization Problem.
Algorithms that make what seems to be the “best” choice at each
step are called greedy algorithms.
• ALGORITHM For Greedy Change-
Making Algorithm
procedure change(c1, c2, . . . , cr : values
of denominations of coins, where
c1 > c2 > ・ ・ ・ > cr ; n: a positive
integer)
for i := 1 to r
di := 0 {di counts the coins of denomination
ci used}
while n ≥ ci
di := di + 1 {add a coin of denomination ci}
n := n − ci
{di is the number of coins of denomination
ci in the change for i = 1, 2, . . . , r}
TheHaltingProblem
• these are unsolvable problems, called halting
problem.
• a problem that cannot be solved using any
procedure.
• We will describe Turing’s proof that the halting
problem is unsolvable.
Algorithms
Algorithms

More Related Content

What's hot (20)

PPT
Context free grammars
Ronak Thakkar
 
PPT
Finite automata
Bipul Roy Bpl
 
PPT
Normalisation - 2nd normal form
college
 
PPTX
Selection sort algorithm presentation, selection sort example using power point
University of Science and Technology Chitttagong
 
PPTX
Relational Algebra,Types of join
raj upadhyay
 
PPTX
Algorithm analysis (All in one)
jehan1987
 
PPT
chapter 1
yatheesha
 
PPT
Chapter 3 2
Ch Farhan
 
PPTX
Array
Anil Neupane
 
PDF
Array data structure
maamir farooq
 
PPT
Binary Search
kunj desai
 
PPTX
Types of Tree in Data Structure in C++
Himanshu Choudhary
 
PPTX
ER diagram powerpoint
Steffi Libarios
 
PDF
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
PDF
Python list
Mohammed Sikander
 
PPT
1.1 binary tree
Krish_ver2
 
PPTX
Data structures and algorithms
Julie Iskander
 
PPTX
Find Transitive Closure Using Floyd-Warshall Algorithm
Rajib Roy
 
PPTX
Aggregate function
Rayhan Chowdhury
 
PPTX
Unit 1 polynomial manipulation
LavanyaJ28
 
Context free grammars
Ronak Thakkar
 
Finite automata
Bipul Roy Bpl
 
Normalisation - 2nd normal form
college
 
Selection sort algorithm presentation, selection sort example using power point
University of Science and Technology Chitttagong
 
Relational Algebra,Types of join
raj upadhyay
 
Algorithm analysis (All in one)
jehan1987
 
chapter 1
yatheesha
 
Chapter 3 2
Ch Farhan
 
Array data structure
maamir farooq
 
Binary Search
kunj desai
 
Types of Tree in Data Structure in C++
Himanshu Choudhary
 
ER diagram powerpoint
Steffi Libarios
 
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Python list
Mohammed Sikander
 
1.1 binary tree
Krish_ver2
 
Data structures and algorithms
Julie Iskander
 
Find Transitive Closure Using Floyd-Warshall Algorithm
Rajib Roy
 
Aggregate function
Rayhan Chowdhury
 
Unit 1 polynomial manipulation
LavanyaJ28
 

Similar to Algorithms (20)

PPTX
Lect-2.pptx
mrizwan38
 
PPT
21-algorithms.ppt
ashwinraiyani1
 
PPT
Algorithm, Pseudocode and Flowcharting in C++
Johnny Jean Tigas
 
PPT
21-algorithms (1).ppt
DaniloMislosAlbay
 
PPT
CHAP 3 ALGORITHM for infomatique ingenieure .ppt
FarahHarrathi1
 
PPTX
Chapter3.pptx
ASMAALWADEE2
 
PPT
Introduction to Algorithm for computer engineering students
geraldjamesignacio2
 
PPT
Introduction to Algorithm for computer engineering students
geraldjamesignacio2
 
PPTX
Dsa – data structure and algorithms sorting
sajinis3
 
PPTX
Searching and Sorting Algorithms in Data Structures
poongothai11
 
PPTX
Unit viii searching and hashing
Tribhuvan University
 
PDF
Ada notes
VIKAS SINGH BHADOURIA
 
PDF
Chapter 1 - Introduction to Searching and Sorting Algorithms - Student.pdf
mylinhbangus
 
PPTX
Binary search
AparnaKumari31
 
PDF
Algorithm chapter 1
chidabdu
 
PPTX
Lecture of algorithms and problem solving
menewratings009
 
PDF
Daa chapter5
B.Kirron Reddi
 
PPTX
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
Lect-2.pptx
mrizwan38
 
21-algorithms.ppt
ashwinraiyani1
 
Algorithm, Pseudocode and Flowcharting in C++
Johnny Jean Tigas
 
21-algorithms (1).ppt
DaniloMislosAlbay
 
CHAP 3 ALGORITHM for infomatique ingenieure .ppt
FarahHarrathi1
 
Chapter3.pptx
ASMAALWADEE2
 
Introduction to Algorithm for computer engineering students
geraldjamesignacio2
 
Introduction to Algorithm for computer engineering students
geraldjamesignacio2
 
Dsa – data structure and algorithms sorting
sajinis3
 
Searching and Sorting Algorithms in Data Structures
poongothai11
 
Unit viii searching and hashing
Tribhuvan University
 
Chapter 1 - Introduction to Searching and Sorting Algorithms - Student.pdf
mylinhbangus
 
Binary search
AparnaKumari31
 
Algorithm chapter 1
chidabdu
 
Lecture of algorithms and problem solving
menewratings009
 
Daa chapter5
B.Kirron Reddi
 
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
Ad

Recently uploaded (20)

PDF
Building scalbale cloud native apps with .NET 8
GillesMathieu10
 
PPTX
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
 
PPTX
Seamless-Image-Conversion-From-Raster-to-wrt-rtx-rtx.pptx
Quick Conversion Services
 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
PPTX
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
PPTX
declaration of Variables and constants.pptx
meemee7378
 
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
PDF
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
PPTX
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
PDF
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
 
PPTX
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
 
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
PDF
What Is an Internal Quality Audit and Why It Matters for Your QMS
BizPortals365
 
PDF
Cloud computing Lec 02 - virtualization.pdf
asokawennawatte
 
PDF
How DeepSeek Beats ChatGPT: Cost Comparison and Key Differences
sumitpurohit810
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
 
Building scalbale cloud native apps with .NET 8
GillesMathieu10
 
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
 
Seamless-Image-Conversion-From-Raster-to-wrt-rtx-rtx.pptx
Quick Conversion Services
 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
CONCEPT OF PROGRAMMING in language .pptx
tamim41
 
declaration of Variables and constants.pptx
meemee7378
 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
 
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
What Is an Internal Quality Audit and Why It Matters for Your QMS
BizPortals365
 
Cloud computing Lec 02 - virtualization.pdf
asokawennawatte
 
How DeepSeek Beats ChatGPT: Cost Comparison and Key Differences
sumitpurohit810
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
 
Ad

Algorithms

  • 1. Discrete Mathematics And it’s Applications Algorithms
  • 2. Group # 01 BSIT-3rd –B-Morning Members  Muhammad Waqar Munir  Rehan Ali  Farooq Shah  Jahanzaib Shahid  Muhammad Hammad
  • 3. Algorithms Methodology:  Construct a model that translates the problem into a mathematical context  Build a method that will solve the general problem using the model  Ideally, we need a procedure that follows a sequence of steps that leads to the desired answer, such a sequence is called an Algorithm. History: The term Algorithm is a corruption of the name Al-Khowarizmi (mathematician of the 9th century)
  • 4. Algorithms  What is an algorithms? An Algorithm is a finite set of precise instructions for performing a computation or for solving a problem.
  • 5. • Finding the Maximum Element in a Finite Sequence procedure max(a1, a2, . . . , an: integers) max := a1 for i := 2 to n if max < ai then max := ai return max{max is the largest element}
  • 6. Properties of algorithms:  Inputfrom a specified set.  Outputfrom a specified set (solution)  Correctness of output for every possible input.  Definiteness of evert step in the computation  Effectiveness of each calculation step and  Generality for a class of problems.
  • 7. Searching Algorithms  The problem of locating an element in an ordered list occurs in many contexts. For instance, a  program that checks the spelling of words searches for them in a dictionary, which is just an  ordered list of words. Problems of this kind are called searching problems.
  • 8. THE LINEAR SEARCH The first algorithm that we will present is called the linear search, or sequential search, algorithm. • ALGORITHM For The Linear Search procedure linear search(x: integer, a1, a2, . . . , an: distinct integers) i := 1 while (i ≤ n and x = ai ) i := i + 1 if i ≤ n then location := i else location := 0 return location{location is the subscript of the term that equals x, or is 0 if x is not found}
  • 9. THE BINARY SEARCH Some Instructions: • if the terms are numbers, they are listed from smallest to largest • if they are words, they are listed in lexicographic, or alphabetic, order can be used when the list has terms occurring in order of increasing size.
  • 10. Binary Search  May only b used on a sorted array.  Eliminates one half of the elements after each comparison.  Locate the middle of the array.  Compare the value at that location with the search key.  If they are equal-done.  Otherwise, decide which half of the array contains the search key.  Repeat the search on that half of the array and ignore the other half.  The search continues until the key is matched or no elements remain to be sorted.
  • 11. • ALGORITHM For The Binary Search procedure binary search (x: integer, a1, a2, . . . , an: increasing integers) i := 1{i is left endpoint of search interval} j := n {j is right endpoint of search interval} while i < j m := (i + j)/2 if x > am then i := m + 1 else j := m if x = ai then location := i else location := 0 return location{location is the subscript i of the term ai equal to x, or 0 if x is not found}
  • 12. Sorting  Goal “Ordering the elements” for example, sorting the list 7,2,1,4,5,9 produces the list 1,2,4,5,7,9. Similarly, sorting of list d, h, c, a, f produces a, c, d, f, h.
  • 13. BUBBLE SORT The bubble sort is one of the simplest sorting algorithms, but not one of the most efficient. It puts a list into increasing order by successively comparing adjacent elements, interchanging them if they are in the wrong order. The Bubble Sort algorithm looks at the pairs of entries in the array, and swaps their order if needed.
  • 15. • ALGORITHM For The Bubble Sort procedure bubble sort(a1, . . . , an : real numbers with n ≥ 2) for i := 1 to n − 1 for j := 1 to n − i if aj > aj+1 then interchange aj and aj+1 {a1, . . . , an is in increasing order}
  • 16. INSERTION SORT • The insertion sort is a simple sorting algorithm, but it is usually not the most efficient. • To sort a list with n elements, • insertion sort begins with the second element.
  • 17. • ALGORITHM For Insertion Sort procedure insertion sort(a1, a2, . . . , an: real numbers with n ≥ 2) for j := 2 to n i := 1 while aj > ai i := i + 1 m := aj for k := 0 to j − i − 1 aj−k := aj−k−1 ai := m {a1, . . . , an is in increasing order}
  • 18. Greedy Algorithms • to find a solution to the given problem that either minimizes or maximizes the value of some parameter • one of the simplest approaches often leads to a solution of an optimization Problem. Algorithms that make what seems to be the “best” choice at each step are called greedy algorithms.
  • 19. • ALGORITHM For Greedy Change- Making Algorithm procedure change(c1, c2, . . . , cr : values of denominations of coins, where c1 > c2 > ・ ・ ・ > cr ; n: a positive integer) for i := 1 to r di := 0 {di counts the coins of denomination ci used} while n ≥ ci di := di + 1 {add a coin of denomination ci} n := n − ci {di is the number of coins of denomination ci in the change for i = 1, 2, . . . , r}
  • 20. TheHaltingProblem • these are unsolvable problems, called halting problem. • a problem that cannot be solved using any procedure. • We will describe Turing’s proof that the halting problem is unsolvable.