1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Serjik [45]
3 years ago
9

3. (20 points) Write a C++ recursive function that finds the maximum value in an array (or vector) of integers without using any

loops. (a) Test your function using different input arrays. Include the code. i. ii. (b) Write a recurrence relation that represents your algorithm. i. T(n) = T(n-1) + O(1) (c) Solve the recurrence relation and obtain the running time of the algorithm in Big-O notation.
Computers and Technology
1 answer:
Luden [163]3 years ago
5 0

Answer:

Following are the code to this question:

In option (i):

#include <iostream>//defining header file

using namespace std;

int findMax(int B[], int x)//defining recursive method findMax

{

if (x == 1)//defining condition when value of n==1

return B[0];//return array first element

return max(B[x-1], findMax(B, x-1)); // calling recursive method inside max method and return value

}

int main() //defining main method  

{

int B[] = {12, 24, 55, 60, 50, 30, 29};//defining array B

int x= 7;//defining integer variable and assign a value

cout << "Maximum element value of the array is: "<<findMax(B, x)<<endl;//calling method findMax and print value

return 0;

}

Output:

Maximum element value of the array is: 60

In option (ii):

\Rightarrow \ T(n) = 1 + T(n-1)\\\Rightarrow  1 + 1 + T(n-2)\\ \Rightarrow  1 + 1 + 1 + ... n \ times \\\Rightarrow  O(n) \\

Explanation:

In the above-given program a recursive method "findMax" is defined, which accepts an array "B" and an integer variable "n" in its parameter, inside the method a conditional statement is used that, checks value of x equal to 1.

  • If the above condition is true it will return the first element of the array and find the max number.
  • Inside the main method, an array B is declared that assigns some values and an integer variable is declared, that also assigns some values, in the last step print method is used that pass value in method and prints its return value.
  • In the option (ii) we calculate the Big-O notation algorithm value.
You might be interested in
Why is it important to ask an interviewer at least one question at the end of an interview?
tatiyna
Because it, not only does it give you a chance to learn more about the workplace, it also makes you look more interested in the position.
<span />
4 0
3 years ago
Read 2 more answers
Declare an array named tax rates of five elements of type double and initialize the elements (starting with the first) to the va
inysia [295]

Answer:

"double tax_rates[5]= {0.10, 0.15, 0.21, 0.28, 0.31};" is the correct answer for the above question.

Explanation:

  • An array is a user-defined data type that is used to define the multiple variables of a single type in a continuous storage location.
  • In the C-programming language, When the user wants to declare an array he needs to define with the help of data type and size of the array with the help of the following syntax-- "Data_type variable_name [size_of_the_array];".
  • When the user wants to initialize the static value in the array then he can do that by the help of following syntax: "Data_type variable_name [size_of_the_array]={first_value,second_value,....,last_value};
  • The above question asked to defined the array of tax_rates name of type double with the above-defined value then he can do that with the help of above-defined syntax (which is defined in the answer part).
4 0
3 years ago
Items that are cut or copied are placed on the Clipboard.
WINSTONCH [101]

Anwer is <u>True</u>

please mark me brainliest answer

7 0
3 years ago
Read 2 more answers
Match these step-by-step directions in the order that you will find them in this course.
7nadin3 [17]

Answer:

1.Go to the View tab and select Watch.

2.Comparison

3.Editing

4.Drawing (I think)

5.Predesigned slides available for creating a new presentation

Explanation:

6 0
3 years ago
ou are working as a technician on a computer loaded with MS Windows. You boot the computer that has an incorrect driver loaded f
jeka94

Answer:

My Computer>>Properties>>Device Manager>>Video Card Properties>>Drivers Tab>>Roll Back Driver.

Explanation:

The user can do so by reverting the driver to the previous  version, The correct process to do so is by the Right Clicking on the computer menu and clicking device manager from the properties. In the device manager, click the properties of the video card and select the Drivers tab. In the Drivers tab, click on the Roll Back Driver. This will restore to the previous driver.

7 0
3 years ago
Other questions:
  • These are questions from my Computer/Customer Support Class
    6·1 answer
  • Rebooting the computer is a good troubleshooting technique.<br><br> True<br> False
    6·2 answers
  • James, a technician, needs to format a new drive on a workstation. He will need to configure read attributes to specific local f
    5·1 answer
  • What are the benefits of using a multiview sketch?
    11·1 answer
  • An investor is considering in which of two start-up companies to invest. The investor has faith in the industrial organization (
    9·2 answers
  • write a program that asks the user to enter a positive integer, then prints a list of all positive integers that divide that num
    6·1 answer
  • PLEASE HELP!!!!!!!!!!! The Excel tool that extends the height of a selected cell so that all the text fits into the cell and is
    10·2 answers
  • You wrote a program to allow to guess a number chosen randomly.
    10·2 answers
  • 3.<br>Give two reasons why everyone should study technology<br>​
    10·1 answer
  • when two people are in a race, what do you need to know to determine who is the fastest 1 units of speed that are identical 2 th
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!