From the course: Advanced Algorithmic Thinking with Python

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Challenge: Implementing Fibonacci function in Python

Challenge: Implementing Fibonacci function in Python - Python Tutorial

From the course: Advanced Algorithmic Thinking with Python

Challenge: Implementing Fibonacci function in Python

[Electronic Music] - [Voiceover] Divide and conquer algorithms are often implemented using recursion. Now in the previous chapter, we looked at quicksort and our quicksort function actually used recursion. I just want to show you some aspects of it now. So in quicksort.py we have, first of all, this if lenn(arr) is less than or equal to one now we called it a base case. So there needs to be a base case in a recursive function. So at some point the recursion will stop and we'll start returning values from our function. So, if the length of the array in this case was less than one, then we just return the array itself. Otherwise, we did some partitioning, that's lines four through seven, and then we made further calls. So this is the recursive part. So we're recording the function which we're currently defining, and we call it with different parameters in this case, the list that we've created with our petition and it's…

Contents