Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 18, Problem 18.34PE
(Game: Eight Queens) The Eight Queens problem is to find a solution to place a queen in each row on a chessboard such that no two queens can attack each other. Write a
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
2, Towers of Hanoi Problem. (10 points)
The Towers of Hanoi is a famous problem for studying recursion in
computer science and searching in artificial intelligence. We start with N
discs of varying sizes on a peg (stacked in order according to size), and two
empty pegs. We are allowed to move a disc from one peg to another, but we
are never allowed to move a larger disc on top of a smaller disc. The goal is
to move all the discs to the rightmost peg (see figure). To solve the problem
by using search methods, we need first formulate the problem. Supposing
there are K pegs and N disk. Answer the following questions.
(1) Determine a state representation for this problem. (4points)
(2) What is the size of the state space? (3 points)
(3) Supposing K=3, N=4, what is the start state by using your proposed
state representation method and what is the goal state? (3 points)
АСTIVITY 3
RECURSION
Instructions: Use any size of bond paper. Write your name, course and year, date in your
answer sheets. Use ALL CAPS.
I.
Recursion: Prove the following using recursion.
1. Ifg is defined recursively by g(0) = 3 and g(n + 1) = 2" – n. Find
g(1), g(3), g(5), g(7) and g(9)
Exercise 1: (Design of algorithm to find greatest common divisor)
In mathematics, the greatest common divisor (gcd) of two or more integers
is the largest positive integer that divides each of the integers.
For example, the gcd of 8 and 12 is 4. Why?
Divisors of 8 are 1, 2, 4, 8.
Divisors of 12 are 1, 2, 4, 6, 12
Thus, the common divisors of 8 and 12 are 1, 2, 4.
Out of these common divisors, the greatest one is 4. Therefore, the greatest
common divisor (gcd) of 8 and 12 is 4.
Write a programming code for a function FindGCD(m,n) that find the greatest
common divisor. You can use any language of Java/C++/Python/Octave.
Find GCD Algorithm:
Step 1 Make an array to store common divisors of two integers m, n.
Step 2 Check all the integers from 1 to minimun(m,n) whether they divide
both m, n. If yes, add it to the array.
Step 3 Return the maximum number in the array.
Chapter 18 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global 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
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What is the purpose of the let constructs in functional languages?
Concepts Of Programming Languages
A derived class inherits the ________ of its base class.
Starting Out with C++ from Control Structures to Objects (9th Edition)
Big data Big data describes datasets with huge volumes that are beyond the ability of typical database manageme...
Management Information Systems: Managing The Digital Firm (16th Edition)
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
Show a snippet of PHP code for displaying the contents of a recordset. Explain the meaning of the code.
Database Concepts (8th Edition)
What character does a comment begin with in Visual Basic?
Starting Out With Visual Basic (8th Edition)
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
- (Recursion and Backtracking) Write the pseudo code for a recursive method called addB2D that takes two binary numbers as strings, adds the numbers and returns the result as a decimal integer. For example, addB2D(‘‘101’’, ‘‘11’’) should return 8 (because the strings are binary representation of 5 and 3, respectively). Your solution should not just simply convert the binary numbers to decimal numbers and add the re- sults. An acceptable solution tries to find the sum by just directly processing the binary representations without at first converting them to decimal values.arrow_forward4. CodeW. X b For fun X Solved x b Answer x+ Ohttps://codeworko... CodeWorkout X264: Recursion Programming Exercise: Multiply For function multiply,write the missing base case condition and action. This function will multiply two numbers x and y.You can assume that both x and y are positive. Examples: multiply(2, 3) -> 6 Your Answer: 1 public int multiply(int x, int y) { 2. if > { > } else { return multiply(x 1, y) + y; 3. 5. { 7. 1:08 AM 50°F Clear 日arrow_forwardProgramming Language C Note:No Need for Detailed Explanation. The Answer is Enough For Me.Solve according to this information. (No: 2012010206083)arrow_forward
- PYTHON RECURSIVE FUNCTION Write a python program that lists all ways people can line up for a photo (all permutations of a list of strings). The program will read a list of one word names, then use a recursive method to create and output all possible orderings of those names, one ordering per line. When the input is: Julia Lucas Mia then the output is (must match the below ordering): Julia Lucas Mia Julia Mia Lucas Lucas Julia Mia Lucas Mia Julia Mia Julia Lucas Mia Lucas Juliaarrow_forwardProblem 2 -- Recursive Palindrome (Grey + Scarlet) Write a recursive method, isPalindrome, which takes a String as a parameter, and returns true if the String is a palindrome. For the purposes of this method, you may assume Strings with a length of o or 1 are palindromes.arrow_forward12:09 9 & K all 86%i Asgn5 Part 2- recursion For this part, you have 2 small programs to write (independent of each other). In both cases, write only one class, with one recursive static method and one main method. The main method should have some example code showing how the recursive method is called, with hardcoded values. 1. Write a recursive method that calculates the total space used by all files under a given folder (or directory), including all files that are accessible from it when traversing down some subfolders. Here are some methods that could help you here, that are part of the class "File": isFile() : returns true if the file is a regular file (not a directory) isDirectory() : returns true if the file is a directory length() : returns a value of type "long" (not int), that is the number of bytes taken by the file. Note that it has to be called on a normal file only, not on a directory. listFiles() : called on a directory, it returns an array of File objects corresponding…arrow_forward
- CodeW X b For func x C Solved X b Answer X https://codeworkou... CodeWorkout X270: Recursion Programming Exercise: Count Characters For function countChr() write the missing part of the recursive call. This function should return the number of times that the letter "A" appears in string "str". Recall that str.substring(a) will return the substring of str from position a to the end of str, while str.substring (a, b) will return the substring of str starting at position a and continuing to (but not including) the character at position b. Examples: countChr ("ctcoWCAt") -> 1 Your AnsSwer: 1 public int countChr(String str) { 2. if (str.length() return 0; } (0 4. { int count = 0; www. 5. 9. if (str.substring(0, 1).equals("A")) { count = 1 7. { 9. return count + > 1:10 AM 50°F Clear 12/4/2021 呼arrow_forwardUse the recursion to solve the following problems 1. Calculate the sum of an array of n integers. 2. Compute Powers, p(x,n)=xn 3. Revers an array of n integers 4. Calculate the length of string (number of characters) 5. Implement the tail recursion for problems 1 and 2. Please test the program by using 2 different input sets!arrow_forwardTask 4: The first problem that you solve recursively is to implement enoughGate() to check if the dogMaze has at least two gates (one for the entrance and one for the exit). This problem must be solved recursively, however there is no limitation on what type of recursion (i.e., direct or indirect recursion) you use . As a reminder, a direct recursion refers to the function that calls itself to solve the given problem. However, by indirect recursion, more than one function involves in solving the problem. It is possible that a non-recursive function solves a small part of the problem and then calls the recursive function to finish the job. /** * This method returns true if the number of * gates in dogMaze >= 2. * @return it returns true, if enough gate exists (at least 2), otherwise false. */ publicboolean enoughGate (){ // insert your code here. Change the return value to fit your purpose. return true; }arrow_forward
- T/F 11. A recursion will still be replaced by an iteration and the other way around.arrow_forwardExercise 1: The number of combinations CR represents the number of subsets of cardi- nal p of a set of cardinal n. It is defined by C = 1 if p = 0 or if p = n, and by C = C+ C in the general case. An interesting property to nxC calculate the combinations is: C : Write the recursive function to solve this problem.arrow_forwardplease write and explain the code in Carrow_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 LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License