0% found this document useful (0 votes)
19 views22 pages

Sorting

The document discusses different sorting algorithms including bubble sort, insertion sort, and merge sort. It provides details on how bubble sort works by comparing adjacent elements and swapping them if out of order over multiple iterations. Insertion sort works by dividing an array into sorted and unsorted sections, selecting items from unsorted to insert into the correct position of sorted. Merge sort is a recursive algorithm that divides a list into sublists, sorts the sublists, and then merges the sorted sublists.

Uploaded by

Jiji Macaso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views22 pages

Sorting

The document discusses different sorting algorithms including bubble sort, insertion sort, and merge sort. It provides details on how bubble sort works by comparing adjacent elements and swapping them if out of order over multiple iterations. Insertion sort works by dividing an array into sorted and unsorted sections, selecting items from unsorted to insert into the correct position of sorted. Merge sort is a recursive algorithm that divides a list into sublists, sorts the sublists, and then merges the sorted sublists.

Uploaded by

Jiji Macaso
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

SORTING in

ARRAY
WMSU Members:
BERNALDEZ, SITTI AISA ALBON
CALULUT, JOSHUA MIGUEL CAÑETE
JABONAN, KENNY JAY CELO
MUTALIB, SADAMIER SABUDDIN
SANCHEZ, CAROLINE THERESE GARCIA
SUEÑO, DIANA SANTOS
1
SORTING
• basic techniques used to arrange
elements in a specified order

2
VIDEO PRESENTATION
________________

3
Common Sorting Algorithms
• Bubble sort
• Insertion sort
• Merge sort

4
BUBBLE SORT

5
Bubble Sort
• is a sorting algorithm that compares two
adjacent elements and swaps them until
they are in the intended order.

• is the simplest of the sorting techniques.

• suppose we are trying to sort the elements


in ascending order.
6
1. First Iteration (Compare and
Swap)

• Starting from the first index,


compare the first and the second
elements.

• If the first element is greater than


the second element, they are
swapped.

• Now, compare the second and the


third elements. Swap them if they
are not in order.

• The above process goes on until


the last element.
7
2. Remaining Iteration
• The same process goes
on for the remaining
iteration.

• After each iteration, the


largest element among
the unsorted elements is
placed at the end

8
• In each iteration, the
comparison takes place
up to the last unsorted
element.

• The array is sorted when


all the unsorted elements
are placed at their correct
positions.

• Array entirely sorted.

9
Bubble sort is used if

• Complexity does not matter

• Short and simple code is preferred

10
The above illustration can be summarized
in a tabular form

11
INSERTION SORT

12
Insertion Sort
• Insertion sort is an uncomplicated sorting
method that functions much like organizing
playing cards in your hand. It essentially
divides the array into two sections: one
sorted and the other unsorted. Items from
the unsorted segment are chosen and
inserted into their appropriate positions
within the sorted segment.

13
First Pass

14
15
16
17
18
MERGE SORT

19
Merge Sort
• Recursive algorithm
• Divides the list into smaller sublists
• Sorts the sublists
• Merge them afterwards

20
Implementation
• [Insert algorithm here]

21
22

You might also like