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
Using numerous computers to inundate and overwhelm the network from numerous launch points is called a(n) ________ attack.
AnnZ [28]
Distributed Denial of Service /<span> </span><span>DDoS</span>
4 0
3 years ago
What tool can help discover and report computer errors when you first turn on a computer and before the operating system is laun
Vlada [557]

Answer:

a post diagnostic

Explanation:

4 0
3 years ago
Read 2 more answers
The term "Big Data" is relative as it depends on the size of the using organization.
oksano4ka [1.4K]

Answer:

A

Explanation:

8 0
3 years ago
Using the lab's show ip sla statistics example, what does the failure count indicate about the web server?
NeX [460]

It shows the number of times SLA ICMP (Internet Control Message Protocol), Protocol (TCP), File Transfer Protocol (FTP), Dynamic Host Configuration Protocol (DHCP), Domain Name System (DNS), or UDP echo operations did not manage to reach the web server.






7 0
3 years ago
Jason works as a financial investment advisor. He collects financial data from clients, processes the data online to calculate t
Sedbober [7]

I believe the answer is A. because he has to listen to what the people tell him and he information he has to think about and make a choice on what to reply with.

I hope this helps and its correct please let me know if its wrong have a great day//night.

4 0
3 years ago
Other questions:
  • "Server Manager will allow you to manage all roles and features installed on any server, and view the status of all your servers
    7·1 answer
  • You are asked to design a system of FP numbers representation (with your own design choices), labeled Custom_FP_48, for which we
    8·1 answer
  • List 5 anti-virus products currently in use
    15·1 answer
  • I Just Realized................
    7·2 answers
  • This problem has been solved!
    8·1 answer
  • Which sentence(s) below are true?a. IP stands for Internet Protocol.b. In most home networks IP addresses are assigned by the In
    6·1 answer
  • Privacy Group of answer choices must be respected if we are to function as complete, self-governing agents is an absolute value
    5·1 answer
  • The average American has 10 devices, ask for users average number of devices. Any number between 7 and 12 will print “you have a
    13·1 answer
  • Creating a Numpy Array
    5·1 answer
  • what option can be used to create vpn connections that can be distributed to users' computers so that vpn clients do not have to
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!