
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
Tracing the Recursion. Observe the recursive solution provided below and answer the following
questions:
1. Which line(s) of this program define(s) the base case of the binary() method?
2. Which line(s) of this program include recursive call(s)?
3. Trace the recursion below. You must show the tracing step by step (write them
down); otherwise – little to no credit!
4. At what step of your recursion tracing did you hit the base case?
5. What is the final output of this code?
![1 public class binarySearch {
2
3e
4
5
6
7
8
10
11
12
13
14
15
16
16
176
10
18
10
19
20
21
22
23
24
25
26}
ខ្លួនជនដម្ដង
public static int binary(int[] arr, int target, int left, int right) {
if (left
right) {
return -1;
}
}
int mid (left + right) / 2;
if (arr[mid] == target) {
return mid;
} else if (arr[mid]> target) {
return binary(arr, target, left, mid - 1);
} else {
}
Page < 4
return binary(arr, target, mid + 1, right);
}
public static void main(String[] args) {
int[] arr= {1, 2, 3, 4, 5, 6, 7);
int target = 2;
System.out.println (binary(arr, target, 0, arr.length - 1));
of 4
ZOOM
+](https://content.bartleby.com/qna-images/question/467946bb-e41e-4beb-a6a7-a7fc7a246d66/2cae8627-306b-4846-af83-e5eeb0d9d8b5/0r27lk7_thumbnail.png)
Transcribed Image Text:1 public class binarySearch {
2
3e
4
5
6
7
8
10
11
12
13
14
15
16
16
176
10
18
10
19
20
21
22
23
24
25
26}
ខ្លួនជនដម្ដង
public static int binary(int[] arr, int target, int left, int right) {
if (left
right) {
return -1;
}
}
int mid (left + right) / 2;
if (arr[mid] == target) {
return mid;
} else if (arr[mid]> target) {
return binary(arr, target, left, mid - 1);
} else {
}
Page < 4
return binary(arr, target, mid + 1, right);
}
public static void main(String[] args) {
int[] arr= {1, 2, 3, 4, 5, 6, 7);
int target = 2;
System.out.println (binary(arr, target, 0, arr.length - 1));
of 4
ZOOM
+
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 1 images

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
- 2. Consider a rectangle whose side lengths are two consecutive Fibonacci numbers. (Of course, neither of them is 0.) Such a rectangle could be, for example, 3 by 5, or 8 by 13, or 21 by 34, etc. (a) Give a recursive algorithm to dissect such a rectangle into squares such that no more than two of the resulting squares are the same size. (For example, if you had two 3 by 3 squares, you could have at most one 4 by 4 square.) Here's a specification for your algorithm: // Input: Two consecutive Fibonacci numbers f0, f1, representing an f0 by f1 rectangle, such that f0 <= f1. (Neither f0 nor f1 will be 0.) // Output: A list of integers representing side lengths of squares, such that the input rectangle can be dissected into squares of those sizes. No more than two of the squares can be the same size. Please be sure to give an English description of the algorithm along with pseu- docode, explaining the main points of its design, and a concise inductive argument for its correctness (i.e., say…arrow_forwardTracing the Recursion. Observe the recursive solution provided below and answer the followingquestions:1. Which line(s) of this program define(s) the base case of the binary() method?2. Which line(s) of this program include recursive call(s)?3. Trace the recursion below. You must show the tracing step by step (write themdown); otherwise – little to no credit!4. At what step of your recursion tracing did you hit the base case?5. What is the final output of this code?arrow_forwardKeeping in mind data structures, recursion, and using Java What is the value returned from the following method when it is called with the value 5? int mystery(int x, int y) { if (y == 0) return 1; if (y == 1) return x; return x * mystery(x, y-1); }arrow_forward
- Write a recursive method that returns the value of N! (N factorial) using the definition given in this chapter. Explain why you would not normally use recursion to solve this problem.arrow_forwardT/F 11. A recursion will still be replaced by an iteration and the other way around.arrow_forwardDo 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 thereturned value will be 19. public static int think(int x) {if(x<10)if(x%2!=0)return x;elsereturn 0;elseif(x%2!=0)return x%10 + think(x/10);elsereturn think(x/10);}arrow_forward
- Written explaination requiredarrow_forwardWhat is the static and dynamic scope? -Static scope: x=……. y=……. -Dynamic Scope: x=……. y=……. x, y:Real; Procedure Show () Begin Printf(x, y) ; End Procedure Small () Begin x: Real; x-1.25; y=3.5; Show (); End Begin x=2.5; y=3; Show (); Small (); Endarrow_forwardAttached is a programming question and its Java solution. My question regarding the recursion part: 1. "arr.add(j)" but then "arr.remove(arr.size() - 1)" follows soon after, and I think nothing should be printed. How does the program still print out permutations? Is it because the recursive method call only recurse all instructions from the start of the recursion method to that line? Otherwise, say the input is "5", how does "5=1+1+1+1+1" get printed? 2. Does the recursion stop when "j<=n" evaluates false because of "for(int j = i; j <= n; j++)"? Otherwise, which line of code tells the recursion to stop?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