Lists of Lists of Lists of …
Firstly, we should know what recursion means "A common method of simplification is to divide a problem into subproblems of the same type. As a computer programming technique, this is called divide and conquerand is key to the design of many important algorithms. Divide and conquer serves as a top-down approach to problem solving, where problems are solved by solving smaller and smaller instances. A contrary approach is dynamic programming. This approach serves as a bottom-up approach, where problems are solved by solving larger and larger instances, until the desired size is reached".(http://en.wikipedia.org/wiki/Recursion#Recursion_in_computer_science)
In last few weeks, we already learn the recursion tree,
today I learn the recursion number lists
From notes there is an example:
>depth (list (list (list 1
2)
3)
(list 4)))
>3
The answer is 3 that because:
*(list 1 2) and (list 4) is one
(list(list 1 2) 3 (list 4 ))is two
(list (list (list 1 2) 3 (list 4 ))) is three
* importantly: lists of lists of lists… are a inclusion relation and not a coordinating relation
Also, we have other method to get the answer 3 that is:
(define (depth lol) (cond [(list? lol) (+ 1 (apply max (map depth lol)))] [else 0]))
By the way, we have a second project in this week and due in early december.
I will know the second term test marks in Friday and I think I will not get a high mark TT
I will know the second term test marks in Friday and I think I will not get a high mark TT
没有评论:
发表评论