Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781119278023
Author: Michael T. Goodrich; Roberto Tamassia; Michael H. Goldwasser
Publisher: Wiley Global Education US
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 5, Problem 11C

Explanation of Solution

Recursive method to compute the integer part of base-two logarithm “n”:

Create the method baseTwoLog() that accepts the input parameter as “n” to compute the integer part of base-two logarithm “n” by using addition and division by calling this method recursively.

//Define the baseTwoLog() method

public static int baseTwoLog(int n)

{

  //Declare and initialize the required variables

  int result = 0;

  //Loop executes until the "n" is less than "1"

  while(n > 1)

  {

  //Divide "n" by "2" and store the result into "n"

  n=n/2;

  //Increment "result" by "1"

  result++;

/*Call baseTwoLog() method recursively to compute the integer part of base-two logarithm of "n"...

Blurred answer
Students have asked these similar questions
I need help making this EER diagram in Chen Notation.
In Java I have an input in a text file that I can't submit here. So, please use it as input.txt
Perceptual acuity, according to Ram Charan, explains how Ted Turner became the first CEO to recognize the potential of 24-hour news and thereby created CNN. a) True  b) False
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT