SlideShare a Scribd company logo
1 of 34
Definition

Algorithm: Steps of problem solving
           well defined

Analysis:
1. Study Performance Characteristics of
   Algorithms: Time and Space
2. Know the existing ways of problem solving
3. Evaluate its suitability for a particular problem

                                                       1
Properties of Algorithm

Algorithm:


•   Precision
•   Determinism
•   Finiteness
•   Correctness
•   Generality

                                   2
Basics of Studying Algorithms

o Independent of Hardware
o Op. Systems, Compilers and Languages
o Independent of Data?
  • Badly chosen Starting Point, Initial Condition
     • Intelligent selection or well defined start
       state
  • Random Selection of an element
     • Repeat algorithm several times


                                                     3
Analysis

Complexity: Goal is to classify algorithms
 according to their performance characteristics:
 Time and Space

This can be done in two ways:
Method 1: Absolute Value

Space required: Bytes?
Time required: Seconds?
                                                   4
Computational Complexity

Second Method:
  Size of the problem represented by n

  Independent of machine, operating system,
  compiler and language used




                                              5
Space Complexity

How much Space required to execute an
  algorithm
  Unit Cost Model for memory representation
Begin
  Initialize n         variable n
  For i=0 to n         variable i
       Print i
  Next
End

                                              6
Space Complexity

Space no longer a problem

Many algorithms compromise space
 requirements since memory is cheap

Search Space grows out of bound!
  Swapping with secondary memory



                                      7
Time Complexity

Time required: Unit Cost Model for time

Begin
  Initialize n
  For i=0 to n
       Print i
  End For
End


                                          8
Time Complexity

Time required: Unit Cost Model for time

Begin                  labels do not cost anything
  Initialize n         1
  For i=0 to n         n+2
       Print i         n+1
  End For              label
End                    label
               Total   T(n) = 2n+4

                                                     9
Complexity

Asymptotic Complexity

• Ignore machine-dependent constants ---
  instead of the actual running time
• Look at the growth of the running time.




                                            10
Asymptotic Complexity

Example:
T(n) = 2n3
T(n) = 1000n2

Which one is better?

For large values of n or
  small values of n

                                  11
Asymptotic Complexity

We study algorithms for large values of n but that
 does not mean that we should forget that high
 complexity algorithms can execute faster if size
 of problem is small

We focus our analysis for large values of n
 where n → ∞




                                                     12
Kinds of Analysis
Worst-case: (usually)
• Max. time of algorithm on any input of size n.

Average-case: (sometimes)
• expected time over all inputs of size n.
• Need assumption of statistical distribution of
  inputs.

• Best-case: (bogus)
• Cheat with a slow algorithm that works fast on
  some input.
                                                   13
Analysis of Algorithms
Worst Case, Best Case, Average Case
 Example: Sorting
Which one to use?
      For Real Time Applications
 Data already sorted!
 Is it really the best case?




                                      14
Mathematical Notations
Big-O:           O (f(N) ) is bounded from above
                       at most!
Big-Omega:       Ω (f(N) ) is bounded from below
                       at least!
Little-o:        o (f(N) ) is bounded from above
                       smaller than!
Little-omega:    ω (f(N) ) is bounded from below
                       greater than!
Theta:           Θ (f(N) ) bounded, above & below
                       equal to!
                                               15
Big-O


• O-notation is an upper-bound notation.
• It makes no sense to say f(n) is at least
  O(n2).




                                              16
Complexity
Example:        T(n) = 2n+4

Dominant Term: As n gets large enough, the
 dominant term has a much larger effect on the
 running time of an algorithm

Example 2:
T(n) = 2n3 + 1000n2 + 100000



                                                 17
Dominant Term
Example 1:      T(n) = 2n+4
Example 2:      T(n) = 2n3 + 1000n2 + 100000

Remove negligible terms

Example 1:      n
Example 2:      n3




                                               18
Dominant Term & Big-O

Example 1:       n
Example 2:       n3

We say that the algorithm runs
     Ex1: in the Order of n = O(n)
     Ex2: in the Order of n3 = O(n3)

O(n) : The Time Complexity in the worst case,
  grows with the size of the problem

                                                19
Rules for using Big-O

•   For a single statement whose execution does
    not depend on n: O(1)
    Example:       i=0



•   For a sequence of statement, S1,S2,…,Sk
      T(S1)+T(S2)+…+T(Sk)

    Example:     i=0              O(1) +
                 print i          O(1)
                                                  20
Rules for using Big-O

•   Loop:   For i=0 to n
                  S1
                  S2
            End For

Dominent Term * No. of times loop executed

    Example:      For i=0 to n
                        j=j*8
                        j=j-1
                  End For                    21
Rules for using Big-O

