SlideShare a Scribd company logo
1 of 15
Analysis of Algorithms
                         Big-Oh




                         Courtesy : Dale Roberts
Asymptotic Analysis

    Ignoring constants in T(n)
    Analyzing T(n) as n "gets large"
     Example:
                    T (n) = 13n + 42n + 2n log n + 4n
                                   3        2


As n grows larger, n3 is MUCH larger than n2 , n log n, and n,
so it dominates T (n)

The running time grows "roughly on the order of n3 "
Notationally, T(n) = O(n3 )     The big-oh (O) Notation




                                                Courtesy : Dale Roberts
3 major notations
Ο(g(n)), Big-Oh of g of n, the Asymptotic Upper
Bound.
Ω (g(n)), Big-Omega of g of n, the Asymptotic
Lower Bound.
Θ (g(n)), Big-Theta of g of n, the Asymptotic
Tight Bound.




                               Courtesy : Dale Roberts
Big-Oh Defined
   The O symbol was introduced in 1927 to indicate relative growth of
    two functions based on asymptotic behavior of the functions now us
    ed to classify functions and families of functions

T(n) = O(f(n)) if there are constants c and n0 such that T(n) < c*f(n)
   when n ≥ n0



                                                         c*f(n)
      c*f(n) is an upper bound for T(n)
                                                          T(n)




                                  n0                       n
                                                Courtesy : Dale Roberts
Big-Oh
Describes an upper bound for the running
time of an algorithm

Upper bounds for Insertion Sort running times:
 •worst case:    O(n2)        T(n) = c1*n2 + c2*n + c3
 •best case:     O(n)         T(n) = c1*n + c2


                Time Complexity




                                     Courtesy : Dale Roberts
Big-O Notation
We say Insertion Sort’s run time is O(n2)
  Properly we should say run time is in O(n2)
  Read O as “Big-Oh” (you’ll also hear it as “order”)
In general a function
  f(n) is O(g(n)) if there exist positive constants c and n0
  such that f(n) ≤ c ⋅ g(n) for all n ≥ n0
e.g. if f(n)=1000n and g(n)=n2, n0 = 1000 and c =
1 then f(n) < 1*g(n) where n > n0 and we say that
f(n) = O(g(n))
The O notation indicates 'bounded above by a
constant multiple of.'
                                         Courtesy : Dale Roberts
Big-Oh Properties
Fastest growing function dominates a sum
  O(f(n)+g(n)) is O(max{f(n), g(n)})
Product of upper bounds is upper bound for the product
  If f is O(g) and h is O(r) then fh is O(gr)
f is O(g) is transitive
    If f is O(g) and g is O(h) then f is O(h)
Hierarchy of functions
    O(1), O(logn), O(n1/2), O(nlogn), O(n2), O(2n), O(n!)




                                          Courtesy : Dale Roberts
Some Big-Oh’s are not reasonable
Polynomial Time algorithms
  An algorithm is said to be polynomial if it is
  O( nc ), c >1
  Polynomial algorithms are said to be reasonable
     They solve problems in reasonable times!
     Coefficients, constants or low-order terms are ignored
     e.g. if f(n) = 2n2 then f(n) = O(n2)



Exponential Time algorithms
  An algorithm is said to be exponential if it is
  O( rn ), r > 1
  Exponential algorithms are said to be unreasonable

                                             Courtesy : Dale Roberts
Can we justify Big O notation?
Big O notation is a huge simplification; can we
justify it?
    It only makes sense for large problem sizes
    For sufficiently large problem sizes, the
    highest-order term swamps all the rest!
Consider R = x 2 + 3x + 5 as x varies:
x   =   0      x2   =   0         3x   =   10     5   =   5   R   =   5
x   =   10     x2   =   100       3x   =   30     5   =   5   R   =   135
x   =   100    x2   =   10000     3x   =   300    5   =   5   R   =   10,305
x   =   1000 x2     =   1000000   3x   =   3000   5   =   5   R   =   1,003,005
x   =   10,000                                                R   =   100,030,005
x   =   100,000                                               R   =   10,000,300,005




                                                              Courtesy : Dale Roberts
Classifying Algorithms based on Big-Oh
A function f(n) is said to be of at most logarithmic growth if f(n) =
O(log n)
A function f(n) is said to be of at most quadratic growth if f(n) =
O(n2)
A function f(n) is said to be of at most polynomial growth if f(n) =
O(nk), for some natural number k > 1
A function f(n) is said to be of at most exponential growth if there is
a constant c, such that f(n) = O(cn), and c > 1
A function f(n) is said to be of at most factorial growth if f(n) = O(n!).
A function f(n) is said to have constant running time if the size of
the input n has no effect on the running time of the algorithm (e.g.,
assignment of a value to a variable). The equation for this algorithm
is f(n) = c
Other logarithmic classifications: f(n) = O(n log n)
                                     f(n) = O(log log n)




                                                Courtesy : Dale Roberts
