MINOR PROJECTMINOR PROJECT
Group No.- ETA-08Group No.- ETA-08
Name of Group membersName of Group members:-:-
1.1. PRAVEEN KANSARIPRAVEEN KANSARI
2.2. SURBHI NAIDUSURBHI NAIDU
3.3. SMITA SINGHSMITA SINGH
4.4. NEHA SINGHNEHA SINGH
Name of project guideName of project guide:-:-
Prof. HITESH KISHNANIProf. HITESH KISHNANI
RUNGTA COLLEGE OFRUNGTA COLLEGE OF
ENGINEERING & TECHNOLGY,ENGINEERING & TECHNOLGY,
RAIPURRAIPUR
SORTING TECHNIQUES
USING FUNCTION
About C++About C++
C++ is a computer
programming language.
And the programming
language C++ was
developed by BJARNE
STROUSTRUP at
AT&T Bell Laboratories
in Murray Hill, New
Jesrey, USA in the early
1980.
SORTING
INTRODUCTIONINTRODUCTION:-:-
Sorting is a technique to rearrange theSorting is a technique to rearrange the
elements of a list in ascending or descendingelements of a list in ascending or descending
order, which can be numerical, lexicographical,order, which can be numerical, lexicographical,
or any user-defined order. Sorting is a processor any user-defined order. Sorting is a process
through which the data is arranged in ascendingthrough which the data is arranged in ascending
or descending order. Sorting is the part of theor descending order. Sorting is the part of the
Data StructureData Structure..
Example of the sorting:-
Fig.(1)- Before Sorting Fig.(2)-After Sorting
Before Sorting After Sorting
TYPES OF
SORTING
5.Merge Sort.5.Merge Sort.
6.Quick Sort.6.Quick Sort.
7.Heap Sort.7.Heap Sort.
8.Shell Sort.8.Shell Sort.
1.Bubble Sort.1.Bubble Sort.
2.Insertion2.Insertion
Sort.Sort.
3.Selection3.Selection
Sort.Sort.
4.Bucket Sort.4.Bucket Sort.
BUBBLE SORT
In bubble sort methodIn bubble sort method
the list is divided into twothe list is divided into two
sub-lists sorted andsub-lists sorted and
unsorted. The smallestunsorted. The smallest
element is bubbled fromelement is bubbled from
unsorted sub-list.unsorted sub-list.
Example of Bubble Sort
Example of Bubble Sort
Swap?
Example of Bubble Sort
Yes!
Example of Bubble Sort
Swap?
Example of Bubble Sort
No
Example of Bubble Sort
Swap?
Example of Bubble Sort
No
Example of Bubble Sort
Swap?
Example of Bubble Sort
Yes!
Example of Bubble Sort
Swap?
Example of Bubble Sort
Yes!
Example of Bubble Sort
Swap?
Example of Bubble Sort
No
Example of Bubble Sort
Swap?
Example of Bubble Sort
No
Example of Bubble Sort
Swap?
Example of Bubble Sort
Yes!
Example of Bubble Sort
Swap?
Example of Bubble Sort
Yes!
Example of Bubble Sort
Swap?
Example of Bubble Sort
No
Example of Bubble Sort
Swap?
Example of Bubble Sort
No
Example of Bubble Sort
Swap?
Example of Bubble Sort
Yes!
Example of Bubble Sort
Swap?
Example of Bubble Sort
Yes!
Example of Bubble Sort
Swap?
Example of Bubble Sort
No
Example of Bubble Sort
Swap?
Example of Bubble Sort
No
Example of Bubble Sort
Swap?
Example of Bubble Sort
This picture
shows an
array of six
integers that
is sorted by
Bubble sort
from
smallest to
larges.
INSERTION SORT
In bubble sort methodIn bubble sort method
the list is divided into twothe list is divided into two
sub-lists sorted andsub-lists sorted and
unsorted. The smallestunsorted. The smallest
element is bubbled fromelement is bubbled from
unsorted sub-list.unsorted sub-list.
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
These columnsThese columns
or arrays areor arrays are
not sorted.not sorted.
The unsortedThe unsorted
arrays arearrays are
shown in theshown in the
figure.figure.
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Unsorted sideSorted sideSorted side Unsorted side
The sortedThe sorted
side startsside starts
with just thewith just the
first element,first element,
which is notwhich is not
necessarilynecessarily
the smallestthe smallest
element.element.
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Sorted side Unsorted side
The sortedThe sorted
side grows byside grows by
taking thetaking the
front elementfront element
from thefrom the
unsortedunsorted
side...side...
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Sorted side Unsorted side
...and...and
inserting it ininserting it in
the place thatthe place that
keeps thekeeps the
sorted sidesorted side
arranged fromarranged from
small to largesmall to large..
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Sorted side Unsorted side
The two
arrays or
column are
sorted in this
figure.
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
In this time
the arrays
are sorted so
we don’t
need to
move any
element.
Sorted side Unsorted side
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Sorted side Unsorted sideIn this time,
we also
don’t need
to move the
any array
because
these are
already
sorted.
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Sorted side Unsorted side
Copy theCopy the
newnew
element toelement to
a separatea separate
location.location.
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
ShiftShift
elements inelements in
the sortedthe sorted
side,side,
creating ancreating an
open spaceopen space
for the newfor the new
element.element.
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Insert theInsert the
element.element.
Shift elementsShift elements
in the sortedin the sorted
side, creatingside, creating
an open spacean open space
for the newfor the new
element.element.
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
ContinueContinue
shiftingshifting
elements...elements...
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
ContinueContinue
shiftingshifting
elements...elements...
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
...until you...until you
reach thereach the
location forlocation for
the newthe new
element.element.
Example of Insertion Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Sorted side Unsorted side
Copy the newCopy the new
element backelement back
into the array,into the array,
at the correctat the correct
location.location.
Example of Insertion Sort
Sorted side Unsorted side
The lastThe last
element mustelement must
also bealso be
inserted. Startinserted. Start
by copying it...by copying it...
Example of Insertion Sort
This is theThis is the
finale sortedfinale sorted
result by theresult by the
InsertionInsertion
sort.sort.
SELECTION SORT
In selection sort the list is divided into
two sub-lists sorted and unsorted.
These two lists are divided by imaginary
wall. We find a smallest element from
unsorted sub-list and swap it to the
beginning. And the wall moves one
element ahead, as the sorted list is
increases and unsorted list is
decreases.
Example of Selection Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
These columnsThese columns
or arrays areor arrays are
not sorted.not sorted.
The unsortedThe unsorted
arrays arearrays are
shown in theshown in the
figure.figure.
Example of Selection Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Start byStart by
finding thefinding the
smallestsmallest
entry.entry.
Example of Selection Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Swap theSwap the
smallestsmallest
entry withentry with
the firstthe first
entry.entry.
Example of Selection Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Swap theSwap the
smallestsmallest
entry withentry with
the firstthe first
entry.entry.
Example of Selection Sort
0
10
20
30
40
50
60
70
[1] [2] [3] [4] [5] [6]
Sorted side Unsorted side
Part of thePart of the
array isarray is
now sorted.now sorted.
Find the
smallest
element in
the unsorted
side.
Sorted side Unsorted side
Example of Selection Sort
Example of Selection Sort
Unsorted sideSorted side
Swap withSwap with
the front ofthe front of
thethe
unsortedunsorted
side.side.
Example of Selection Sort
We haveWe have
increasedincreased
the size ofthe size of
the sortedthe sorted
side by oneside by one
element.element.
Sorted side Unsorted side
Example of Selection Sort
Sorted side Unsorted side
Smallest
from
unsorted
Smallest
from
unsorted
TheThe
processprocess
continues...continues...
Example of Selection Sort
TheThe
processprocess
continues...continues...
Sorted side Unsorted side
Swap
with
front
Swap
with
front
Example of Selection Sort
TheThe
processprocess
continues...continues...
Sorted side Unsorted side
Example of Selection Sort
Check theCheck the
smallestsmallest
array inarray in
unsortedunsorted
side &side &
sorted this.sorted this.
Unsorted sideSorted side
Example of Selection Sort
TheThe
process isprocess is
continue….continue….
Sorted side Unsorted side
Example of Selection Sort
The array isThe array is
now sortednow sorted
by theby the
SelectionSelection
sort.sort.
The C & C++ is the ComputerThe C & C++ is the Computer
programming language.programming language. The sorting
technique uses for rearrange the data
in increasing or decreasing order.
The computer programming
language C and C++ are used in the
many works as like web development
and other.
Conclusion:-
Sorting Techniques

