Question

a) Give a recursive algorithm for finding the max of a finite set of integers, making...

a) Give a recursive algorithm for finding the max of a finite set of integers, making use of the fact that the max of n integers is the larger of the last integer in the list and the max of the first n-1 integers in the list.

Procedure power(x,n):

If (n=0):

return 1

Else:

return power(x,n-1) · x

b) Use induction to prove your algorithm is correct

Homework Answers

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Give an algorithm for finding the second largest integer in a finite sequence of integers. Write...
Give an algorithm for finding the second largest integer in a finite sequence of integers. Write the algorithm in pseudocode format
The following is Algorithm 8 from §5.4. Note that it uses the following definition of the...
The following is Algorithm 8 from §5.4. Note that it uses the following definition of the fibonacci sequence: fn = fn−1 + fn−2, f1 = 1, f0 = 0. procedure iterative fibonacci(n: nonnegative integer) if n = 0 then return 0 else x := 0 y := 1 for i := 1 to n − 1 do z := x + y x := y y := z end for return y end if end procedure Prove this algorithm is...
Question 4: The function f : {0,1,2,...} → R is defined byf(0) = 7, f(n) =...
Question 4: The function f : {0,1,2,...} → R is defined byf(0) = 7, f(n) = 5·f(n−1)+12n2 −30n+15 ifn≥1.• Prove that for every integer n ≥ 0, f(n)=7·5n −3n2. Question 5: Consider the following recursive algorithm, which takes as input an integer n ≥ 1 that is a power of two: Algorithm Mystery(n): if n = 1 then return 1 else x = Mystery(n/2); return n + xendif • Determine the output of algorithm Mystery(n) as a function of n....
Let S denote the set of all possible finite binary strings, i.e. strings of finite length...
Let S denote the set of all possible finite binary strings, i.e. strings of finite length made up of only 0s and 1s, and no other characters. E.g., 010100100001 is a finite binary string but 100ff101 is not because it contains characters other than 0, 1. a. Give an informal proof arguing why this set should be countable. Even though the language of your proof can be informal, it must clearly explain the reasons why you think the set should...
Q1: Thefollowing code is supposed to return n!, for positive n. An analysis of the code...
Q1: Thefollowing code is supposed to return n!, for positive n. An analysis of the code using our "Three Question" approach reveals that: int factorial(int n){ if (n == 0)     return 1;   else     return (n * factorial(n – 1)); } Answer Choices : it fails the smaller-caller question.     it passes on all three questions and is a valid algorithm.     it fails the base-case question.     it fails the general-case question. Q2: Given that values is of...
Given the following algorithm, matching each statement to the correct sequence for complexity analysis. procedure Alg3(A):...
Given the following algorithm, matching each statement to the correct sequence for complexity analysis. procedure Alg3(A): A is a list of n integers 1 for i = 1 to n-1 do 2   x=aix=ai 3 j = i − 1 4 while (j ≥≥ 0) do 5 if x≥ajx≥aj then 6 break 7 end if 8   aj+1=ajaj+1=aj 9 j = j − 1 a end while b   aj+1=xaj+1=x c end for d return A The complexity of this algorithm is O(n2)O(n2)...
The main goal is to implement two recursive methods, each is built to manipulate linked data...
The main goal is to implement two recursive methods, each is built to manipulate linked data structures. To host these methods you also have to define two utterly simplified node classes. 1.) Add a class named BinaryNode to the project. This class supports the linked representation of binary trees. However, for the BinaryNode class Generic implementation not needed, the nodes will store integer values The standard methods will not be needed in this exercise except the constructor 2.) Add a...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes...
In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes a contestant’s name, talent code, and talent description. The competition has become so popular that separate contests with differing entry fees have been established for children, teenagers, and adults. Modify the Contestant class to contain a field that holds the entry fee for each category, and add get and set accessors. Extend the Contestant class to create three subclasses: ChildContestant, TeenContestant, and AdultContestant. Child...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...