









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










10/11/
Lecture 16Recursion II
10/11/
10/11/
10/11/
linear_search(list
a_list,
int
search_int,
list
NOT_FOUND)
{
if
(a_list.size()
==
return
NOT_FOUND;
list
beginning
=
a_list.begin();
list
remainder
=
a_list;
remainder.pop_front();if
(*beginning
==
search_int)
return
beginning;
else
return
linear_search(remainder,search_int,
NOT_FOUND);
}
10/11/
which computes b
e^
using multiplication (and
recursion!)
10/11/
// First easy caseif n == 1
return 0 // Second easy caseelse if n == 2
return 1 // Hard caseelse
return fib(n-1) + fib(n-2)
}
10/11/
e
1 ... 2
1
^
−
−^
e
e e b
729
27
3
1 2
1 2 3
=
=
10/11/
10/11/
10/11/
1
and S
2
}q and q{S 1
}r, then p{S 2
}r 2
(Just a composition rule!)
y = 2;
1
z = x+y;
2
p: x=1, q: z=
10/11/
-^
p: true
-^
q: y
≥
x
-^
S: if (x>y) then y=x
10/11/
1
else
2
}q 1
(p
}q 2
à
p{if
1
else
}q 2