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
EBK NUMERICAL METHODS FOR ENGINEERS
Additional Engineering Textbook Solutions
Math in Our World
Pathways To Math Literacy (looseleaf)
Precalculus
Precalculus: Mathematics for Calculus (Standalone Book)
Elementary and Intermediate Algebra: Concepts and Applications (7th Edition)
College Algebra (7th Edition)
- Suppose your CFD code can handle nonelementary blocks. Combine as many blocks of Fig. as you can. The only restriction is that in any one block, the number of i-intervals and the number of j-intervals must be constants. Show that you can create a structured grid with only three nonelementary blocks. Renumber all the blocks and indicate how many i- and j-intervals are contained in each block. Add up all the cells and verify that the total number of cells does not change.arrow_forwardQuestion 4 List the steps in details to draw the shape below using AutoCAD commands 190 220 50 -90 - 50 114 81 R80 450 122 -R125 68 65 290 50 290 630arrow_forwardIn your own words with no google, how do you add vectors using parallelogram method graphicallyarrow_forward
- Let there be five jobs of the same type and one machine to get those jobs done. The processing time of the job on the machine and the time allowed for the job to be completed for each job are given in the table below. Job On the machinecompletion time(minute) Allowed To be finishedtime (minute) 1 3 4 2 6 8 3 8 12 4 4 15 5 2 11 Apply the branch-and-boundary method step by step to order the jobs in a way that minimizes the total delay time. State the optimal solution clearly. Thank you so much.arrow_forwardCreate the following images in AUTOCAD using web.autocad.com (Take screenshots of your work.) Design 3 6.50 1.50-- 3.50 1.00 1.00 4.00 1.00 1.75 2.75 4.75arrow_forwardThe following tools / resources may be useful for you to complete the assignment:a. Chatgpt (You may use it to learn Matlab coding or any other computer language. An example is given here: https://shareg.pt/mXHGne9 ). Please take note that code generated by chatgpt can be directly copied and pasted.b. Matlabi) Useful cheat sheet (https://n.ethz.ch/~marcokre/download/ML-CheatSheet.pdf)ii) Getting started with Matlab (https://matlabacademy.mathworks.com/en/details/gettingstarted )iii) Getting 30-day Matlab trial license (https://www.mathworks.com/campaigns/products/trials.html ) iv) Polyfit (https://www.mathworks.com/help/matlab/ref/polyfit.html )v) Exponential Fit (https://www.mathworks.com/matlabcentral/answers/91159-how-do-i-fit-an-exponential-curve-to-my-data)c. PlotDigitizer (https://plotdigitizer.sourceforge.net/ ) or a free online app that does not requires installation (https://plotdigitizer.com/app )You may use your own engineering judgement to make any assumptions on any…arrow_forward
- Please help, this for Matlab the image is the first question with following 2 and 3 they go together. 2. Solving the question by using bisection.m with the stopping criterion at 1%. Report the root and # of iterations. 3. by using newton-Raphson matlab script with the stopping criterion at 0.1%. Report the root and # of iterations.arrow_forwardI having a problem with my code in MATLAB. In the following code results for r is just a 1x3 matrix. Although inside the while loop r equals to multiple 1x3 matrices. I need r equal to one matrix that is of size 27032x3. So, I just need the multiple r matrices to merge together to get one big matrix. I need that matrix to retain its value outside the while loop as well. cc=0; % set line counter JD = 2460626.666667; fid = fopen('tle_catalog.txt'); % load the TLE tline2='gg'; while ischar(tline2) cc = cc+1; % counter name = fgets(fid);% for the ones with three lines tline1 = fgets(fid); % collect first line of two line elements tline2 = fgets(fid); % collect second line of two line elements if tline2>0 % stop at the end of the file % initialize the propagation [satrec, startmfe, stopmfe, deltamin] ... = twoline2rv(721, tline1, tline2, 'c', 'd'); time_JD = tline1(21:32); yeardayhour = str2double(regexp(tline1, '(\d{2})(\d{3})(\.\d+)', 'tokens', 'once')); dn =…arrow_forwardRead and solve carefully please write clearly and box the final answer (remember to make the block diagram)arrow_forward
- Could you please fix my code it’s supposed to look like the graph that’s on the picture. But the lines do not cross eachother at the beginning. Could you make the lines look like the lines on the graph? Use this code in MATLAB and fix it. % Sample data for Diesel and Petrol cars carPosition = linspace(1, 60, 50); % Assumed positions of cars % Define your seed here seed = 50; rand('seed',seed); % Set the seed for reproducibility % Assumed CO2 emissions for Diesel and Petrol CO2Diesel = 25 + 5*cos(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Diesel CO2Petrol = 20 + 5*sin(carPosition/60*2*pi) + randn(1, 50)*5; % Random data for Petrol % Fit polynomial curves with a reduced degree of 2 pDiesel = polyfit(carPosition, CO2Diesel, 2); pPetrol = polyfit(carPosition, CO2Petrol, 2); % Generate points for best fit lines fitDiesel = polyval(pDiesel, carPosition); fitPetrol = polyval(pPetrol, carPosition); % Plotting the data figure; hold on; % Plot Diesel best fit line…arrow_forward.arrow_forwardPlease help solve the question shown. I attempted this problem over five times and it keeps saying my answers are wrong. I typed 11.1hr, 1.11hr, 8.67hr, 6.9384hr, and 7.1152hr but it keeps saying that those are all incorrect. Can you please show how to get the correct answer so I can understand how to solve it? Thank you!arrow_forward
- Elements Of ElectromagneticsMechanical EngineeringISBN:9780190698614Author:Sadiku, Matthew N. O.Publisher:Oxford University PressMechanics of Materials (10th Edition)Mechanical EngineeringISBN:9780134319650Author:Russell C. HibbelerPublisher:PEARSONThermodynamics: An Engineering ApproachMechanical EngineeringISBN:9781259822674Author:Yunus A. Cengel Dr., Michael A. BolesPublisher:McGraw-Hill Education
- Control Systems EngineeringMechanical EngineeringISBN:9781118170519Author:Norman S. NisePublisher:WILEYMechanics of Materials (MindTap Course List)Mechanical EngineeringISBN:9781337093347Author:Barry J. Goodno, James M. GerePublisher:Cengage LearningEngineering Mechanics: StaticsMechanical EngineeringISBN:9781118807330Author:James L. Meriam, L. G. Kraige, J. N. BoltonPublisher:WILEY