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 22.9, Problem 22.9.2CP
Program Plan Intro
Eight Queen Problem:
- The eight queen problem is to place “8” Queens in “8X8” chessboard such that no queen would attack other one.
- There are possibly “92” solutions. But some of these are reflections or rotations of other.
- There are possibly “12” distinct solutions without any refection or rotation similarities.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The puzzle called the Towers of Hanoi consists of three pegs, one of which contains several rings stacked in order of descending diameter from bottom to top.
The problem is to move the stack of rings to another peg. You are allowed to move only one ring at a time, and at no time is a ring to be placed on top of a smaller one. Observe that if the puzzle involved only one ring, it would be extremely easy.
Moreover, when faced with the problem of moving several rings, if you could move all but the largest ring to another peg, the largest ring could then be placed on the third peg, and then the problem would be to move the remaining rings on top of it.
Using this observation, develop a recursive algorithm for solving the Towers of Hanoi puzzle for an arbitrary number of rings.
Subject: Analysis & Design of Algorithms
Solve Using Python
Note: I want the output to be the same as shown in the screenshot.
Shrek has guessed three positive integers a, b, and c. He keeps these numbers in secret, but he
writes down four numbers on a board in arbitrary order their pairwise sums (three numbers) and sum
of all three numbers (one number). So, there are four numbers on a board in random order: a + b, a+
c, b + c and a+b+c.
You have to guess three numbers a, b, and c using given numbers. Print three guessed integers in any
order. Pay attention that some given numbers a, b and c can be equal (it is also possible that a-b=c).
Instruction: Create a Java program that will perform the algorithm that will solve the problem using
inheritance as shown in the figure. It must satisfy the 3-sample output as shown below. Explain your codes
using comments.
Main class Creates an instance of "Number"
class and call the methods. in
Input
sequence as shown in the figure.
numl, num2, num3, num4 :int
●
Main
Input class - It contains a method in() that ask
four positive integers for the numbers
on the board in…
Chapter 22 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 22.2 - Prob. 22.2.1CPCh. 22.2 - What is the order of each of the following...Ch. 22.3 - Count the number of iterations in the following...Ch. 22.3 - How many stars are displayed in the following code...Ch. 22.3 - Prob. 22.3.3CPCh. 22.3 - Prob. 22.3.4CPCh. 22.3 - Example 7 in Section 22.3 assumes n = 2k. Revise...Ch. 22.4 - Prob. 22.4.1CPCh. 22.4 - Prob. 22.4.2CPCh. 22.4 - Prob. 22.4.3CP
Ch. 22.4 - Prob. 22.4.4CPCh. 22.4 - Prob. 22.4.5CPCh. 22.4 - Prob. 22.4.6CPCh. 22.5 - Prob. 22.5.1CPCh. 22.5 - Why is the recursive Fibonacci algorithm...Ch. 22.6 - Prob. 22.6.1CPCh. 22.7 - Prob. 22.7.1CPCh. 22.7 - Prob. 22.7.2CPCh. 22.8 - Prob. 22.8.1CPCh. 22.8 - What is the difference between divide-and-conquer...Ch. 22.8 - Prob. 22.8.3CPCh. 22.9 - Prob. 22.9.1CPCh. 22.9 - Prob. 22.9.2CPCh. 22.10 - Prob. 22.10.1CPCh. 22.10 - Prob. 22.10.2CPCh. 22.10 - Prob. 22.10.3CPCh. 22 - Program to display maximum consecutive...Ch. 22 - (Maximum increasingly ordered subsequence) Write a...Ch. 22 - (Pattern matching) Write an 0(n) time program that...Ch. 22 - (Pattern matching) Write a program that prompts...Ch. 22 - (Same-number subsequence) Write an O(n) time...Ch. 22 - (Execution time for GCD) Write a program that...Ch. 22 - (Geometry: gift-wrapping algorithm for finding a...Ch. 22 - (Geometry: Grahams algorithm for finding a convex...Ch. 22 - Prob. 22.13PECh. 22 - (Execution time for prime numbers) Write a program...Ch. 22 - (Geometry: noncrossed polygon) Write a program...Ch. 22 - (Linear search animation) Write a program that...Ch. 22 - (Binary search animation) Write a program that...Ch. 22 - (Find the smallest number) Write a method that...Ch. 22 - (Game: Sudoku) Revise Programming Exercise 22.21...Ch. 22 - (Bin packing with smallest object first) The bin...Ch. 22 - Prob. 22.27PE
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
- Basics of Nested Lists in Python Problem Description Consider an 8 × 8 table for a board game. Using two nested loops, initialize the board so that zeroes and ones alternate, as on a checkerboard: 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 . . . 1 0 1 0 1 0 1 0 Hint: Check whether i + j is even. In Python Pleasearrow_forwardIn computer science and mathematics, the Josephus Problem (or Josephus permutation) is a theoretical problem. Following is the problem statement: There are n people standing in a circle waiting to be executed. The counting out begins at some point (rear) in the circle and proceeds around the circle in a fixed direction. In each step, a certain number (k) of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom. Given the total number of persons n and a number k which indicates that k-1 persons are skipped and kth person is killed in circle. The task is to choose the place in the initial circle so that you are the last one remaining and so survive. For example, if n = 5 and k = 2, then the safe position is 3. Firstly, the person at position 2 is killed, then person at position 4 is killed, then person at position 1…arrow_forwardplease help with the python problem, thank youarrow_forward
- Using the recursion three method find the upper and lower bounds for the following recur- rence (if they are the same, find the tight bound). T(n) = T(n/2) + 2T(n/3) + n.arrow_forwardMemoization technique is one of the popular techniques that improve the performance of the recursive algorithms. When applied to a recursive problem how does it affect overall performance? Time complexity decreases and the space complexity increases Time complexity decreases and the space complexity decreases Time complexity increases and the space complexity decreases Time complexity increases and the space complexity increasesarrow_forwardsolve recursion where t(0) = 0 and t(1) = 4 sqrt 5arrow_forward
- I have no problem finding for the recursion version but for iteration I am unable to do so as the results are different. def gibonacci_R(n):if n <= 1 :return 0elif n == 2 :return 1else:return gibonacci_R(n-1) + gibonacci_R(n-3) def gibonacci_I(n):if n <= 1 :return 0elif 2 <= n < 4:return 1x = 1y = 0for i in range (4,n+1,1):current = xy = x x = currentreturn current I should be getting: gibonacci_I(4) == 1 gibonacci_I(5) == 2 gibonacci_I(6) == 3 gibonacci_I(7) == 4 gibonacci_I(8) == 6 gibonacci_I(9) == 9 gibonacci_I(10) == 13 gibonacci_I(11) == 19 gibonacci_I(12) == 28 gibonacci_I(13) == 41 gibonacci_I(14) == 60 gibonacci_I(15) == 88arrow_forwardExplain carefully the time complexity to compute f(n) using recursion only.arrow_forwardSuppose you are to make change for the amount 1234 with the smallest possible number of coins. The coin values you have available to you are 1, 17, and 29. In implementing a recursive solution mincoins( n ), what three values of n would be used for the three recursive calls of mincoins()? Smallest: Next: Largest: This straight recursive implementation would have exponential runtime because results are computed repeatedly. One speedup technique would be to make a table and store intermediate results when they are computed, so they don't need to be computed again. What is this technique called? Another speedup technique involves computing mincoins(1), mincoins(2), mincoins(1234). What is this technique called?arrow_forward
- For the following problem please write an algorithm in plain English .i.e give details as to how you will solve the problem.A deck of 52 playing cards (as used for playing bridge) has to be sorted. At the end of the attempt, the sorted deck of cards should be on the table with the backside up.The order within a suite is Ace - King - Queen - Jack- 10 -9 - 8 - 7- 6- 5- 4- 3- 2. The very first card in the sorted deck is the Ace of Clubs, the next ones are the King of Clubs, the Queen of Clubs, the Jack of Clubs, the 10 of Clubs ... down to the 2 of Clubs. The next card is Ace of Spades, followed by the King of Spades etc. The hearts and diamonds cards follow in the same order.The deck of cards must be well-shuffled immediately prior to the challenge.Please write the algorithm in steps like you write a recipe for a dish.If any steps need to be repeated try to use a loop.Please try to not use any programming language.(IT's one question just with a lot of instructions to be understood well)arrow_forwardGiven base and n that are both 1 or more, compute recursively (no loops) the value of baseto the n power, so powerN(3, 2) is 9 (3 squared).powerN(3, 1) → 3powerN(3, 2) → 9powerN(3, 3) → 27Write code in Java or Python for this problemarrow_forwardMake a cpp program to solves the Towers of Hanoi puzzle using this recursiveapproach. It communicates the moves by displaying them; this requires much less code than displaying the towers graphically. It’s up to the human reading the list to actually carry out the movearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
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