Coursera - Data Structures and Algorithms - Algorithmic Toolbox - Week 2


In the previous post I described the first week of "Data Structures and Algorithms" course on Coursera. In this post I am going to describe the second week.

What's has been covered

Authors started the second week with Fibonacci numbers. 15th century Italian mathematician Leonardo Fibonacci found this sequence of numbers where every number in it is the sum of the two preceding ones. They presented two versions of Fibonacci numbers algorithm: exponential (recursive) and polynomial.

They introduced a couple of very important concepts, such as types of algorithms:

  • Greedy
  • Divide and Conquer
  • Dynamic

And levels of algorithm's design:

  • Naive
  • Standard
  • Optimized
  • Magic

Then they continued with the greatest common divisor algorithms: naive GCD and Euclidian algorithm. Also they covered Big-O notation and how algorithm's runtime depends on input. There were few quizzes (nothing special) and after that I've started working on the assignment.

There are number of problems that has to be solved. The first three problems are very simple and covered in lectures. The other four were more complex and were not covered in lectures.

  1. Find Fibonacci number with given index - the classic approach to this problem is to use recursion, the problem is that the recursive algo is not as effective as other implementations, it simply won't pass tests. So it is required to come up with iterative version.
  2. Find last digit of Fibonacci number with given index - the trick is to store only the last digit of the number.
  3. Greatest common divisor - Euclidian algorithm - a very straightforward, but still useful algo.
  4. Least common multiple of two numbers - also, very common algo, that's not hard to implement, just check Least common multiple on wiki.
  5. Find Fibonacci number modulo m with given index - this one is more advanced, it requires understanding of Pisano period. But still, it is very simple once you understand how you can solve it in the way that you don't need to iterate through millions of numbers.
  6. Last digit of sum of Fibonacci numbers - very similar to the previous problem, you have to know about Pisano period for modulo 10 and apply it accordingly.
  7. Partial sum of Fibonacci numbers - a more advanced version of the previous problem.

There are couple of links that I have used to solve this week problems, if you don't want to get a complete solution but just looking for more info regarding outlined problems, you can check these:


In this post I have described the second week of "Data Structures and Algorithms" course on Coursera. This week wasn't hard, I hope next one will be more challenging. I like that weekly assignment starts with easier problems and then you get more complex ones. In the next post I will cover the third week.