•   Conditional Loop:    While i<0
                              S1
                              S2
                         End While
No fixed rule, find a bound on the number of
   iterations




                                               22
Rules for using Big-O

•   If condition C then
        S1
    else
        S2
    end if

T(C) + max (T(S1) , T(S2) )



                                    23
Rules for using Big-O

•   Nested Loop

    S1
    For i=0 to n
      For j=0 to m
             S2
      End For
    End For

As n → ∞, m → ∞
                                   24
Time Complexity

Begin
  Initialize n          1
  For i=0 to n          n+2
        For j=0 to m    (m+2)(n+2)
              Print i   (m+1)(n+1)
       End For
  End For
End
              Total     T(n) = 2mn + 3m + 4n + 8
                        O(n)=n^2
                                                   25
Constants?

Begin
  Initialize n
  For i=0 to n
       Print i
  End for
End
                          What are these?
T(n)= 2 n + 4

                                            26
Slope Intercept Form

T(n)= 2n+4
                18



 n T(n)         16


                14

 1    6         12



 2    8         10


                 8

 3 10            6


 4 12            4



 5 14
                 2


                 0


 6 16                1   2   3      4   5   6




                                                27
Slope Intercept Form

T(n)= 2n+4           C1n + C2
                     if n = 0 ?
 n T(n)              if C2= 0?
 1    6
 2    8
                18

 3 10           16
                14

 4 12           12
                10


 5 14            8
                 6


 6 16
                 4
                 2
                 0
                       1    2     3   4   5   6

                                                  28
Growth




         29
Growth




         30
Order notation –
         some useful comparisons

• O(1) < log n < n < n log n < n2 < n3 <
  2n < 3n < n! < nn




                                           31
Order notation –
        some useful comparisons
• Behavior of Growth for Log( number, base) is
  the same; Log2 n = Log3 n = Log10 n




                                                 32
Practical and
           Un-practical algorithms

• Algorithm is practical, if it’s time complexity is
  T(n) = O(na)          (polynomial)

• Algorithm is not practical otherwise
  T(nn) usually is exponential)




                                                       33
Example

• Assume that we have a record of 1000
  students. If we want to search a specific
  record, what is the time complexity?

• If ordered?
  Fastest Known Sorting Algorithm (n * log n)
       Quick Sort / Merge Sort
  Fastest Known Searching Algorithm (log n)
       Binary Search

                                                34

More Related Content

What's hot

Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexityAbbas Ali
 
asymptotic notations i
asymptotic notations iasymptotic notations i
asymptotic notations iAli mahmood
 
Basics & asymptotic notations
Basics & asymptotic notationsBasics & asymptotic notations
Basics & asymptotic notationsRajendran
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Quantifying the call blending balance in two way communication retrial queues...
Quantifying the call blending balance in two way communication retrial queues...Quantifying the call blending balance in two way communication retrial queues...
Quantifying the call blending balance in two way communication retrial queues...wrogiest
 
Analysis of algorithn class 3
Analysis of algorithn class 3Analysis of algorithn class 3
Analysis of algorithn class 3Kumar
 
Lec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesLec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesAnkita Karia
 
Nonlinear Stochastic Optimization by the Monte-Carlo Method
Nonlinear Stochastic Optimization by the Monte-Carlo MethodNonlinear Stochastic Optimization by the Monte-Carlo Method
Nonlinear Stochastic Optimization by the Monte-Carlo MethodSSA KPI
 

What's hot (20)

Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
 
asymptotic notations i
asymptotic notations iasymptotic notations i
asymptotic notations i
 
Lec10
Lec10Lec10
Lec10
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Basics & asymptotic notations
Basics & asymptotic notationsBasics & asymptotic notations
Basics & asymptotic notations
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexity
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Quantifying the call blending balance in two way communication retrial queues...
Quantifying the call blending balance in two way communication retrial queues...Quantifying the call blending balance in two way communication retrial queues...
Quantifying the call blending balance in two way communication retrial queues...
 
Analysis of algorithn class 3
Analysis of algorithn class 3Analysis of algorithn class 3
Analysis of algorithn class 3
 
Lec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesLec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrences
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Lec5
Lec5Lec5
Lec5
 
Algorithum Analysis
Algorithum AnalysisAlgorithum Analysis
Algorithum Analysis
 
Lec4
Lec4Lec4
Lec4
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Nonlinear Stochastic Optimization by the Monte-Carlo Method
Nonlinear Stochastic Optimization by the Monte-Carlo MethodNonlinear Stochastic Optimization by the Monte-Carlo Method
Nonlinear Stochastic Optimization by the Monte-Carlo Method
 

Viewers also liked

Viewers also liked (8)

Android
AndroidAndroid
Android
 
