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
All of the following are guidelines for maintaining an engineering notebook EXCEPT
gayaneshka [121]

C) numbering pages at the bottom inside corner

An Engineering notebook is a legal document made of bound, grid paper where engineers formally document written ideas, sketches, work session summaries, research findings and interview information in chronological order.

When not in use, the notebook should be stored in a safe location with each page dated and signed.

There will absolutely no situation where a page is removed.

All entries should start at the top of each page and ending at the bottom. Supporting material should be permanently affixed.  

Book pages should be numbered on the top right side of the page.  


6 0
3 years ago
Sound technology has been influenced the most by the ___.
GaryK [48]
I think its the phonograph i hope this helps!
5 0
3 years ago
Read 2 more answers
Write a MATLAB code for the following problem:
AysviL [449]
<span>Here is matlab that should work % cos(x) = 1 - (x^2)/2! + (x^4)/4! -(x^6)/6!+(x^8)/8!... % let y= x*x % cos(x) = sum( (-y)^n/(2n)! ) format short x= 0.3*pi; y= x*x; for N= 1:6 n= 0:N; s1= [(-y).^n./factorial(2*n) ] mac= sum(s1); cx= cos(x); str= sprintf('%d terms. series: %12.10f cos(x): %12.10f\n %12.10f',... N, mac,cx, (cx-mac)); disp(str); end;</span>
7 0
3 years ago
Engineers are problem-solvers who use math, science, creativity and other knowledge and skills to solve problems. They use every
Elena-2011 [213]
Different types of engineers solve different kinds of problems. A mechanical engineer might design a rollercoaster that is fun and safe using knowledge of physics and mechanics,

this person is an engineer

just so u know I don't know if this is correct
8 0
3 years ago
Read 2 more answers
A set of programs that enable hardware to process data is
andreyandreev [35.5K]
C. the database as in the name is the base of everything.
8 0
4 years ago
Other questions:
  • 1. If you are 15% years old, you are old enough to obtain
    10·2 answers
  • Charlie is a British national who works in the United States as a novelist for children. Because he is British, he types the wor
    10·2 answers
  • COMPUTER SCIENCE:PIXELS
    5·1 answer
  • Our readings so far explored computer hardware and software, in particular operating systems and application software. There are
    11·1 answer
  • Challenge
    6·1 answer
  • QUESTION 56 Use the Windows ________ to check on a nonresponsive program. Backup utility Error-checking System Restore Task Mana
    6·1 answer
  • Explain default dictionary in microsoft word​
    9·1 answer
  • Does paste link Always increases the size of the referenced document ?
    14·1 answer
  • What is the difference between word processing software and presentation software​
    9·1 answer
  • Which of the following is a method to create a new table in Access?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!