MYPROGRAMMINGLAB WITH PEARSON ETEXT
8th Edition
ISBN: 9780134225340
Author: Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 6, Problem 6.11E
(Bubble Sort) The bubble sort presented in Fig. 6.15 is inefficient for large arrays. Make the following simple modifications to improve its performance.
- After the first pass, the largest number is guaranteed to be ¡n the highest-numbered element of the array; after the second pass, the two highest numbers are “in place,” and so on. Instead of making nine comparisons on every pass, modify the bubble sort to make eight comparisons on the second pass, seven on the third pass and so on.
- The data in the array may already be in the proper or near-proper order, so why make nine passes if fewer will suffice? Modify the sort to check at the end of each pass whether any swaps have been made. If none has been made, then the data must already be in the proper order, so the program should terminate. If swaps have been made, then at least one more pass is needed.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
(Q7) This is a Data Structures problem and the programming language used is Lisp. Solve the question we detailed steps and make it concise and easy to understand. Please and thank you.
(Recursive Selection Sort) A selection sort searches an array looking for the smallest elementin the array. When that element is found, it’s swapped with the first element of the array. The process is then repeated for the subarray, beginning with the second element. Each pass of the arrayresults in one element being placed in its proper location. This sort requires processing capabilitiessimilar to those of the bubble sort—for an array of n elements, n – 1 passes must be made, and foreach subarray, n – 1 comparisons must be made to find the smallest value. When the subarray beingprocessed contains one element, the array is sorted. Write a recursive function selectionSort toperform this algorithm
bool ok(int q[])
which takes an array q and returns true if the array represents a valid configuration of the eight
queens and returns false otherwise.
4. Write a function
Chapter 6 Solutions
MYPROGRAMMINGLAB WITH PEARSON ETEXT
Ch. 6 - Fill in the blanks in each of the following: C...Ch. 6 - State which of the following are true and which...Ch. 6 - Write statements to accomplish each of the...Ch. 6 - Consider a 2-by-5 integer array t. Write a...Ch. 6 - (Sales Commissions) Use a one-dimensional array to...Ch. 6 - (Bubble Sort) The bubble sort presented in Fig....Ch. 6 - Write loops that perform each of the following...Ch. 6 - Prob. 6.13ECh. 6 - (Mean, Median and Mode Program Modifications)...Ch. 6 - (Duplicate Elimination) Use a one-dimensional...
Ch. 6 - Label the elements of 3-by-5 two-dimensional array...Ch. 6 - What does the following program do?Ch. 6 - What does the following program do?Ch. 6 - (Dice Rolling) Write a program that simulates the...Ch. 6 - (Game of Craps) Write a program that runs 1000...Ch. 6 - Prob. 6.21ECh. 6 - (Total Sales) Use a two-dimensional array to solve...Ch. 6 - (Turtle Graphics) The Logo language made the...Ch. 6 - Prob. 6.24ECh. 6 - (Knights Tour: Brute-Force Approaches) In Exercise...Ch. 6 - (Eight Queens) Another puzzler for chess buffs is...Ch. 6 - (Eight Queens: Brute-Force Approaches) In this...Ch. 6 - (Duplicate Elimination) In Chapter 12, we explore...Ch. 6 - (Knights Tour: Closed Tour Test) In the Knights...Ch. 6 - (The Sieve of Eratosthenes) A prime integer is any...Ch. 6 - Prob. 6.31RECh. 6 - (Linear Search) Modify the program of Fig. 6.18 to...Ch. 6 - (Binary Search) Modify the program of Fig. 6.19 to...Ch. 6 - Prob. 6.35RECh. 6 - Prob. 6.36RECh. 6 - Prob. 6.37RE
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The __________ file format is commonly used to export spreadsheet data to a text file. a. spreadsheet data volu...
Starting out with Visual C# (4th Edition)
True or False: All static member variables are initialized to 1 by default.
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Suppose that both a program and the hardware that executes it have been formally verified to be accurate. Does ...
Computer Science: An Overview (12th Edition)
FileArray Class Design a class that has a static method named writeArray. The method should take two arguments:...
Starting Out with Java: Early Objects (6th Edition)
What does the throw statement do?
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
In Exercises 17 through 28, write a line (or lines) of code to carry out the task.
Make lblTwo disappear.
Introduction To Programming Using Visual Basic (11th 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
- 9. Implement an array with values 1, 5, 14, 23, 45, 52, 58, 81, 82 91. a) Create a getindex( function which does a linear search upon the array for a specific value n. Return the index of n, or -1 ifn does not exist, b) Print the array. c) Search the array for the values 23, 58, 11, rint the reaults. Qutpur Examnle 15 14 23 45 52 58 71 82 91 Number 23 is located at index Number 58 As located at index C Number 11 i looated at index -1arrow_forward(Java) question 6arrow_forwardPlease complete code in Java per the instructions. Thank you!arrow_forward
- AIM: Write a program to do Linear Search using a given Search Key in an un- sorted Linear Array 'A' which has N values in it. Description: The linear search compares each element of the array with the search key until the search key is found. To determine that a value is not in the array, the program must compare the search key to every element in the array 'A'. It is also called "Sequential Search" because it traverses the data sequentially to locate the element. Algorithm: (Linear Search) LINEAR SEARCH (A, N, SKEY) Here A is a Linear Array with N elements and SKEY is a given item of information to search. This algorithm finds the location of SKEY in A and if successful, it returns its location otherwise it returns -1 for unsuccessful. 1. Repeat step-2 for K = 0 to N-1 2. if(A [K] = SKEY) return K [Successful Search] [End of loop of step-1 ] 3. return -1 [Un-Successful] 4. End.arrow_forward(Locate the largest element) Write the following function that finds the location of the largest element in a two-dimensional array. void 1ocateLargest(const double a[][4 ], int 1ocation[]) The location is stored in a one-dimensional array location that contains two elements. These two elements indicate the row and column indices of the largest element in the two-dimensional array. Write a test program that prompts the user to enter a 3 × 4 two-dimensional array and displays the location of the largest element in the array.arrow_forward(Compute total marks for each student) Suppose the marks obtained by all students are stored ina two-dimensional array. Each row records a student’s marks for five tests. For example, the followingarray stores the test marks for eight students. Write a program that displays students and the totalmarks they obtained in five tests, in decreasing order of the total marks.arrow_forward
- 9. Write function getMoveRow to do the following a. Return type integer b. Parameter list i. 1-d character array (i.e. move), size 3 c. Convert the row portion of the player’s move to the associated integer index for the board array d. Example: i. move = ‘b2’ ii. 2 is the row iii. 2 is index 1 in the board array e. Return the row array index that corresponds to the player’s move f. Return a -1 if the row is not valid (i.e. INVALID) 10. Write function getMoveCol to do the following a. Return type integer b. Parameter list i. 1-d character array (i.e. move), size 3 c. Convert the column portion of the player’s move to the associated integer index for the board array d. Example: i. move = ‘b2’ ii. b is the column iii. b is index 1 in the board array e. Return the column array index that corresponds to the player’s move f. Return a -1 if the column is not valid (i.e. INVALID) I am getting an error when entering the code at the very end. please fix it. This is the code in C int…arrow_forward9. Consider a 2-by-5 integer array t (. a. Write a definition for t. b. How many rows does t have? c. How many columns does t have? d. How many elements does t have? e. Write the names of all the elements in the second row of t. f. Write the names of all the elements in the third column of t. g. Write a single statement that sets the element of t in row 1 and column 2 to zero. h. Write a series of statements that initialize each element of t to zero. Do not use an iteration statement. i. Write a nested for statement that initializes each element of t to zero. j. Write a statement that inputs the values for the elements of t from the terminal. k. Write a series of statements that determine and print the smallest value in array t. I. Write a statement that displays the elements of the first row of t. m. Write a statement that totals the elements of the fourth column of t. n. Write a series of statements that print the array t in tabular format. List the column indices as headings across…arrow_forwardIn C++arrow_forward
- (Bucket Sort) A bucket sort begins with a one-dimensional array of positive integers to besorted, and a two-dimensional array of integers with rows subscripted from 0 to 9 and columns subscripted from 0 to n – 1, where n is the number of values in the array to be sorted. Each row of thetwo-dimensional array is referred to as a bucket. Write a function bucketSort that takes an integerarray and the array size as arguments.The algorithm is as follows:a) Loop through the one-dimensional array and place each of its values in a row of thebucket array based on its ones digit. For example, 97 is placed in row 7, 3 is placed inrow 3 and 100 is placed in row 0.b) Loop through the bucket array and copy the values back to the original array. The neworder of the above values in the one-dimensional array is 100, 3 and 97.c) Repeat this process for each subsequent digit position (tens, hundreds, thousands, andso on) and stop when the leftmost digit of the largest number has been processedarrow_forward90. Mos.arrow_forward30.// programming Write a function void reverse(int a[ ], int size) to reverse the elements in array a, the second parameter size is the number of elements in array a. For example, if the initial values in array a is {5, 3, 2, 0}. After the invocation of function reverse(), the final array values should be {0, 2, 3, 5} In main() function, declares and initializes an integer array a with{5, 3, 2, 0}, call reverse() function, display all elements in final array a. Write the program on paper, take a picture, and upload it as an attachment. Or just type in the program in the answer area. m861144 m861144arrow_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
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License