Berkeley 61A 1_7 Reaction


Today I finished chapter 1.7. The main point in this chapter is Recursive Functions, which culculate problems by apply itself.

And this chapter shows me lots of example and many function logic and skills. The first is a interesting function that can sum solo digits in a big number. Such as 123456 can equal 1+2+3+4+5+6 = 21, and this function used recursive function’s characteristic .

And there are two factorial functions, one of the fuction is a iterative function and another is a recursive function, let’s see what’s the differences in the two fuctions:

The first is a iterative function and have used while element to design it, like this:

And the rescursive version is:

This fuction save many useful name, like “total” and “k”, just have “fact()” and “n”, so this is better (Jhon said)

Next function is called “Mutual Recursive Function”, because it use 2 recursive function to argument, and the example below is used to examin the number is even or odd:

It also can write down in a single recursive function, like this:

And the next important point named “Tree Function”, the lecture gives a lively example by using Fibonacci fuction:

It’s easy to understand because I remind this. So this step is easy for me.

“Partitions” have a very hard logic I think, and it’s the most important example in this lecture.

“The number of partitions of a positive integer n, using parts up to size m, is the number of ways in which n can be expressed as the sum of positive integer parts up to m in increasing order. For example, the number of partitions of 6 using parts up to 4 is 9.”


All of this, I finished the chapter1 today!

Besides, I watching a grammar lectuer in youtube.

The website is “https://www.youtube.com/watch?v=nw0X025a2nA” and I love this teacher