• Tidak ada hasil yang ditemukan

Bubble Sort real-life scenario

N/A
N/A
Protected

Academic year: 2023

Membagikan "Bubble Sort real-life scenario"

Copied!
3
0
0

Teks penuh

(1)

Bubble Sort real-life scenario

Bubble Sort technique works by repeatedly swapping the adjacent elements if the position of the elements are in wrong order. We have all been through this process of bubble sort throughout our childhood. We used to line up randomly in front of the teacher, then the teacher put the task of lining all up in an ascending order of height.

The bubble sort algorithm comes in this scenario. In this case every person’s height is an element of the list. With every pass, the teacher goes over the students, they slowly start standing in a more orderly manner till all of them stand according to height.

Selection Sort real-life scenario

Selection sort is a sorting algorithm that sorts an array by repeatedly finding the minimum element from unsorted part and putting it at the beginning of the unsorted part. Consider an example, if we have 200 glasses of different volume 100 ml, 110 ml, 120 ml, 130 ml, …. , 2080 ml and 2090 ml. We find them spread on a room floor and want to place them such that the 2090 glass, then 2080 glass inside it, then 2070 glass inside it and so on. It can be an example of selection sort.

(2)

Insertion Sort real-life scenario

In insertion sort, the list is searched sequentially and unsorted items are moved and inserted into the sorted sub-list. Real world example of insertion sort is how tailors arrange shirts in a cupboard, they always keep them in sorted order of size and thus insert new shirt at the right position very quickly by moving other shirts forward to keep the right place for a new shirt.

Merge Sort real-life scenario

Merge Sort is a divide and conquer algorithm that uses a merge process to merge the two sub-list into one by sorting its elements that are in incorrect order. The type of sorting required to be done on data that resides in secondary memory. This is required in case when the amount of data is too large to fit into the main memory. Since the memory location of data need not be contiguous in secondary memory thus merge sort is preferred.

(3)

Referensi

Dokumen terkait