Mobile computing
Mobile computingMobile computing
Mobile computing
 
Android OS Presentation
Android OS PresentationAndroid OS Presentation
Android OS Presentation
 
My presentation on Android in my college
My presentation on Android in my collegeMy presentation on Android in my college
My presentation on Android in my college
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Mobile Computing
Mobile ComputingMobile Computing
Mobile Computing
 
Android seminar-presentation
Android seminar-presentationAndroid seminar-presentation
Android seminar-presentation
 
Android ppt
Android ppt Android ppt
Android ppt
 

Similar to Algo complexity

1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptxpallavidhade2
 
2 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart12 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart1SSE_AndyLi
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfAmayJaiswal4
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.Tariq Khan
 
l1.ppt
l1.pptl1.ppt
l1.pptImXaib
 
Welcome to Introduction to Algorithms, Spring 2004
Welcome to Introduction to Algorithms, Spring 2004Welcome to Introduction to Algorithms, Spring 2004
Welcome to Introduction to Algorithms, Spring 2004jeronimored
 
Introduction of Algorithm.pdf
Introduction of Algorithm.pdfIntroduction of Algorithm.pdf
Introduction of Algorithm.pdfLaxmiMobile1
 
Algorithms - Rocksolid Tour 2013
Algorithms  - Rocksolid Tour 2013Algorithms  - Rocksolid Tour 2013
Algorithms - Rocksolid Tour 2013Gary Short
 
Chapter One.pdf
Chapter One.pdfChapter One.pdf
Chapter One.pdfabay golla
 
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
 
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
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2chidabdu
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihmSajid Marwat
 
Skiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationSkiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationzukun
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsKrishnan MuthuManickam
 

Similar to Algo complexity (20)

1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
2 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart12 chapter2 algorithm_analysispart1
2 chapter2 algorithm_analysispart1
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
l1.ppt
l1.pptl1.ppt
l1.ppt
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
l1.ppt
l1.pptl1.ppt
l1.ppt
 
l1.ppt
l1.pptl1.ppt
l1.ppt
 
Welcome to Introduction to Algorithms, Spring 2004
Welcome to Introduction to Algorithms, Spring 2004Welcome to Introduction to Algorithms, Spring 2004
Welcome to Introduction to Algorithms, Spring 2004
 
Introduction of Algorithm.pdf
Introduction of Algorithm.pdfIntroduction of Algorithm.pdf
Introduction of Algorithm.pdf
 
Algorithms - Rocksolid Tour 2013
Algorithms  - Rocksolid Tour 2013Algorithms  - Rocksolid Tour 2013
Algorithms - Rocksolid Tour 2013
 
Chapter One.pdf
Chapter One.pdfChapter One.pdf
Chapter One.pdf
 
AsymptoticAnalysis.ppt
AsymptoticAnalysis.pptAsymptoticAnalysis.ppt
AsymptoticAnalysis.ppt
 
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
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
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
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
analysis.ppt
analysis.pptanalysis.ppt
analysis.ppt
 
Skiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationSkiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notation
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 

Recently uploaded

Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
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
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
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
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
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
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
“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
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
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
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
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
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
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 🔝✔️✔️
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
“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...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

Algo complexity

  • 1. Definition Algorithm: Steps of problem solving well defined Analysis: 1. Study Performance Characteristics of Algorithms: Time and Space 2. Know the existing ways of problem solving 3. Evaluate its suitability for a particular problem 1
  • 2. Properties of Algorithm Algorithm: • Precision • Determinism • Finiteness • Correctness • Generality 2
  • 3. Basics of Studying Algorithms o Independent of Hardware o Op. Systems, Compilers and Languages o Independent of Data? • Badly chosen Starting Point, Initial Condition • Intelligent selection or well defined start state • Random Selection of an element • Repeat algorithm several times 3
  • 4. Analysis Complexity: Goal is to classify algorithms according to their performance characteristics: Time and Space This can be done in two ways: Method 1: Absolute Value Space required: Bytes? Time required: Seconds? 4
  • 5. Computational Complexity Second Method: Size of the problem represented by n Independent of machine, operating system, compiler and language used 5
  • 6. Space Complexity How much Space required to execute an algorithm Unit Cost Model for memory representation Begin Initialize n variable n For i=0 to n variable i Print i Next End 6
  • 7. Space Complexity Space no longer a problem Many algorithms compromise space requirements since memory is cheap Search Space grows out of bound! Swapping with secondary memory 7
  • 8. Time Complexity Time required: Unit Cost Model for time Begin Initialize n For i=0 to n Print i End For End 8
  • 9. Time Complexity Time required: Unit Cost Model for time Begin labels do not cost anything Initialize n 1 For i=0 to n n+2 Print i n+1 End For label End label Total T(n) = 2n+4 9
  • 10. Complexity Asymptotic Complexity • Ignore machine-dependent constants --- instead of the actual running time • Look at the growth of the running time. 10
  • 11. Asymptotic Complexity Example: T(n) = 2n3 T(n) = 1000n2 Which one is better? For large values of n or small values of n 11
  • 12. Asymptotic Complexity We study algorithms for large values of n but that does not mean that we should forget that high complexity algorithms can execute faster if size of problem is small We focus our analysis for large values of n where n → ∞ 12
  • 13. Kinds of Analysis Worst-case: (usually) • Max. time of algorithm on any input of size n. Average-case: (sometimes) • expected time over all inputs of size n. • Need assumption of statistical distribution of inputs. • Best-case: (bogus) • Cheat with a slow algorithm that works fast on some input. 13
  • 14. Analysis of Algorithms Worst Case, Best Case, Average Case Example: Sorting Which one to use? For Real Time Applications Data already sorted! Is it really the best case? 14
  • 15. Mathematical Notations Big-O: O (f(N) ) is bounded from above at most! Big-Omega: Ω (f(N) ) is bounded from below at least! Little-o: o (f(N) ) is bounded from above smaller than! Little-omega: ω (f(N) ) is bounded from below greater than! Theta: Θ (f(N) ) bounded, above & below equal to! 15
  • 16. Big-O • O-notation is an upper-bound notation. • It makes no sense to say f(n) is at least O(n2). 16
  • 17. Complexity Example: T(n) = 2n+4 Dominant Term: As n gets large enough, the dominant term has a much larger effect on the running time of an algorithm Example 2: T(n) = 2n3 + 1000n2 + 100000 17
  • 18. Dominant Term Example 1: T(n) = 2n+4 Example 2: T(n) = 2n3 + 1000n2 + 100000 Remove negligible terms Example 1: n Example 2: n3 18
  • 19. Dominant Term & Big-O Example 1: n Example 2: n3 We say that the algorithm runs Ex1: in the Order of n = O(n) Ex2: in the Order of n3 = O(n3) O(n) : The Time Complexity in the worst case, grows with the size of the problem 19
  • 20. Rules for using Big-O • For a single statement whose execution does not depend on n: O(1) Example: i=0 • For a sequence of statement, S1,S2,…,Sk T(S1)+T(S2)+…+T(Sk) Example: i=0 O(1) + print i O(1) 20
  • 21. Rules for using Big-O • Loop: For i=0 to n S1 S2 End For Dominent Term * No. of times loop executed Example: For i=0 to n j=j*8 j=j-1 End For 21
  • 22. Rules for using Big-O • Conditional Loop: While i<0 S1 S2 End While No fixed rule, find a bound on the number of iterations 22
  • 23. Rules for using Big-O • If condition C then S1 else S2 end if T(C) + max (T(S1) , T(S2) ) 23
  • 24. Rules for using Big-O • Nested Loop S1 For i=0 to n For j=0 to m S2 End For End For As n → ∞, m → ∞ 24
  • 25. Time Complexity Begin Initialize n 1 For i=0 to n n+2 For j=0 to m (m+2)(n+2) Print i (m+1)(n+1) End For End For End Total T(n) = 2mn + 3m + 4n + 8 O(n)=n^2 25
  • 26. Constants? Begin Initialize n For i=0 to n Print i End for End What are these? T(n)= 2 n + 4 26
  • 27. Slope Intercept Form T(n)= 2n+4 18 n T(n) 16 14 1 6 12 2 8 10 8 3 10 6 4 12 4 5 14 2 0 6 16 1 2 3 4 5 6 27
  • 28. Slope Intercept Form T(n)= 2n+4 C1n + C2 if n = 0 ? n T(n) if C2= 0? 1 6 2 8 18 3 10 16 14 4 12 12 10 5 14 8 6 6 16 4 2 0 1 2 3 4 5 6 28
  • 29. Growth 29
  • 30. Growth 30
  • 31. Order notation – some useful comparisons • O(1) < log n < n < n log n < n2 < n3 < 2n < 3n < n! < nn 31
  • 32. Order notation – some useful comparisons • Behavior of Growth for Log( number, base) is the same; Log2 n = Log3 n = Log10 n 32
  • 33. Practical and Un-practical algorithms • Algorithm is practical, if it’s time complexity is T(n) = O(na) (polynomial) • Algorithm is not practical otherwise T(nn) usually is exponential) 33
  • 34. Example • Assume that we have a record of 1000 students. If we want to search a specific record, what is the time complexity? • If ordered? Fastest Known Sorting Algorithm (n * log n) Quick Sort / Merge Sort Fastest Known Searching Algorithm (log n) Binary Search 34