Rules for Calculating Big-Oh
Base of Logs ignored
 logan = O(logbn)
Power inside logs ignored
 log(n2) = O(log n)
Base and powers in exponents not ignored
 3n is not O(2n)
    2

 a(n ) is not O(an)
If T(x) is a polynomial of degree n, then T(x) =
 O(xn)
                                Courtesy : Dale Roberts
Big-Oh Examples
2n3 + 3n2 + n =
              =   2n3 + 3n2   + O(n)
              =   2n3 + O(    n2 + n)
              =   2n3 + O(    n2 )
              =   O(n3 ) =    O(n4)




                              Courtesy : Dale Roberts
Big-Oh Examples (cont.)
3. Suppose a program P is O(n3), and a program Q
  is O(3n), and that currently both can solve proble
  ms of size 50 in 1 hour. If the programs are run o
  n another system that executes exactly 729 time
  s as fast as the original system, what size proble
  ms will they be able to solve in one hour?




                                  Courtesy : Dale Roberts
Big-Oh Examples (cont)
n3 = 503 ∗ 729                3n = 350 ∗ 729
n = 3 503 * 3 729             n = log3 (729 ∗ 350)
                              n = log3(729) + log3 350
n = 50 ∗ 9                    n = 6 + log3 350
n = 50 ∗ 9 = 450              n = 6 + 50 = 56


  Improvement: problem size increased by 9 times for n3
  algorithm but only a slight improvement in problem
  size (+6) for exponential algorithm.




                                      Courtesy : Dale Roberts
Acknowledgements
Philadephia University, Jordan
Nilagupta, Pradondet




                                 Courtesy : Dale Roberts

More Related Content

What's hot

R. Jimenez - Fundamental Physics from Astronomical Observations
R. Jimenez - Fundamental Physics from Astronomical ObservationsR. Jimenez - Fundamental Physics from Astronomical Observations
R. Jimenez - Fundamental Physics from Astronomical ObservationsSEENET-MTP
 
Lesson 26: The Fundamental Theorem of Calculus (slides)
Lesson 26: The Fundamental Theorem of Calculus (slides)Lesson 26: The Fundamental Theorem of Calculus (slides)
Lesson 26: The Fundamental Theorem of Calculus (slides)Matthew Leingang
 
7 6 the inverse trig functions
7 6 the inverse trig functions7 6 the inverse trig functions
7 6 the inverse trig functionshisema01
 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theoremRajendran
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsMamta Pandey
 
Lec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesLec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesAnkita Karia
 
A Note on Latent LSTM Allocation
A Note on Latent LSTM AllocationA Note on Latent LSTM Allocation
A Note on Latent LSTM AllocationTomonari Masada
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)ijceronline
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Lesson 32: The Fundamental Theorem Of Calculus
Lesson 32: The Fundamental Theorem Of CalculusLesson 32: The Fundamental Theorem Of Calculus
Lesson 32: The Fundamental Theorem Of CalculusMatthew Leingang
 

What's hot (20)

S 7
S 7S 7
S 7
 
R. Jimenez - Fundamental Physics from Astronomical Observations
R. Jimenez - Fundamental Physics from Astronomical ObservationsR. Jimenez - Fundamental Physics from Astronomical Observations
R. Jimenez - Fundamental Physics from Astronomical Observations
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Lesson 26: The Fundamental Theorem of Calculus (slides)
Lesson 26: The Fundamental Theorem of Calculus (slides)Lesson 26: The Fundamental Theorem of Calculus (slides)
Lesson 26: The Fundamental Theorem of Calculus (slides)
 
7 6 the inverse trig functions
7 6 the inverse trig functions7 6 the inverse trig functions
7 6 the inverse trig functions
 
Two Curves Upfront
Two Curves UpfrontTwo Curves Upfront
Two Curves Upfront
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Lec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesLec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrences
 
A Note on TopicRNN
A Note on TopicRNNA Note on TopicRNN
A Note on TopicRNN
 
A Note on Latent LSTM Allocation
A Note on Latent LSTM AllocationA Note on Latent LSTM Allocation
A Note on Latent LSTM Allocation
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)International Journal of Computational Engineering Research(IJCER)
International Journal of Computational Engineering Research(IJCER)
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Crystallographic groups
Crystallographic groupsCrystallographic groups
Crystallographic groups
 
Algorithum Analysis
Algorithum AnalysisAlgorithum Analysis
Algorithum Analysis
 
