Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Do the trace in detail and submit The source Code As Well
From the following recursive method
Trace (in details) the calling of the above method with any input from your choice such that the
returned value will be 19.
public static int think(int x) {
if(x<10)
if(x%2!=0)
return x;
else
return 0;
else
if(x%2!=0)
return x%10 + think(x/10);
else
return think(x/10);
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
Knowledge Booster
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
- Use java and correctly indent code.arrow_forwardUsing the code in the image provided: Implement a method called summation which adds two integers and returns their sum. INPUT: The first line of input contains an integer a. The Second Line of input containes and integer b. OUTPUT: Print the result which is the sum of a and b.arrow_forwardJava - Write an iterative method that calculates the SUM of all integers between 1 and a given integer N (input into the method). Write a corresponding recursive solution. (return answer, don’t print)arrow_forward
- Consider the following method: public static void method (int x, int y) { if (x < y) { method (x+1, y); System.out.print (x + " "); } } What will happen as the result of calling method (2,6)? (Select all correct answers) output will be 6 5 4 3 2 Program goes to an infinite loop because of errors in recursive calls 5 recursive calls will be made from method (3,6) to method (7,6) output will be 5 4 3 2 method (6, 6) will be called inside of the recursion 4 recursive calls will be made from method (3,6) to method (6,6) method (5, 6) will be called inside of the recursionarrow_forward49, question is in java, thanksarrow_forwardWhen looking at this code making recursive calls, how would I identify how many recursive calls are being made?arrow_forward
- Consider the following recursive method: Public static int Fib(int a1, int a2, int n){ if(n == 1) return a1; else if (n == 2) return a2;else return Fib(a1, a2, n-1) + Fib(a1, a2, n-2);} Please draw the recursion trace for Fib(2,3,5)arrow_forwardGiven a list of integers, you want to know whether it is possible to divide the integers into two sets, so that the sums of the two sets are the same. Every integer must be in one set or the other. Write a recursive helper method that takes any number of arguments you like, and make the initial call to your recursive helper method from equalSum(). Do not use any loops or regular expressions. Test case 1: equalSum([2, 3, 5]) true Test case 2: equalSum([2, 2, 5]) falsearrow_forwardNote that you can only use recursion to solve Q1 and you cannot use any loop. You are free to add helper methods, but you are not allowed to change the method header.Question 1: Crazy seriesIn this session, you need to implement the crazy series method. In the crazy series, you will be given a starting number. Then, you need to times 2 for each number until the number is greater than 100. After the number is greater than 100, you need to divide 3 until we reach the number is less than 5. Note that the input number must be greater than 0, and you are not allowed to use loop here.For example,crazySeries(10) should return ArrayList [10.0, 20.0, 40.0, 80.0, 160.0, 53.333333333333336, 17.77777777777778, 5.9259259259259265, 1.9753086419753088]crazySeries(5) should return ArrayList [5.0, 10.0, 20.0, 40.0, 80.0, 160.0, 53.333333333333336, 17.77777777777778, 5.9259259259259265, 1.9753086419753088]crazySeries(1) should return ArrayList [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0,…arrow_forward
- change Summation Integers problem to Finding the minimumproblem. Make sure you properly wrote/updated all text messages, method names,and math calculations.Hint: You can use java.lang.Math.min() method.Example: System.out.printf("The min of the integers %4d and %4d and %4dis %7d\n", a, b, c,d MinTest(a, b, c,d)); fix below code structurearrow_forwardI have two questions: Is my programs code the most effective way at finding recursion or is there a much better and cleaner way? Why is the program showing 0 when I implement a number that depth is greater than 100? Shouldn't it show the number 1? Source code: package recursiveModule; public class RecursiveMethod { public static long calculateFactorial(int n, int depth) { if (depth > 100 || n <= 1) { return 1; } return n * calculateFactorial(n - 1, depth + 1); } public static void main(String[] args) { System.out.println("Factorial of 1 is " + RecursiveMethod.calculateFactorial(1, 0)); System.out.println("Factorial of 8 is " + RecursiveMethod.calculateFactorial(8, 0)); System.out.println("Factorial of 101 is " + RecursiveMethod.calculateFactorial(101, 0)); } }arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education