📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 37definition

ALGORITHMIC STRATEGIES · Part 9

Chapter 2: 3 · COMPUTER SCIENCE

sort is a simple sorting algorithm. The algorithm starts at the beginning of the list of values stored in an array. It compares each pair of adjacent elements and swaps them if they are in the unsorted order. This comparison and passed to be continued until no swaps are needed, which indicates that the list of values stored in an array is sorted.

The algorithm is a comparison sort, is named for the way smaller elements "bubble" to the top of the list. Although the algorithm is simple, it is too slow and less efficient when compared to insertion sort and other sorting methods. Assume list is an array of n elements. The swap function swaps the values of the given array elements.

Procedure . Start with the first element i.e., index = , compare the current element with the next element of the array. . If the current element is greater than the next element of the array, swap them.

. If the current element is less than the next or right side of the element, move to the next element. Go to Step and repeat until end of the index is reached. 12th Computer Chapter - - Algorithmic Strategies Let's consider an array with values { , , , , , } Below, we have a pictorial representation of how bubble sort will sort the given array.

> So interchange > No swapping > So interchange > So interchange > So interchange The above pictorial example is for iteration- . Similarly, remaining iteration can be done. The final iteration will give the sorted array. At the end of all the iterations we will get the sorted values in an array as given below: .

. Selection sort The selection sort is a simple sorting algorithm that improves on the performance of bubble sort by

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →