SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Downloaden Sie, um offline zu lesen
Proofs, Recursion and Analysis of
                     Algorithms




                    Mathematical
                    Structures for
                  Computer Science
                               Chapter 2




    Copyright © 2006 W.H. Freeman & Co. and modified by David Hyland-Wood, UMW 2010
   Proofs, Recursion and
    Analysis of Algorithms
Wednesday, February 10, 2010
Recursive Sequences
        ●     Definition: A sequence is defined recursively by explicitly naming the
              first value (or the first few values) in the sequence and then defining
              later values in the sequence in terms of earlier values.
        ●     Examples:
                  S(1) = 2
                  ■


                  S(n) = 2S(n-1) for n ≥ 2
                  ■


                       • Sequence S ⇒ 2, 4, 8, 16, 32,….

                  ■
                      T(1) = 1
                  ■   T(n) = T(n-1) + 3 for n ≥ 2
                       • Sequence T ⇒ 1, 4, 7, 10, 13,….

                  ■
                      Fibonaci Sequence
                  ■
                      F(1) = 1
                  ■
                      F(2) = 1
                  ■
                      F(n) = F(n-1) + F(n-2) for n > 2
                       • Sequence F ⇒ 1, 1, 2, 3, 5, 8, 13,….
    Section 2.4                                     Recursive Definitions             2
Wednesday, February 10, 2010
Fibonaci Sequence
         ●     Related mathematically to fractals
                   ■
                       …and thus to computer graphics.




     Section 2.4                                           Recursive Definitions   3
Wednesday, February 10, 2010
 Thanks to http://www.flickr.com/photos/pagedooley/2216914220/
Recursive function
        ●   Ackermann function
        	

 	

 	

 n+1	

 	

               	

    m=0
                  A(m,n) = 	

 A(m-1, 1)	

  	

    for m > 0 and n = 0
                  	

 	

      	

    A(m-1, A(m,n-1))	

  for m > 0 and n >
                      0

                  ■
                      Find the terms A(1,1), A(2,1), A(1,2)
                  A(1,1) = A(0, A(1,0)) = A(0, A(0,1)) = A(0,2) = 3
                  A(1,2) = A(0, A(1,1)) = A(0, 3) = 4
                  A(2,1) = A(1, A(2,0)) = A(1, A(1,1)) = A(1, 3)
                  	

 	

          = A(0, A(1,2)) = A(0, 4) = 5
                  Using induction it can be shown that
                  	

 	

      	

     	

     A(1,n) = n + 2 for n = 0,1,2…
                  	

 	

      	

     	

     A(2,n) = 2n + 3 for n = 0,1,2…
    Section 2.4                             Recursive Definitions                4
Wednesday, February 10, 2010
Recursively defined operations


        ●     Exponential operation
                  ■
                      a0 = 1
                  ■   an = aan-1 for n ≥ 1

        ●     Multiplication operation
                  ■
                      m(1) = m
                  ■   m(n) = m(n-1) + m for n ≥ 2

        ●     Factorial Operation
                  ■
                      F(0) = 1
                  ■   F(n) = nF(n-1) for n ≥ 1

    Section 2.4                               Recursive Definitions   5
Wednesday, February 10, 2010
Backus–Naur Form
          ●    A recursive symbolic notation for strings, used to
               define computer programming language syntax
          ●    e.g.




     Section 2.4                                  Recursive Definitions   6
Wednesday, February 10, 2010
 Originally used to define the syntax for Algol
 The example is from IETF RFC 2616, HTTP 1.1
Recursively defined algorithms
        ●     If a recurrence relation exists for an operation, the algorithm for such a
              relation can be written either iteratively or recursively
        ●     Example: Factorial, multiplication etc.
                  S(1) = 1
                  S(n) = 2S(n-1) for n ≥ 2
                  S(integer n) //function that iteratively computes the value S(n)
                  Local variables:
                  	

 integer i ;//loop index
                  	

 CurrentValue ;                             S(integer n)      //recursively calculates S(n)
                  if n =1 then                                      if n =1 then	
        //base case
                  	

 output 2                                   	
          output 2
                  j=2                                               else
                  CurrentValue = 2                               	
          return (2*S(n-1))
                  while j ≤ n                                         end if
                  	

 CurrentValue = CurrentValue *2               end function S
                  	

 j = j+1
                  end while
                  return CurrentValue
                  end if
    Section 2.4                                           Recursive Definitions                                     7
Wednesday, February 10, 2010
Why Write Recursive Functions?
          ●    Because CPU operations are cheap … and getting
               cheaper,
          ●    But code is expensive to maintain.




     Section 2.4                                               Recursive Definitions                                            8
Wednesday, February 10, 2010
 “Several measures of digital technology are improving at exponential rates related to Moore's law, including the size, cost, density
 and speed of components.”
 Thanks to http://en.wikipedia.org/wiki/File:Transistor_Count_and_Moore%27s_Law_-_2008.svg
Recursive algorithm for selection sort
          ●       Algorithm to sort recursively a sequence of numbers in increasing or
                  decreasing order
          	

     Function sort(List s,Integer n)	

 //This function sorts in increasing order
             	

 	

     if n =1 then
          	

 	

        	

       output “sequence is sorted”	

               //base case
             	

 	

     end if
             	

 	

     max_index = n 	

 	

        //assume sn is the largest
             	

 	

     for j = 2 to n do
          	

     	

    	

        if s[j] > s[max_index] then
          	

     	

    	

        	

        max_index = j	

 //found larger, so update
          	

     	

    	

        end if
             	

 	

     end for
             	

 	

     exchange/swap s[n] and s[max_index]                //move largest to the end
             	

 	

  return(sort(s,n-1))
             	

 end function sort
     Section 2.4                                     Recursive Definitions                               9
Wednesday, February 10, 2010
 Fixed max_index definition to correct
 algorithm
Selection Sort Example
         ●     Sequence S to be sorted:
                   ■
                       S: 23, 12, 9, –3, 89, 54
         ●     After 1st recursive call, the sequence is:
                   Swap 89 and 54
                   ■


                   S: 23, 12, 9, -3, 54, 89
                   ■


         ●     After 2nd recursive call:
                   ■
                       Nothing is swapped as elements happen to be in increasing order.
         ●     After 3rd recursive call, the sequence is:
                   Swap -3 and 23
                   ■



                   S: -3, 12, 9, 23, 54, 89
                   ■


         ●     After 4th recursive call:
                   ■
                       Swap 12 and 9
                   ■
                       S: -3, 9, 12, 23, 54, 89
         ●     After 5th recursive call, the sequence is:
                   ■
                       Nothing is swapped as elements happen to be in increasing order.
         ●     Final sorted array S: -3, 9, 12, 23, 54, 89
     Section 2.4                                    Recursive Definitions                  10
Wednesday, February 10, 2010
 Fixed run of algorithm to be
 correct
Recursive algorithm for binary search
        ●     Looks for a value in an increasing sequence and returns the
              index of the value if it is found or 0 otherwise.
                  Function binary_search(s, j, k, key)
                  	

 if j > k then	

         	

   //not found
                  	

 	

             return 0
                     	

 end if
                     	

 m = (j+k)/2
                     	

 if key = sk then 	

  	

   // base case
                        	

 	

          return (m)
                        	

 end if
                        	

 if key < sk then
                  	

    	

        k = m-1
                     	

 else
                     	

 	

        j = m+1
                     	

 end if
                     	

 return(binary_search(s,j,k,key))
                     end binary_search
    Section 2.4                                        Recursive Definitions   11
Wednesday, February 10, 2010
Binary Search Example
        ●     Search for 81 in the sequence 3, 6, 18, 37, 76, 81, 92
                  ■
                      Sequence has 7 elements.
                  ■
                      Calculate middle point: (1 + 7)/2 = 4.
                  ■
                      Compares 81 to 37 (4th sequence element): no match.
                  ■
                      Search in the lower half since 81 > 37
                  ■
                      New sequence for search: 76 81 92
                  ■
                      Calculate midpoint: (5 + 7)/2 = 6
                  ■
                      6th Element: 81 Compares 81 to 81: perfect match
                  ■
                      Element 81 found as the 6th element of the sequence




    Section 2.4                            Recursive Definitions             12
Wednesday, February 10, 2010
Class exercise
        ●     What does the following function calculate?
                  Function mystery(integer n)
                     if n = 1 then
                  	

 return 1
                     else
                  	

 return (mystery(n-1)+1)
                     end if
                     end function mystery

        ●     Write the algorithm for the recursive definition of the
              following sequence
                  ■
                      a, b, a+b, a+2b, 2a+3b, 3a+5b

    Section 2.4                            Recursive Definitions        13
Wednesday, February 10, 2010

Weitere ähnliche Inhalte

Was ist angesagt?

Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysisSoujanya V
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesjayavignesh86
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms ISri Prasanna
 
Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Vai Jayanthi
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosluzenith_g
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisAnindita Kundu
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and ComplexityRajandeep Gill
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notationsjayavignesh86
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical MethodsESUG
 
Recursion | C++ | DSA
Recursion | C++ | DSARecursion | C++ | DSA
Recursion | C++ | DSASumit Pandey
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsAbdullah Al-hazmy
 

Was ist angesagt? (20)

Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrences
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Recursion
RecursionRecursion
Recursion
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
 
Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmos
 
Alg1
Alg1Alg1
Alg1
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
 
Time andspacecomplexity
Time andspacecomplexityTime andspacecomplexity
Time andspacecomplexity
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Data Structures- Hashing
Data Structures- Hashing Data Structures- Hashing
Data Structures- Hashing
 
Recursion
RecursionRecursion
Recursion
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
 
Recursion | C++ | DSA
Recursion | C++ | DSARecursion | C++ | DSA
Recursion | C++ | DSA
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
 

Ähnlich wie Recursive Algorithms and Proofs

1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptxpallavidhade2
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 
CPSC 125 Ch 2 Sec 5
CPSC 125 Ch 2 Sec 5CPSC 125 Ch 2 Sec 5
CPSC 125 Ch 2 Sec 5David Wood
 
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
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexityshowkat27
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexityashishtinku
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutionssubhashchandra197
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqPradeep Bisht
 
Efficient Identification of Improving Moves in a Ball for Pseudo-Boolean Prob...
Efficient Identification of Improving Moves in a Ball for Pseudo-Boolean Prob...Efficient Identification of Improving Moves in a Ball for Pseudo-Boolean Prob...
Efficient Identification of Improving Moves in a Ball for Pseudo-Boolean Prob...jfrchicanog
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonshin
 
Sure interview algorithm-1103
Sure interview algorithm-1103Sure interview algorithm-1103
Sure interview algorithm-1103Sure Interview
 
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
 
Lecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptLecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptZohairMughal1
 
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
 
06 Recursion in C.pptx
06 Recursion in C.pptx06 Recursion in C.pptx
06 Recursion in C.pptxMouDhara1
 

Ähnlich wie Recursive Algorithms and Proofs (20)

1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Dsp lecture vol 2 dft & fft
Dsp lecture vol 2 dft & fftDsp lecture vol 2 dft & fft
Dsp lecture vol 2 dft & fft
 
CPSC 125 Ch 2 Sec 5
CPSC 125 Ch 2 Sec 5CPSC 125 Ch 2 Sec 5
CPSC 125 Ch 2 Sec 5
 
Alex1 group2
Alex1 group2Alex1 group2
Alex1 group2
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
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..
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexity
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexity
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
 
pradeepbishtLecture13 div conq
pradeepbishtLecture13 div conqpradeepbishtLecture13 div conq
pradeepbishtLecture13 div conq
 
Efficient Identification of Improving Moves in a Ball for Pseudo-Boolean Prob...
Efficient Identification of Improving Moves in a Ball for Pseudo-Boolean Prob...Efficient Identification of Improving Moves in a Ball for Pseudo-Boolean Prob...
Efficient Identification of Improving Moves in a Ball for Pseudo-Boolean Prob...
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluiton
 
Sure interview algorithm-1103
Sure interview algorithm-1103Sure interview algorithm-1103
Sure interview algorithm-1103
 
6-Python-Recursion.pdf
6-Python-Recursion.pdf6-Python-Recursion.pdf
6-Python-Recursion.pdf
 
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
 
Lecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptLecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.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
 
06 Recursion in C.pptx
06 Recursion in C.pptx06 Recursion in C.pptx
06 Recursion in C.pptx
 

Mehr von David Wood

Internet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchainInternet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchainDavid Wood
 
Returning to Online Privacy?
Returning to Online Privacy?Returning to Online Privacy?
Returning to Online Privacy?David Wood
 
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...David Wood
 
BlockSW 2019 Keynote
BlockSW 2019 KeynoteBlockSW 2019 Keynote
BlockSW 2019 KeynoteDavid Wood
 
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221David Wood
 
Privacy in the Smart City
Privacy in the Smart CityPrivacy in the Smart City
Privacy in the Smart CityDavid Wood
 
Controlling Complexities in Software Development
Controlling Complexities in Software DevelopmentControlling Complexities in Software Development
Controlling Complexities in Software DevelopmentDavid Wood
 
Privacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable ClaimsPrivacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable ClaimsDavid Wood
 
Implementing the Verifiable Claims data model
Implementing the Verifiable Claims data modelImplementing the Verifiable Claims data model
Implementing the Verifiable Claims data modelDavid Wood
 
So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301David Wood
 
Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601David Wood
 
When Metaphors Kill
When Metaphors KillWhen Metaphors Kill
When Metaphors KillDavid Wood
 
Secularism in Australia
Secularism in AustraliaSecularism in Australia
Secularism in AustraliaDavid Wood
 
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and PleonasmsMeditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and PleonasmsDavid Wood
 
Building a writer's platform with social media
Building a writer's platform with social mediaBuilding a writer's platform with social media
Building a writer's platform with social mediaDavid Wood
 
Summary of the Hero's Journey
Summary of the Hero's JourneySummary of the Hero's Journey
Summary of the Hero's JourneyDavid Wood
 
Open by Default
Open by DefaultOpen by Default
Open by DefaultDavid Wood
 
Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926David Wood
 
Linked Data ROI 20110426
Linked Data ROI 20110426Linked Data ROI 20110426
Linked Data ROI 20110426David Wood
 
Introduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF VocabulariesIntroduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF VocabulariesDavid Wood
 

Mehr von David Wood (20)

Internet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchainInternet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchain
 
Returning to Online Privacy?
Returning to Online Privacy?Returning to Online Privacy?
Returning to Online Privacy?
 
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
 
BlockSW 2019 Keynote
BlockSW 2019 KeynoteBlockSW 2019 Keynote
BlockSW 2019 Keynote
 
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
 
Privacy in the Smart City
Privacy in the Smart CityPrivacy in the Smart City
Privacy in the Smart City
 
Controlling Complexities in Software Development
Controlling Complexities in Software DevelopmentControlling Complexities in Software Development
Controlling Complexities in Software Development
 
Privacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable ClaimsPrivacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable Claims
 
Implementing the Verifiable Claims data model
Implementing the Verifiable Claims data modelImplementing the Verifiable Claims data model
Implementing the Verifiable Claims data model
 
So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301
 
Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601
 
