Lecture 16: Recursion on Non-numerics

Lecture 16: Recursion on Non-numerics

MIT OpenCourseWare

6 месяцев назад

12,148 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@tunahanada6116
@tunahanada6116 - 28.04.2024 23:09

🔥

Ответить
@luisp1375
@luisp1375 - 03.05.2024 21:06

This one reversed my brain

Ответить
@JV_Arg
@JV_Arg - 17.05.2024 04:53

I watched this two times. The second time I didn't understand it. 🤣
She is a great teacher. Excellent explanations.

Ответить
@MrRosamunda
@MrRosamunda - 26.06.2024 22:52

I wanted to revisit recursion and found lecture 15 and 16. Such an epic professor! I was doing the exercise about basketball and got stuck for a while because her function's docstring said: "order doesn't matter", but it does (e.g. 2+1 and 1+2 are counted as 2 different options)! Pointing it out in case it helps someone :)

Ответить
@mawkuri5496
@mawkuri5496 - 06.08.2024 05:19

those are big chalks😮

Ответить
@voitikfamily2679
@voitikfamily2679 - 21.08.2024 16:21

Thank you.

Ответить
@dominikwilczek5655
@dominikwilczek5655 - 25.08.2024 14:23

Correct me if im wrong but if order in this basketball score recursion example doesnt matter, then there are 4 ways to score 4 points: (1,1,1,1), (1,1,2), (1,3) and (2,2). Yet the recursive function of 4 returns 6. If order of scoring would matter then there are 7 ways for getting to 4 points: (1,1,1,1), (1,1,2), (1,2,1), (2,1,1), (2,2), (1,3) and (3,1), and they dont sum up to returned 6 ways.

Ответить
@সমুদ্রসন্তান
@সমুদ্রসন্তান - 29.09.2024 23:14

This also works for fib example, if for any reason it helps

def fib(n, d = {1:1, 2:1}):
if n in d:
return d[n]
else:
result = fib(n-1) + fib (n-2)
d[n] = result
return result

Ответить
@ManishKumar-pp3li
@ManishKumar-pp3li - 05.10.2024 14:34

Think you mam

Ответить
@ifedayoosifuye8798
@ifedayoosifuye8798 - 24.10.2024 20:35

boolean inListOfLists(List<List<Integer>> L, int e) {
// Base case: if the list is empty, return false
if (L.size() == 0) return false;

// Get the first sublist
List<Integer> sublist = L.get(0);

// Check if the element exists in the current sublist
for (int num : sublist) {
if (num == e) return true;
}

// Recursive case: check the rest of the list of lists
return inListOfLists(L.subList(1, L.size()), e);
}

Ответить