Lesson 32: The Fundamental Theorem Of Calculus
Lesson 32: The Fundamental Theorem Of CalculusLesson 32: The Fundamental Theorem Of Calculus
Lesson 32: The Fundamental Theorem Of Calculus
 
Rumus
RumusRumus
Rumus
 

Viewers also liked

Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms ISri Prasanna
 
Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notationMuthiah Abbhirami
 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notationirdginfo
 
QUESTION BANK FOR ANNA UNNIVERISTY SYLLABUS
QUESTION BANK FOR ANNA UNNIVERISTY SYLLABUSQUESTION BANK FOR ANNA UNNIVERISTY SYLLABUS
QUESTION BANK FOR ANNA UNNIVERISTY SYLLABUSJAMBIKA
 
Big o notation
Big o notationBig o notation
Big o notationkeb97
 

Viewers also liked (8)

Algo analysis
Algo analysisAlgo analysis
Algo analysis
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
 
Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notation
 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notation
 
QUESTION BANK FOR ANNA UNNIVERISTY SYLLABUS
QUESTION BANK FOR ANNA UNNIVERISTY SYLLABUSQUESTION BANK FOR ANNA UNNIVERISTY SYLLABUS
QUESTION BANK FOR ANNA UNNIVERISTY SYLLABUS
 
Algorithm big o
Algorithm big oAlgorithm big o
Algorithm big o
 
Big o notation
Big o notationBig o notation
Big o notation
 
Gephi Toolkit Tutorial
Gephi Toolkit TutorialGephi Toolkit Tutorial
Gephi Toolkit Tutorial
 

Similar to Analysis of algo

Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfAmayJaiswal4
 
CMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of FunctionsCMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of Functionsallyn joy calcaben
 
Class 18: Measuring Cost
Class 18: Measuring CostClass 18: Measuring Cost
Class 18: Measuring CostDavid Evans
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..KarthikeyaLanka1
 
A note on arithmetic progressions in sets of integers
A note on arithmetic progressions in sets of integersA note on arithmetic progressions in sets of integers
A note on arithmetic progressions in sets of integersLukas Nabergall
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptxpallavidhade2
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Dr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistDr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistGatewayggg Testeru
 
Skiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationSkiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationzukun
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notationsajinis3
 
lecture 1
lecture 1lecture 1
lecture 1sajinsc
 
04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptxarslanzaheer14
 
Weekends with Competitive Programming
Weekends with Competitive ProgrammingWeekends with Competitive Programming
Weekends with Competitive ProgrammingNiharikaSingh839269
 
Lecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptLecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptZohairMughal1
 

Similar to Analysis of algo (20)

Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
big_oh
big_ohbig_oh
big_oh
 
CMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of FunctionsCMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of Functions
 
Class 18: Measuring Cost
Class 18: Measuring CostClass 18: Measuring Cost
Class 18: Measuring Cost
 
algorithm_analysis1
algorithm_analysis1algorithm_analysis1
algorithm_analysis1
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
 
Big o
Big oBig o
Big o
 
A note on arithmetic progressions in sets of integers
A note on arithmetic progressions in sets of integersA note on arithmetic progressions in sets of integers
A note on arithmetic progressions in sets of integers
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Dr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistDr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabist
 
Skiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationSkiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notation
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
lecture 1
lecture 1lecture 1
lecture 1
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 3
Unit 3Unit 3
Unit 3
 
04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx
 
Weekends with Competitive Programming
Weekends with Competitive ProgrammingWeekends with Competitive Programming
Weekends with Competitive Programming
 
Lecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptLecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).ppt
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Analysis of algo

  • 1. Analysis of Algorithms Big-Oh Courtesy : Dale Roberts
  • 2. Asymptotic Analysis Ignoring constants in T(n) Analyzing T(n) as n "gets large" Example: T (n) = 13n + 42n + 2n log n + 4n 3 2 As n grows larger, n3 is MUCH larger than n2 , n log n, and n, so it dominates T (n) The running time grows "roughly on the order of n3 " Notationally, T(n) = O(n3 ) The big-oh (O) Notation Courtesy : Dale Roberts
  • 3. 3 major notations Ο(g(n)), Big-Oh of g of n, the Asymptotic Upper Bound. Ω (g(n)), Big-Omega of g of n, the Asymptotic Lower Bound. Θ (g(n)), Big-Theta of g of n, the Asymptotic Tight Bound. Courtesy : Dale Roberts
  • 4. Big-Oh Defined  The O symbol was introduced in 1927 to indicate relative growth of two functions based on asymptotic behavior of the functions now us ed to classify functions and families of functions T(n) = O(f(n)) if there are constants c and n0 such that T(n) < c*f(n) when n ≥ n0 c*f(n) c*f(n) is an upper bound for T(n) T(n) n0 n Courtesy : Dale Roberts
  • 5. Big-Oh Describes an upper bound for the running time of an algorithm Upper bounds for Insertion Sort running times: •worst case: O(n2) T(n) = c1*n2 + c2*n + c3 •best case: O(n) T(n) = c1*n + c2 Time Complexity Courtesy : Dale Roberts
  • 6. Big-O Notation We say Insertion Sort’s run time is O(n2) Properly we should say run time is in O(n2) Read O as “Big-Oh” (you’ll also hear it as “order”) In general a function f(n) is O(g(n)) if there exist positive constants c and n0 such that f(n) ≤ c ⋅ g(n) for all n ≥ n0 e.g. if f(n)=1000n and g(n)=n2, n0 = 1000 and c = 1 then f(n) < 1*g(n) where n > n0 and we say that f(n) = O(g(n)) The O notation indicates 'bounded above by a constant multiple of.' Courtesy : Dale Roberts
  • 7. Big-Oh Properties Fastest growing function dominates a sum O(f(n)+g(n)) is O(max{f(n), g(n)}) Product of upper bounds is upper bound for the product If f is O(g) and h is O(r) then fh is O(gr) f is O(g) is transitive If f is O(g) and g is O(h) then f is O(h) Hierarchy of functions O(1), O(logn), O(n1/2), O(nlogn), O(n2), O(2n), O(n!) Courtesy : Dale Roberts
  • 8. Some Big-Oh’s are not reasonable Polynomial Time algorithms An algorithm is said to be polynomial if it is O( nc ), c >1 Polynomial algorithms are said to be reasonable They solve problems in reasonable times! Coefficients, constants or low-order terms are ignored e.g. if f(n) = 2n2 then f(n) = O(n2) Exponential Time algorithms An algorithm is said to be exponential if it is O( rn ), r > 1 Exponential algorithms are said to be unreasonable Courtesy : Dale Roberts
  • 9. Can we justify Big O notation? Big O notation is a huge simplification; can we justify it? It only makes sense for large problem sizes For sufficiently large problem sizes, the highest-order term swamps all the rest! Consider R = x 2 + 3x + 5 as x varies: x = 0 x2 = 0 3x = 10 5 = 5 R = 5 x = 10 x2 = 100 3x = 30 5 = 5 R = 135 x = 100 x2 = 10000 3x = 300 5 = 5 R = 10,305 x = 1000 x2 = 1000000 3x = 3000 5 = 5 R = 1,003,005 x = 10,000 R = 100,030,005 x = 100,000 R = 10,000,300,005 Courtesy : Dale Roberts
  • 10. Classifying Algorithms based on Big-Oh A function f(n) is said to be of at most logarithmic growth if f(n) = O(log n) A function f(n) is said to be of at most quadratic growth if f(n) = O(n2) A function f(n) is said to be of at most polynomial growth if f(n) = O(nk), for some natural number k > 1 A function f(n) is said to be of at most exponential growth if there is a constant c, such that f(n) = O(cn), and c > 1 A function f(n) is said to be of at most factorial growth if f(n) = O(n!). A function f(n) is said to have constant running time if the size of the input n has no effect on the running time of the algorithm (e.g., assignment of a value to a variable). The equation for this algorithm is f(n) = c Other logarithmic classifications: f(n) = O(n log n) f(n) = O(log log n) Courtesy : Dale Roberts
  • 11. Rules for Calculating Big-Oh Base of Logs ignored logan = O(logbn) Power inside logs ignored log(n2) = O(log n) Base and powers in exponents not ignored 3n is not O(2n) 2 a(n ) is not O(an) If T(x) is a polynomial of degree n, then T(x) = O(xn) Courtesy : Dale Roberts
  • 12. Big-Oh Examples 2n3 + 3n2 + n = = 2n3 + 3n2 + O(n) = 2n3 + O( n2 + n) = 2n3 + O( n2 ) = O(n3 ) = O(n4) Courtesy : Dale Roberts
  • 13. Big-Oh Examples (cont.) 3. Suppose a program P is O(n3), and a program Q is O(3n), and that currently both can solve proble ms of size 50 in 1 hour. If the programs are run o n another system that executes exactly 729 time s as fast as the original system, what size proble ms will they be able to solve in one hour? Courtesy : Dale Roberts
  • 14. Big-Oh Examples (cont) n3 = 503 ∗ 729 3n = 350 ∗ 729 n = 3 503 * 3 729 n = log3 (729 ∗ 350) n = log3(729) + log3 350 n = 50 ∗ 9 n = 6 + log3 350 n = 50 ∗ 9 = 450 n = 6 + 50 = 56 Improvement: problem size increased by 9 times for n3 algorithm but only a slight improvement in problem size (+6) for exponential algorithm. Courtesy : Dale Roberts