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
Drupady [299]
4 years ago
14

Implement a sublinear running time complexity recursive function in Java public static long exponentiation (long x, int n) to ca

lculate x^n. Note: In your function you can use only the basic arithmetic operators (+, -, *, and /).
Computers and Technology
1 answer:
Archy [21]4 years ago
8 0

Answer:

Following are the code block in the Java Programming Language.

//define recursive function

public static long exponentiation(long x, int n) {

//check the integer variable is equal to the 0.

if (x == 0) {

//then, return 1

return 1;

}

//Otherwise, set else

else {

//set long data type variable

long q = exponentiation(x, n/2);

q *= q;

//check if the remainder is 1

if (n % 2 == 1) {

q *= x;

}

//return the variable

return q;

}

}

Explanation:

<u>Following are the description of the code block</u>.

  • Firstly, we define the long data type recursive function.
  • Then, set the if conditional statement and return the value 1.
  • Otherwise, set the long data type variable 'q' that sore the output of the recursive function.
  • Set the if conditional statement and check that the remainder is 1 and return the variable 'q'.
You might be interested in
The Monte Carlo method is commonly used to approximate areas or volumes of shapes. In this problem, we will use Monte Carlo to f
sdas [7]

Answer:

import numpy as np

import matplotlib.pyplot as plt

def calculate_pi(x,y):

   points_in_circle=0

   for i in range(len(x)):

       if np.sqrt(x[i]**2+y[i]**2)<=1:

           points_in_circle+=1

       pi_value=4*points_in_circle/len(x)

       return pi_value

length=np.power(10,6)

x=np.random.rand(length)

y=np.random.rand(length)

pi=np.zeros(7)

sample_size=np.zeros(7)

for i in range(len(pi)):

   xs=x[:np.power(10,i)]

   ys=y[:np.power(10,i)]

   sample_size[i]=len(xs)

   pi_value=calculate_pi(xs,ys)

   pi[i]=pi_value

 

print("The value of pi at different sample size is")

print(pi)

plt.plot(sample_size,np.abs(pi-np.pi))

plt.xscale('log')

plt.yscale('log')

plt.xlabel('sample size')

plt.ylabel('absolute error')

plt.title('Error Vs Sample Size')

plt.show()

Explanation:

The python program gets the sample size of circles and the areas and returns a plot of one against the other as a line plot. The numpy package is used to mathematically create the circle samples as a series of random numbers while matplotlib's pyplot is used to plot for the visual statistics of the features of the samples.

4 0
3 years ago
What is the solution to the equation ?
ki77a [65]
There’s no solution to the equation
4 0
3 years ago
Read 2 more answers
In most signal "timing diagrams" (like the one below) the signals do not change from low to high, or from high to low, abruptly.
melisa1 [442]

Explanation:

This transient state occurs due to the fact that the signal change from low to high and high to low doesn't occur intermediately but in a very small time, in relation to the signal time itself.

At transistor level there are parasitic (undesired) capacitances and resistances, formed due to the layout configuration of conductor and dielectrics. As consequence a RC circuit is formed, thus making a propagation delay.

This delay must be characterized for each circuit, and specified as tpHL (transition time from High to Low) and tpLH (transition time from Low to High)

8 0
3 years ago
7
patriot [66]

Answer: i really don’t know

Explanation:

6 0
3 years ago
Question 7 * What is the default powerpoint standard layout A Blank B Title slide C Title only D. Comparison ​
lesantik [10]

Answer:

B. <u>Title</u><u> </u><u>slide</u><u> </u>layout is the default PowerPoint standard layout.

3 0
2 years ago
Other questions:
  • Which technological innovations along history allowed the appearance of the computer
    9·2 answers
  • How do i protect my computer from electrical spikes
    14·2 answers
  • When do on loop conditions happen? (1 point)
    5·1 answer
  • What is related to Gamut in Adobe illustrator?
    8·1 answer
  • Write pseudocode instructions to carry out each of the following computational operations:1. Determine the area of a triangle gi
    12·1 answer
  • Match the metric units with these measurements
    8·1 answer
  • Which spreadsheet toolbar displays options such as Cut and Paste?
    11·2 answers
  • Many interesting science-, technology-, engineering-, and math-oriented websites provide open-source data to the public. Which o
    8·1 answer
  • Supplies/material used in iron​
    11·1 answer
  • Which of the following uses the proper syntax for creating an HTML comment?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!