Question

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

Answer #1

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 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) = 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 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 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...

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 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 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 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...

BridgeRock is a major manufacturer of tires in the U.S.. The
company had five manufacturing facilities where tires were made and
another 20 facilities for various components and materials used in
tires. Each manufacturing facility produced 10,000 tires every
hour. Quality had always been emphasized at BridgeRock, but lately
quality was a bigger issue because of recent fatal accidents
involving tires made by other manufacturers due to tread
separation. All tire manufacturers were under pressure to ensure
problems did not...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 7 minutes ago

asked 14 minutes ago

asked 18 minutes ago

asked 26 minutes ago

asked 35 minutes ago

asked 40 minutes ago

asked 50 minutes ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago

asked 1 hour ago