23. Give a recursive algorithm for computing n * a using only addition, where n is a positive integer and a is a real number. (add a to itself n times).
Discrete Mathematics and its Applications - 14.
a) What is a recursive algorithm?
b) Describe a recursive algorithm for computing the sum of n numbers in a sequence.
Recursive algorithms - Write a recursice algorithm to find x^n mod m whenever n,x and m are positive integers based on the fact that :
x^n mod m = (x^(x-1) mod m * x mod m)mod m
Recursive definition - We can define sorted lists of integers as follows:
BASIS - A list consisting of a single integer is sorted.
INDUCTION - If L is a sorted list in which the last element is a and if b >= a, then L ...
Dynamic Programming : Write an Algorithm to Minimize Cost - There are n trading posts along a river. At any of the posts you can rent a canoe to be returned at any other post downstream. (It is next to impossible to paddle against the current.) For each pos ...