Sorting Techniques

  • 1.
    MINOR PROJECTMINOR PROJECT GroupNo.- ETA-08Group No.- ETA-08 Name of Group membersName of Group members:-:- 1.1. PRAVEEN KANSARIPRAVEEN KANSARI 2.2. SURBHI NAIDUSURBHI NAIDU 3.3. SMITA SINGHSMITA SINGH 4.4. NEHA SINGHNEHA SINGH Name of project guideName of project guide:-:- Prof. HITESH KISHNANIProf. HITESH KISHNANI RUNGTA COLLEGE OFRUNGTA COLLEGE OF ENGINEERING & TECHNOLGY,ENGINEERING & TECHNOLGY, RAIPURRAIPUR
  • 2.
  • 3.
    About C++About C++ C++is a computer programming language. And the programming language C++ was developed by BJARNE STROUSTRUP at AT&T Bell Laboratories in Murray Hill, New Jesrey, USA in the early 1980.
  • 4.
    SORTING INTRODUCTIONINTRODUCTION:-:- Sorting is atechnique to rearrange theSorting is a technique to rearrange the elements of a list in ascending or descendingelements of a list in ascending or descending order, which can be numerical, lexicographical,order, which can be numerical, lexicographical, or any user-defined order. Sorting is a processor any user-defined order. Sorting is a process through which the data is arranged in ascendingthrough which the data is arranged in ascending or descending order. Sorting is the part of theor descending order. Sorting is the part of the Data StructureData Structure..
  • 5.
    Example of thesorting:- Fig.(1)- Before Sorting Fig.(2)-After Sorting Before Sorting After Sorting
  • 6.
    TYPES OF SORTING 5.Merge Sort.5.MergeSort. 6.Quick Sort.6.Quick Sort. 7.Heap Sort.7.Heap Sort. 8.Shell Sort.8.Shell Sort. 1.Bubble Sort.1.Bubble Sort. 2.Insertion2.Insertion Sort.Sort. 3.Selection3.Selection Sort.Sort. 4.Bucket Sort.4.Bucket Sort.
  • 7.
    BUBBLE SORT In bubblesort methodIn bubble sort method the list is divided into twothe list is divided into two sub-lists sorted andsub-lists sorted and unsorted. The smallestunsorted. The smallest element is bubbled fromelement is bubbled from unsorted sub-list.unsorted sub-list.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
    Example of BubbleSort This picture shows an array of six integers that is sorted by Bubble sort from smallest to larges.
  • 41.
    INSERTION SORT In bubblesort methodIn bubble sort method the list is divided into twothe list is divided into two sub-lists sorted andsub-lists sorted and unsorted. The smallestunsorted. The smallest element is bubbled fromelement is bubbled from unsorted sub-list.unsorted sub-list.
  • 42.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] These columnsThese columns or arrays areor arrays are not sorted.not sorted. The unsortedThe unsorted arrays arearrays are shown in theshown in the figure.figure.
  • 43.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Unsorted sideSorted sideSorted side Unsorted side The sortedThe sorted side startsside starts with just thewith just the first element,first element, which is notwhich is not necessarilynecessarily the smallestthe smallest element.element.
  • 44.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Sorted side Unsorted side The sortedThe sorted side grows byside grows by taking thetaking the front elementfront element from thefrom the unsortedunsorted side...side...
  • 45.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Sorted side Unsorted side ...and...and inserting it ininserting it in the place thatthe place that keeps thekeeps the sorted sidesorted side arranged fromarranged from small to largesmall to large..
  • 46.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Sorted side Unsorted side The two arrays or column are sorted in this figure.
  • 47.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] In this time the arrays are sorted so we don’t need to move any element. Sorted side Unsorted side
  • 48.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Sorted side Unsorted sideIn this time, we also don’t need to move the any array because these are already sorted.
  • 49.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Sorted side Unsorted side Copy theCopy the newnew element toelement to a separatea separate location.location.
  • 50.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] ShiftShift elements inelements in the sortedthe sorted side,side, creating ancreating an open spaceopen space for the newfor the new element.element.
  • 51.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Insert theInsert the element.element. Shift elementsShift elements in the sortedin the sorted side, creatingside, creating an open spacean open space for the newfor the new element.element.
  • 52.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] ContinueContinue shiftingshifting elements...elements...
  • 53.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] ContinueContinue shiftingshifting elements...elements...
  • 54.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] ...until you...until you reach thereach the location forlocation for the newthe new element.element.
  • 55.
    Example of InsertionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Sorted side Unsorted side Copy the newCopy the new element backelement back into the array,into the array, at the correctat the correct location.location.
  • 56.
    Example of InsertionSort Sorted side Unsorted side The lastThe last element mustelement must also bealso be inserted. Startinserted. Start by copying it...by copying it...
  • 57.
    Example of InsertionSort This is theThis is the finale sortedfinale sorted result by theresult by the InsertionInsertion sort.sort.
  • 58.
    SELECTION SORT In selectionsort the list is divided into two sub-lists sorted and unsorted. These two lists are divided by imaginary wall. We find a smallest element from unsorted sub-list and swap it to the beginning. And the wall moves one element ahead, as the sorted list is increases and unsorted list is decreases.
  • 59.
    Example of SelectionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] These columnsThese columns or arrays areor arrays are not sorted.not sorted. The unsortedThe unsorted arrays arearrays are shown in theshown in the figure.figure.
  • 60.
    Example of SelectionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Start byStart by finding thefinding the smallestsmallest entry.entry.
  • 61.
    Example of SelectionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Swap theSwap the smallestsmallest entry withentry with the firstthe first entry.entry.
  • 62.
    Example of SelectionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Swap theSwap the smallestsmallest entry withentry with the firstthe first entry.entry.
  • 63.
    Example of SelectionSort 0 10 20 30 40 50 60 70 [1] [2] [3] [4] [5] [6] Sorted side Unsorted side Part of thePart of the array isarray is now sorted.now sorted.
  • 64.
    Find the smallest element in theunsorted side. Sorted side Unsorted side Example of Selection Sort
  • 65.
    Example of SelectionSort Unsorted sideSorted side Swap withSwap with the front ofthe front of thethe unsortedunsorted side.side.
  • 66.
    Example of SelectionSort We haveWe have increasedincreased the size ofthe size of the sortedthe sorted side by oneside by one element.element. Sorted side Unsorted side
  • 67.
    Example of SelectionSort Sorted side Unsorted side Smallest from unsorted Smallest from unsorted TheThe processprocess continues...continues...
  • 68.
    Example of SelectionSort TheThe processprocess continues...continues... Sorted side Unsorted side Swap with front Swap with front
  • 69.
    Example of SelectionSort TheThe processprocess continues...continues... Sorted side Unsorted side
  • 70.
    Example of SelectionSort Check theCheck the smallestsmallest array inarray in unsortedunsorted side &side & sorted this.sorted this. Unsorted sideSorted side
  • 71.
    Example of SelectionSort TheThe process isprocess is continue….continue…. Sorted side Unsorted side
  • 72.
    Example of SelectionSort The array isThe array is now sortednow sorted by theby the SelectionSelection sort.sort.
  • 73.
    The C &C++ is the ComputerThe C & C++ is the Computer programming language.programming language. The sorting technique uses for rearrange the data in increasing or decreasing order. The computer programming language C and C++ are used in the many works as like web development and other. Conclusion:-

Editor's Notes

  • #4 The presentation illustrates two quadratic sorting algorithms: Selectionsort and Insertionsort. Before this lecture, students should know about arrays, and should have seen some motivation for sorting (such as binary search of a sorted array).
  • #65 Each step of the Selectionsort works by finding the smallest element in the unsorted side. At this point, we would find the number 15 at location [5] in the unsorted side.