Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 18.2, Problem 18.2.2CP
Program Plan Intro
Recursive method:
A method which is called again and again by itself is called as recursive method. With the help of recursive method, it is possible to solve certain problems more quickly and easily.
Pros and cons of recursion:
Pros: recursion reduces unnecessary calling of functions. It is possible to solve complex problems more easily.
Cons: Recursion is always logical which is very difficult to understand. It takes more stack space. It also takes more time to process.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Find the recurrence relation of the code below and
find the runtime analysis of it using any method.
function mult(a, b)
if b = 0:
return 0
else if b is odd:
return (mult(2a,[b/2 )+a)
else:
return (mult(2a, [b/2 ))
in c++, use parallel arrays , and srand(time(NULL)) to randomize the two cards dealt at the start
Create a Blackjack (21) game. Your version of the game will imagine only a SINGLE suit of cards, so 13 unique cards, {2,3,4,5,6,7,8,9,10,J,Q,K,A}. Upon starting, you will be given two cards from the set, non-repeating. Your program MUST then tell you the odds of receiving a beneficial card (that would put your value at 21 or less), and the odds of receiving a detrimental card (that would put your value over 21). Recall that the J, Q, and K cards are worth ‘10’ points, the A card can be worth either ‘1’ or ‘11’ points, and the other cards are worth their numerical values.
It's well knowledge that "points" have problems with "dangling and wild pointers." Provide evidence to back up the claim you made.
Chapter 18 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 18.2 - What is a recursive method? What is an infinite...Ch. 18.2 - Prob. 18.2.2CPCh. 18.2 - Show the output of the following programs and...Ch. 18.2 - Prob. 18.2.4CPCh. 18.2 - Prob. 18.2.5CPCh. 18.2 - Write a recursive mathematical definition for...Ch. 18.3 - Prob. 18.3.1CPCh. 18.3 - What is wrong in the following methods?Ch. 18.3 - Prob. 18.3.3CPCh. 18.4 - Describe the characteristics of recursive methods.
Ch. 18.4 - Prob. 18.4.2CPCh. 18.4 - Prob. 18.4.3CPCh. 18.5 - Prob. 18.5.1CPCh. 18.5 - Prob. 18.5.2CPCh. 18.5 - What is a recursive helper method?Ch. 18.6 - Prob. 18.6.1CPCh. 18.6 - How does the program get all files and directories...Ch. 18.6 - How many times will the getSize method be invoked...Ch. 18.6 - Will the program work if the directory is empty...Ch. 18.6 - Will the program work if line 20 is replaced by...Ch. 18.6 - Will the program work if lines 20 and 21 are...Ch. 18.7 - Prob. 18.7.1CPCh. 18.8 - Prob. 18.8.1CPCh. 18.8 - Prob. 18.8.2CPCh. 18.8 - How many times is the displayTriangles method...Ch. 18.8 - Prob. 18.8.4CPCh. 18.8 - Prob. 18.8.5CPCh. 18.9 - Which of the following statements are true? a. Any...Ch. 18.9 - Prob. 18.9.2CPCh. 18.10 - Identify tail-recursive methods in this chapter.Ch. 18.10 - Rewrite the fib method in Listing 18.2 using tail...Ch. 18 - Prob. 18.1PECh. 18 - Prob. 18.2PECh. 18 - (Compute greatest common divisor using recursion)...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Fibonacci series) Modify Listing 18.2,...Ch. 18 - Prob. 18.8PECh. 18 - (Print the characters in a string reversely) Write...Ch. 18 - (Occurrences of a specified character in a string)...Ch. 18 - Prob. 18.11PECh. 18 - (Print the characters in a string reversely)...Ch. 18 - (Find the largest number in an array) Write a...Ch. 18 - (Find the number of uppercase letters in a string)...Ch. 18 - Prob. 18.15PECh. 18 - (Find the number of uppercase letters in an array)...Ch. 18 - (Occurrences of a specified character in an array)...Ch. 18 - (Tower of Hanoi) Modify Listing 18.8,...Ch. 18 - Prob. 18.19PECh. 18 - (Display circles) Write a Java program that...Ch. 18 - (Decimal to binary) Write a recursive method that...Ch. 18 - (Decimal to hex) Write a recursive method that...Ch. 18 - (Binary to decimal) Write a recursive method that...Ch. 18 - (Hex to decimal) Write a recursive method that...Ch. 18 - Prob. 18.25PECh. 18 - (Create a maze) Write a program that will find a...Ch. 18 - (Koch snowflake fractal) The text presented the...Ch. 18 - (Nonrecursive directory size) Rewrite Listing...Ch. 18 - (Number of files in a directory) Write a program...Ch. 18 - (Game: Knights Tour) The Knights Tour is an...Ch. 18 - (Game: Knights Tour animation) Write a program for...Ch. 18 - (Game: Eight Queens) The Eight Queens problem is...Ch. 18 - Prob. 18.35PECh. 18 - (Sierpinski triangle) Write a program that lets...Ch. 18 - (Hilbert curve) The Hilbert curve, first described...Ch. 18 - (Recursive tree) Write a program to display a...Ch. 18 - Prob. 18.39PE
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
- a java assignment about 4 used defined exception using array loop based on real life scenario. (use only java)arrow_forwardFind the bug and write code to proving you have identified the problem. What is the quick fix Byron's code needs? Byron is trying to define a 4 distinct tuples and access one specific element from each of them, but keeps getting an TypeError in his code for some reason a = (0, 1, 100)b = (-1, True, -0.1)c = (10)d = ("XX", "XY", "XXY")print(a[2], b[-1], c[0], d[2])# Byron's desired output for this code is: 100 -0.1 10 XXYarrow_forwardThe arithmetic operators and stream operators are both enumeration types. Is there a method to use these operators instantly while utilising enumeration types? For example, is it feasible to overload these operators and still get a good result? To what end are you arguing?arrow_forward
- Complete the Swap() method in main.c to exchange the values of the num field of two Number struct objects, num1 and num2. Hint: Refer to the given Number struct to see the num data member. Ex: If num1 is 19 and num2 is 178, calling Swap(num1, num2) will swap the values so that num1 becomes 178 and num2 becomes 19.arrow_forwardWhat does it mean to have a disjoint type? I'd want to see an example of this.arrow_forwardIn this task you will work with the linked list of digits we have created in the lessons up to this point. As before you are provided with some code that you should not modify: A structure definition for the storage of each digit's information. A main() function to test your code. The functions createDigit(), append(), printNumber(), freeNumber(), readNumber() and divisibleByThree() (although you may not need to use all of these). Your task is to write a new function changeThrees() which takes as input a pointer that holds the address of the start of a linked list of digits. Your function should change all of those digits in this linked list that equal 3 to the digit 9, and count how many replacements were made. The function should return this number of replacements. Provided codearrow_forward
- Need help making a java file that combines both linearSearch and binarySearch •Both search methods must use the Comparable<T> interface and the compareTo() method.•Your program must be able to handle different data types, i.e., use generics.•For binarySearch, if you decide to use a midpoint computation formula that is different fromthe textbook, explain that formula briefly as a comment within your code. //code from textbook //linearSearch public static <T> boolean linearSearch(T[] data, int min, int max, T target) { int index = min; boolean found = false; while (!found && index <= max) { found = data [index].equals(target); index++; } return found; } //binarySearch public static <T extends Comparable<T>> boolean binarySearch(T[] data, int min, int max, T target) { boolean found = false; int midpoint = (min + max)/2; if (data[midpoint].compareTo(target)==0)…arrow_forwardQuestion 2 Get the Array ADT implementation from your textbook to work. Demonstrate that your code works as specified in the ADT. You are free to change internal names so that you can make better sense of the code provided in the textbook. You will need this code for later exercises Your implementation must provide _str_() and repr_() methods, in addition to the methods implemented in the textbook. The output of these methods must return each value separated with a comma in a string. For example, if the array has values 10, 12, 14, 16, and 18, these methods must return the string "10, 12, 14, 16, 18" Your code should support following operations: import random array = Array ( 100 ) for i in range( len( array ) ): # array[i] = random.random() # Print individual values in the array. # for value in array: # print(value) # Print the entire array. # print(array )arrow_forwardWhat is the difference between void and null pointers.Give suitable example in support of your answerarrow_forward
- Sally and Harry are developing a Coin version. Sally specifies that the type of the single parameter to her compareTo function is Object. Harry defines the parameter to be of type Coin since he is aware that it will always be called on objects of that type. Which approach is appropriate for putting Coin items into an OrderedVector?arrow_forwardIn C++, create a class for a 3-dimensional array. To make it more general, allow the actual dimensionality to be 0d, 1d, 2d, or 3d. It should support indexing with operator(). If the programmer subscripts with fewer indices than you 'need' (0 for a 1d, 0 or 1 for a 2d, 0 or 1 or 2 for a 3d -- note that you can't under-subscript a 0d array), you should return the appropriately sized sub-array (of your class's type). (Note: This will require multiple overloads of operator() with different numbers of index arguments.) Since, as a template, math operations don't make sense, you'll have to for-go addition, etc. But you could use + and += for concatenation. Basically aligning the common dimensions of the two arrays and concatenating along the remaining dimension. (There can be only one for this to make sense. If there are none remaining, there are options for those kinds of things!) Make sure to overload it for proper dimensionality: Of course, you should also support input (the programmer…arrow_forwardPlease provide the solution/code for the following screenshot. The language is used is Racket and please make sure to provide the definitions of all the functions. Please use recursion and set operation.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning