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
Write a recursive mathematical definition for computing 2n for a positive integer n.
Write a recursive mathematical definition for computing xn for a positive integer n and a real number x.
A recursive definition for exponentiation on the non-negative integers is partially given as: • expt(k, 0) ::= ? • expt(k, n + 1) ::= k · expt(k, n) What is the value for ?
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education