Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

f its values are either ascending or descending ordered array, the value of each element is less than or equal to the SORTING: An array

image text in transcribed
f its values are either ascending or descending ordered array, the value of each element is less than or equal to the SORTING: An array is said to be onder. In an ascending value of the next element. That is, leach elementj(nest element A sort is an algorithm for ordering an array. Of the many different an array we discuss the bubble sort t requires the swapping of values sorted in a pair of variables. If varl, var2, and temp are all variables of the same type, then the statements for sorting temp -varl varl var2 var2-temp Assign varl's value to var2 and var2's value to varl. Babble Sort: The bubble sort is an algorithm that compares adjacent items and swaps those that are out of order. If this process repeated enough times, the list will be ordered Let's carry out this process on the list The steps for cach pass through the list are as follesss 1.Compare the first and second items. If they are out of order, swap them 2. Compare the second and third item. If they are out of order, swap them 3.Repeat this pattern for all remaining pairs. The first time first pass. After the first pass the last item will be in its proper position. Therefore, the second pass does not have to consider it and so requires one less comparison At the end of the second pass, the last two items will be in the proper position. Each successive pass requires one less comparison. After four passes, the last four items will be in their proper positions, and hence, the first will be also. through the list, this process is repeated to the end of the list. This is called a specific example of this process, consider the list of numbers 21 13 17 53 This erecess.complctes the first pass through the date and results in the larrest numbe meving to the bottem of the list As the larrest value sinks to its resting place at the betto of the list,the smaller clements slowhy rise.or "bubble" to the top of the list hin bebblss cllect of the smaller clements is what rave rise to the name "bubble void Prinist BubbleSort d Sortist

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

denigration of emotional outbursts; being reserved;

Answered: 1 week ago