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 23.5, Problem 23.5.4CP
Program Plan Intro
Sorting:
Sorting is a process where the elements of a list are arranged in a particular order. The order of the list can be either present in the ascending order or descending order.
Quick sort:
- The
algorithm works by selecting a pivot element from the array. - The array is being divided into two parts such that the element present at the first part of the array will be less than pivot and the elements that are present at the second part of the array are greater than the pivot element.
- The process is made in recursive way to the first half and second half of the list until the complete list is sorted.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that benchmarks QuickSort and InsertionSort. You should use at least 5 different data sets and record the performance of each algorithm on the same sets under the same conditions. Write a short report that compares the two algorithms based your results. It is important to include a discussion of the initial states of the data sets in your report.
language Java
public class week3 {public static void main(String args[]){ //========================================================== //Question 1 testing //================== // Comment on benchmarking for Q1 results // // //========================================================== } static void quickSort(int f[], int p, int q){ if(q-p <= 1) ; //skip else{ int x; int i, j, k; // let x = middle element in f[p..q-1] x = f[(p+q)/2]; //x = f[p]; i = p; j = p; k = q; while(j != k){ if(f[j] == x) j = j + 1; else if(f[j] < x){ //swap f[j] with f[i] int temp; temp = f[j]; f[j] = f[i]; f[i] = temp; j = j + 1; i = i + 1; } else{…
Solve this using python. For the problem, take sample input from the picture into a file called
"input.txt" and save the output in the "output.txt" file.
USE PYTHON:
Implement a "guess-the-number" game using binary search: I think of a number between 1 and 10, your program guesses a number and I reply whether my number is higher or lower. Your program makes a new guess and so on until it guesses the right number. Then extend your program so that I can pick any positive number, not just ones up to 10.
Chapter 23 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 23.2 - Prob. 23.2.1CPCh. 23.2 - Prob. 23.2.2CPCh. 23.2 - Prob. 23.2.3CPCh. 23.3 - Prob. 23.3.1CPCh. 23.3 - Prob. 23.3.2CPCh. 23.3 - Prob. 23.3.3CPCh. 23.4 - Prob. 23.4.1CPCh. 23.4 - Prob. 23.4.2CPCh. 23.4 - What is wrong if lines 615 in Listing 23.6,...Ch. 23.5 - Prob. 23.5.1CP
Ch. 23.5 - Prob. 23.5.2CPCh. 23.5 - Prob. 23.5.3CPCh. 23.5 - Prob. 23.5.4CPCh. 23.6 - Prob. 23.6.1CPCh. 23.6 - Prob. 23.6.2CPCh. 23.6 - Prob. 23.6.3CPCh. 23.6 - Prob. 23.6.4CPCh. 23.6 - Prob. 23.6.5CPCh. 23.6 - Prob. 23.6.6CPCh. 23.6 - Prob. 23.6.7CPCh. 23.6 - Prob. 23.6.8CPCh. 23.6 - Prob. 23.6.9CPCh. 23.7 - Prob. 23.7.1CPCh. 23.7 - Prob. 23.7.2CPCh. 23.8 - Prob. 23.8.1CPCh. 23 - Prob. 23.1PECh. 23 - Prob. 23.2PECh. 23 - Prob. 23.3PECh. 23 - (Improve quick sort) The quick-sort algorithm...Ch. 23 - (Check order) Write the following overloaded...Ch. 23 - Prob. 23.7PECh. 23 - Prob. 23.8PECh. 23 - Prob. 23.10PECh. 23 - Prob. 23.11PECh. 23 - Prob. 23.12PECh. 23 - Prob. 23.13PECh. 23 - (Selection-sort animation) Write a program that...Ch. 23 - (Bubble-sort animation) Write a program that...Ch. 23 - (Radix-sort animation) Write a program that...Ch. 23 - (Merge animation) Write a program that animates...Ch. 23 - (Quicksort partition animation) Write a program...Ch. 23 - (Modify merge sort) Rewrite the mergeSort method...
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
- Implement the first round of AES ( Advanced Encryption Standard ) in python. Given a message with 128 bits, two subkeys subkey0 and subkey1, your program should be able to perform one AddKey before Round 1 and the corresponding operations (SubBytes, ShiftRows, Mix-Columns, and AddKey) in Round 1, and output the result of the encryption after Round 1.arrow_forwardWrite a program to read several lines from a file. For each line, check (recursively) whether it is a palindrome. If it is a palindrome output the original string preceded by an integer (a counter) , like this: 1 : Sore was I, ere I saw Eros.2 : A man, a plan, a canal -- Panama Recall that a palindrome is a String that is the same backwards and forwards. Some examples of single words that are palindromes are: level, madam, racecar Phrases can also be palindromes if you strip out all the whitespace and punctuation and make everything the same case. Some examples are: Madam, I'm Adam A Toyota's a Toyota (See the palindrome video for more) You will need one method to eliminate whitespace and punctuation , make everything lowercase, and return the new string. Use the recursive method you wrote in L15Num2. This returns a string with no whitespace or punctuation, but not all the same case. Then (in main) convert that string to lowercase. You need a recursive method that takes the new…arrow_forwardImagine a ballroom with two kinds of dancers: leaders and followers. Dancers of both kinds wait in two separate queues before entering the dance floor. When a leader arrives, it checks to see if there is a follower waiting. If so, they can both proceed. Otherwise it waits. Similarly, when a follower arrives, it checks for a leader and either proceeds or waits, accordingly. Make sure that the next pair of leader/follower may dance only after the previous pair is done.Write the pseudocode for leaders and followers that enforces these constraints.arrow_forward
- Write Python commands, within a print command, that output the following. (E.g. print(list(range(10))) , in spyder (vi) Let x = [1,3,5] and let y = [2,4,6]. If we interpret these as vectors x and y then the vector sum can be written x + y = [x[0]+y[0],x[1]+y[1],x[2]+y[2]]. Find an the equivalent expression for the vector dot product x⋅y. (vii) With x,y as above find an expression for the vector cross product x * y.arrow_forwardPython Please. An interesting puzzler for chess buffs is the Knight’s Tour problem, originally proposed by the mathematician Euler. Can the knight piece move around an empty chessboard and touch each of the 64 squares once and only once? We study this intriguing problem in depth here. The knight makes only L-shaped moves (two spaces in one direction and one space in a perpendicular direction). Thus, as shown in the figure below, from a square near the middle of an empty chessboard, the knight (labeled K) can make eight different moves (numbered 0 through 7). A: Draw an eight-by-eight chessboard on a sheet of paper, and attempt a Knight’s Tour by hand. Put a 1 in the starting square, a 2 in the second square, a 3 in the third, and so on. Before starting the tour, estimate how far you think you’ll get, remembering that a full tour consists of 64 moves. How far did you get? Was this close to your estimate? B: Now let’s develop a script that will move the knight around a chessboard…arrow_forwardUsing a csv file attached (https://file.io/NMvbdnv4E3r0), Create a program on python that use the csv file. The program should accept a user's input of a compound. It should output the molar mass (in 2 decimal places only) of the compound.by using the csv file to compute for the atomic mass at name of the elements. Furthermore, if the "elements involved" are wrong an invallid message should be outputted and only existing chemical symbols are the output. The same goes for wrong input of the "number of atoms" wherein a wrong an invallid message should be outputted and only integers are to be inputted by the user. Program should look like this: Enter compound: C6H12O6 Enter elements involved: C,H,O Enter no. of Carbon atoms: AA Enter no. of Hydrogen atoms: 12 Enter no. of Oxygen atoms: 6 Wrong input of number of atoms! Try again. or Enter compound: C6H12O6 Enter elements involved: C,H,O Enter no. of Carbon atoms: 6 Enter no. of Hydrogen atoms: 12 Enter no. of Oxygen atoms: 6…arrow_forward
- Implement the"paint fill"function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color.arrow_forwardPlease help me Josephus Problem is a theoretical problem related to a certain counting-out game. On thiscase, people are standing in a circle waiting to be executed. After a specified number ofpeople are skipped, the next person is executed. The procedure is repeated with theremaining people, starting with the next person, going in the same direction and skippingthe same number of people, until one person remains, and is freed.Arrange the numbers 1 , 2, 3 , ... consecutively (say, clockwise) in a circle. Now removenumber 2 and proceed clockwise by removing every other number, among those thatremain, until one number is left. (a) Let denote the final number which remains. Find formula for .(b) If there are 70 people, what is the safe number (the number that remains)?arrow_forwardYou are in the process of choosing between two 3rd party libraries that implement some algorithm and have found two solutions, A and B, that are advertised as O(n) and ~n, respectively. Which of these solutions would you prefer in terms of performance? Explain. (Hint: think about which one gives a more "stable" result.)arrow_forward
- Only need the ans for 1. Solve this using python. For the problem, take sample input from the picture into a file called "input.txt" and save the output in the "output.txt" file.arrow_forwardCreate and implement a different solution to the use of semaphores using pseudocode or some preferred language for the following approach: Five philosophers sit around a table and spend their lives dining and thinking. Each philosopher has a bowl of noodles and a fork to the left of your plate. To eat the noodles you need two forks and each philosopher you can only take the ones to your left and right. If any philosopher takes a fork and the other is busy, he will wait, fork in hand, until pick up the other fork, so you can start eating later. If two adjacent philosophers try to pick up the same fork at the same time, a race condition: they both compete to take the same fork, and one of them left without eating. If all the philosophers take the fork to their right at the same time, then everyone will be waiting forever, because someone must release the fork that is lack. No one will because everyone is in the same situation (hoping that someone put down their forks). Then the…arrow_forwardwrite a java program (method) to store all arrangments(permuations) of a given string in an array. note: Here it has to be mentioned that the permutations can also be of shorter length than the list of letters and that no letter is to be repeated. For example, if the initial list of letters is "STOP", then "TOP" and "TOPS" are both valid permutations, but "STOPS" isn't.arrow_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