The bubble sort is an inefficient, but easy-to-program, sorting technique. The idea behind the sort is to move down through an array comparing adjacent pairs and swapping the values if they are out of order. For this method to sort the array completely, it may need to pass through it many times. As the passes proceed for an ascending-order sort, the smaller elements in the array appear to rise toward the top like bubbles. Eventually, there will be a pass through the array where no swaps are required. Then, the array is sorted. After the first pass, the largest value in the array drops directly to the bottom. Consequently, the second pass only has to proceed to the second-to-last value, and so on. Develop a program to set up an array of 20 random numbers and sort them in ascending order with the bubble sort (Fig. P2.12).
FIGURE P2.12
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
INTERNATIONAL EDITION---Numerical Methods for Engineers, 7th edition
Additional Math Textbook Solutions
Basic Technical Mathematics
Fundamentals of Differential Equations (9th Edition)
Advanced Engineering Mathematics
Thinking Mathematically (6th Edition)
- A company has three machines, A, B, and C, that are each capable of producing a certain item. However, because of a lack of skilled operators, only two of the machines can be used simultaneously. The following table indicates production over a three-day period, using various combinations of the machines. How long would it take each machine, if used alone, to produce 1000 items?arrow_forwardA iPhone store starts by selling 100 iPhone pre-ordered in week zero and expects to sell an average of 15%more each week after that. How many iPhone is the store expected to sell in week 4?arrow_forwardWhile you are on a 4-week vacation, you will play at least one set of tennis matches each day, but you wouldn’t play more than forty sets total during this time. Prove that no matter how you distribute your games during the four weeks, there is a span of consecutive days during which you will play exactly 15 games.arrow_forward
- How do i find the occupancy rate for multiple lots? This spreadsheets contains more lots than given. I only provided are part of lot 1 and a part of lot 2 because the file is too large. They all run together in one file and need the occupancy rate which is column D on my spreadsheet. LotCode LotCapacity LotOccupancy OccupancyRate TimeStamp Day Lot01 863 174 11/20/2016 8:01 Sunday Lot01 863 179 11/20/2016 8:27 Sunday Lot01 863 189 11/20/2016 9:01 Sunday Lot01 863 197 11/20/2016 9:27 Sunday Lot01 863 226 11/20/2016 10:01 Sunday Lot01 863 247 11/20/2016 10:27 Sunday Lot01 863 331 11/20/2016 11:01 Sunday Lot01 863 400 11/20/2016 11:27 Sunday Lot01 863 469 11/20/2016 12:01 Sunday Lot01 863 510 11/20/2016 12:34 Sunday Lot01 863 594 11/20/2016 13:07 Sunday Lot01 863 618 11/20/2016 13:27 Sunday Lot01 863 637 11/20/2016 14:01 Sunday Lot01 863 655 11/20/2016 14:27 Sunday Lot01 863 634 11/20/2016 15:01 Sunday Lot01 863 597…arrow_forwardSuppose that a region has two hospitals. Hospital A has about 10 births per day, and hospital B has about 50 births per day. About 50% of all babies are boys, but the percentage who are boys varies at each hospital from day to day. Over the course of a year, which hospital will have more days on which 60% or more of the births are boys? The smaller Hospital A, the larger B, or will Hospital A and B have nearly the same number of days?arrow_forwardSuppose that the number of students in a class increase by 2, the number of ways they may be arranged randomly would increase 90 times. How many students were there originally?arrow_forward
- In volleyball, players on the same team rotate through all positions so no particular player is assigned a particular position. Suppose you are the coach of team which consists of twelve players and six players are on the court at any particular time. From how many differnt six player teams can you choose to the the court?arrow_forwardSuppose we want to choose 5 objects, with replacement for 8 distinct objects. If the order of these choices does not matter how many time can this be done? And if it does matter?arrow_forward
- Linear Algebra: A Modern IntroductionAlgebraISBN:9781285463247Author:David PoolePublisher:Cengage LearningAlgebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal Littell