When Metaphors Kill
When Metaphors KillWhen Metaphors Kill
When Metaphors Kill
 
Secularism in Australia
Secularism in AustraliaSecularism in Australia
Secularism in Australia
 
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and PleonasmsMeditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
 
Building a writer's platform with social media
Building a writer's platform with social mediaBuilding a writer's platform with social media
Building a writer's platform with social media
 
Summary of the Hero's Journey
Summary of the Hero's JourneySummary of the Hero's Journey
Summary of the Hero's Journey
 
Open by Default
Open by DefaultOpen by Default
Open by Default
 
Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926
 
Linked Data ROI 20110426
Linked Data ROI 20110426Linked Data ROI 20110426
Linked Data ROI 20110426
 
Introduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF VocabulariesIntroduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF Vocabularies
 

Kürzlich hochgeladen

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
“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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
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
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Kürzlich hochgeladen (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
“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...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
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
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Recursive Algorithms and Proofs

  • 1. Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co. and modified by David Hyland-Wood, UMW 2010 Proofs, Recursion and Analysis of Algorithms Wednesday, February 10, 2010
  • 2. Recursive Sequences ● Definition: A sequence is defined recursively by explicitly naming the first value (or the first few values) in the sequence and then defining later values in the sequence in terms of earlier values. ● Examples: S(1) = 2 ■ S(n) = 2S(n-1) for n ≥ 2 ■ • Sequence S ⇒ 2, 4, 8, 16, 32,…. ■ T(1) = 1 ■ T(n) = T(n-1) + 3 for n ≥ 2 • Sequence T ⇒ 1, 4, 7, 10, 13,…. ■ Fibonaci Sequence ■ F(1) = 1 ■ F(2) = 1 ■ F(n) = F(n-1) + F(n-2) for n > 2 • Sequence F ⇒ 1, 1, 2, 3, 5, 8, 13,…. Section 2.4 Recursive Definitions 2 Wednesday, February 10, 2010
  • 3. Fibonaci Sequence ● Related mathematically to fractals ■ …and thus to computer graphics. Section 2.4 Recursive Definitions 3 Wednesday, February 10, 2010 Thanks to http://www.flickr.com/photos/pagedooley/2216914220/
  • 4. Recursive function ● Ackermann function n+1 m=0 A(m,n) = A(m-1, 1) for m > 0 and n = 0 A(m-1, A(m,n-1)) for m > 0 and n > 0 ■ Find the terms A(1,1), A(2,1), A(1,2) A(1,1) = A(0, A(1,0)) = A(0, A(0,1)) = A(0,2) = 3 A(1,2) = A(0, A(1,1)) = A(0, 3) = 4 A(2,1) = A(1, A(2,0)) = A(1, A(1,1)) = A(1, 3) = A(0, A(1,2)) = A(0, 4) = 5 Using induction it can be shown that A(1,n) = n + 2 for n = 0,1,2… A(2,n) = 2n + 3 for n = 0,1,2… Section 2.4 Recursive Definitions 4 Wednesday, February 10, 2010
  • 5. Recursively defined operations ● Exponential operation ■ a0 = 1 ■ an = aan-1 for n ≥ 1 ● Multiplication operation ■ m(1) = m ■ m(n) = m(n-1) + m for n ≥ 2 ● Factorial Operation ■ F(0) = 1 ■ F(n) = nF(n-1) for n ≥ 1 Section 2.4 Recursive Definitions 5 Wednesday, February 10, 2010
  • 6. Backus–Naur Form ● A recursive symbolic notation for strings, used to define computer programming language syntax ● e.g. Section 2.4 Recursive Definitions 6 Wednesday, February 10, 2010 Originally used to define the syntax for Algol The example is from IETF RFC 2616, HTTP 1.1
  • 7. Recursively defined algorithms ● If a recurrence relation exists for an operation, the algorithm for such a relation can be written either iteratively or recursively ● Example: Factorial, multiplication etc. S(1) = 1 S(n) = 2S(n-1) for n ≥ 2 S(integer n) //function that iteratively computes the value S(n) Local variables: integer i ;//loop index CurrentValue ; S(integer n) //recursively calculates S(n) if n =1 then if n =1 then //base case output 2 output 2 j=2 else CurrentValue = 2 return (2*S(n-1)) while j ≤ n end if CurrentValue = CurrentValue *2 end function S j = j+1 end while return CurrentValue end if Section 2.4 Recursive Definitions 7 Wednesday, February 10, 2010
  • 8. Why Write Recursive Functions? ● Because CPU operations are cheap … and getting cheaper, ● But code is expensive to maintain. Section 2.4 Recursive Definitions 8 Wednesday, February 10, 2010 “Several measures of digital technology are improving at exponential rates related to Moore's law, including the size, cost, density and speed of components.” Thanks to http://en.wikipedia.org/wiki/File:Transistor_Count_and_Moore%27s_Law_-_2008.svg
  • 9. Recursive algorithm for selection sort ● Algorithm to sort recursively a sequence of numbers in increasing or decreasing order Function sort(List s,Integer n) //This function sorts in increasing order if n =1 then output “sequence is sorted” //base case end if max_index = n //assume sn is the largest for j = 2 to n do if s[j] > s[max_index] then max_index = j //found larger, so update end if end for exchange/swap s[n] and s[max_index] //move largest to the end return(sort(s,n-1)) end function sort Section 2.4 Recursive Definitions 9 Wednesday, February 10, 2010 Fixed max_index definition to correct algorithm
  • 10. Selection Sort Example ● Sequence S to be sorted: ■ S: 23, 12, 9, –3, 89, 54 ● After 1st recursive call, the sequence is: Swap 89 and 54 ■ S: 23, 12, 9, -3, 54, 89 ■ ● After 2nd recursive call: ■ Nothing is swapped as elements happen to be in increasing order. ● After 3rd recursive call, the sequence is: Swap -3 and 23 ■ S: -3, 12, 9, 23, 54, 89 ■ ● After 4th recursive call: ■ Swap 12 and 9 ■ S: -3, 9, 12, 23, 54, 89 ● After 5th recursive call, the sequence is: ■ Nothing is swapped as elements happen to be in increasing order. ● Final sorted array S: -3, 9, 12, 23, 54, 89 Section 2.4 Recursive Definitions 10 Wednesday, February 10, 2010 Fixed run of algorithm to be correct
  • 11. Recursive algorithm for binary search ● Looks for a value in an increasing sequence and returns the index of the value if it is found or 0 otherwise. Function binary_search(s, j, k, key) if j > k then //not found return 0 end if m = (j+k)/2 if key = sk then // base case return (m) end if if key < sk then k = m-1 else j = m+1 end if return(binary_search(s,j,k,key)) end binary_search Section 2.4 Recursive Definitions 11 Wednesday, February 10, 2010
  • 12. Binary Search Example ● Search for 81 in the sequence 3, 6, 18, 37, 76, 81, 92 ■ Sequence has 7 elements. ■ Calculate middle point: (1 + 7)/2 = 4. ■ Compares 81 to 37 (4th sequence element): no match. ■ Search in the lower half since 81 > 37 ■ New sequence for search: 76 81 92 ■ Calculate midpoint: (5 + 7)/2 = 6 ■ 6th Element: 81 Compares 81 to 81: perfect match ■ Element 81 found as the 6th element of the sequence Section 2.4 Recursive Definitions 12 Wednesday, February 10, 2010
  • 13. Class exercise ● What does the following function calculate? Function mystery(integer n) if n = 1 then return 1 else return (mystery(n-1)+1) end if end function mystery ● Write the algorithm for the recursive definition of the following sequence ■ a, b, a+b, a+2b, 2a+3b, 3a+5b Section 2.4 Recursive Definitions 13 Wednesday, February 10, 2010