SlideShare une entreprise Scribd logo
1  sur  12
SORTING
By:-
Kumar siddharth bansal- 100101114
Mansi mahajan -100101126
Anadi vats- 100101030
Jishnu v. nair- 100101100
Anele kingsley .c- 100101033
Emiri Charles Ugo- 100101085
Johnson Barimlenea Dandy- 100101102
WHAT IS SORTING???
 Sorting is the process of
putting a list or a group of
items in a specific order.
Some common sorting criteria
are: alphabetical or numerical.
SHELL SORT
•      Use increment sequence h 1, h2, …ht. After phase using increment hk, a[i] <= a[i+ hk]


for each hk
    for i = hk to a.size()
     tmp = a[i]
     for j = i j >= hk && tmp < a[j- hk] j-= hk
      a[j] = a[j- hk ]
     a[j] = tmp
BUBBLE SORT
•   This algorithm sorts the array A with the N elements.
    1. Initialise Set I=0
    2. Repeat steps 3 to 5 until I<N
•   3. Set J=0
•   4. Repeat step 5 until J<N-i-1
•   5. If A[J]> A[J+1] then
•      Set temp= A[J]
•      Set A[J]=A[J+1]
•      Set A[J+1]= temp
•   END IF
•   6. exit
QUICK SORT
•   Quicksort (a,l,h)
•   Where
•   a: represents the list of elements.
•   l: represents the position of the first element in the        list (only at the starting point , it’s value changes during the
    execution of the function) .
•   h: represents the position of the last element in the list.
•   1: (Initially)
•       low=l
•       high=h
        key=a[(1+h)/2] { for middle element of the list}
•   2: Repeat through step 7 while (low <=high)
•   3: Repeat 4 while (a([low]<key)
•   4: low=low+1
•   5: Repeat 6 while (a([high]<key))
•   6: high=high-1
•   7: if(low<=high)
•     (a) temp=a[low]
•     (b) a[low]=a[high]
•     (c) a[high]=temp
•     (d) low=low+1
•     (e) high=high-1
•   8: if(l<high) Quick_sort(a,l,high)
•   9: if(low<h) Quick_sort(a,low,h)
•   10: Exit
SELECTION SORT
•   1. Repeat steps 2 & 3 for k=1,2,…,n-1:
•   2. Call min(a,k,n,loc).
•   3. [Interchange a[k] and a[loc].]
•
•   Set temp: = a[k]
•   a[k]= a[loc]
•   a[loc]= temp
•
    [END OF STEP 1]
•   4. Exit
RADIX SORT
1. Find the largest element of the array.
2. Find the total number of digits num in the largets digit.
  set digit =num
3. Repeat steps 4,5 for pass=1 to num
4.Initialise buckets
  for i=1 to (n-1)
Set num=obtain digit number pass of a[i]
Put a[i] in bucket number digit
[END OF FOR LOOP]
5. Calculate all numbers from the bucket in order.
6. Exit.
MERGE SORT
•   If the list is of length 0 or 1, then it is already sorted. Otherwise:
•   Divide the unsorted list into two sublists of about half the size.
•   Sort each sublist recursively by re-applying the merge sort.
•   Mergr the two sublists back into one sorted list.
•   Merge sort incorporates two main ideas to improve its runtime:
•   A small list will take fewer steps to sort than a large list.
•   Fewer steps are required to construct a sorted list from two sorted lists than from two
    unsorted lists. For example, you only have to traverse each list once if they're already
    sorted.
HEAP SORT
• The heap data structure is an array object which can
  be easily visualized as a complete binary tree. There is
  a one to one correspondence between elements of the
  array and nodes of the tree. The tree is completely
  filled on all levels except possibly the lowest, which is
  filled from the left upto a point. All nodes of heap also
  satisfy the relation that the key values at each node is
  at least as large as the value at its children
ALGORITHM
•   The user inputs the size of the heap (within the specified limit). The program
    generates a corresponding binary tree with the nodes having randomly
    generated key values
•   Build heap operation: Let n be the number of nodes in the tree and I be the key
    of a tree. For this, the program uses operation heapify, when Heapify is called
    both the left and right subtree of the I are heaps. The function of heapify is to let
    I settle down to a position (by swapping itself with the larger of its
    children, whenever the heap property is not satisfied) till the heap property is
    satisfied in the tree which was rooted at i.
•   Remove maximum element: The program removes the largest element of the
    heap (the root) by swapping it with the last element.
•   The program executes Heapify (new root) so that the resultig tree satisfies the
    heap property
•   Goto step iii till heap is empty
Sorting

Contenu connexe

Tendances (20)

Heap sort
Heap sortHeap sort
Heap sort
 
Heaps
HeapsHeaps
Heaps
 
Heap Sort in Design and Analysis of algorithms
Heap Sort in Design and Analysis of algorithmsHeap Sort in Design and Analysis of algorithms
Heap Sort in Design and Analysis of algorithms
 
Heap sort
Heap sort Heap sort
Heap sort
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
 
Heap, quick and merge sort
Heap, quick and merge sortHeap, quick and merge sort
Heap, quick and merge sort
 
Heaps
HeapsHeaps
Heaps
 
Nikit
NikitNikit
Nikit
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
 
Heaps
HeapsHeaps
Heaps
 
arrays
arraysarrays
arrays
 
Linked list
Linked listLinked list
Linked list
 
Python List Comprehensions
Python List ComprehensionsPython List Comprehensions
Python List Comprehensions
 
Heap and heapsort
Heap and heapsortHeap and heapsort
Heap and heapsort
 
Heap sort
Heap sortHeap sort
Heap sort
 
Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Unit 7 sorting
Unit   7 sortingUnit   7 sorting
Unit 7 sorting
 
Heap sort
Heap sortHeap sort
Heap sort
 
Array 2
Array 2Array 2
Array 2
 
Heap sort
Heap sortHeap sort
Heap sort
 

En vedette

Bubble sort
Bubble sort Bubble sort
Bubble sort rmsz786
 
Selection sort
Selection sortSelection sort
Selection sortstella D
 
3.4 selection sort
3.4 selection sort3.4 selection sort
3.4 selection sortKrish_ver2
 
Selection sort
Selection sortSelection sort
Selection sortasra khan
 
Bubble sort a best presentation topic
Bubble sort a best presentation topicBubble sort a best presentation topic
Bubble sort a best presentation topicSaddam Hussain
 
Selection sort
Selection sortSelection sort
Selection sortJay Patel
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...widespreadpromotion
 
3.1 bubble sort
3.1 bubble sort3.1 bubble sort
3.1 bubble sortKrish_ver2
 
Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary SearchReem Alattas
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithmNeoClassical
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data StructureTalha Shaikh
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithmsmultimedia9
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sortgeeortiz
 

En vedette (20)

sort search in C
 sort search in C  sort search in C
sort search in C
 
Linear and Bianry search
Linear and Bianry searchLinear and Bianry search
Linear and Bianry search
 
Bubble sort
Bubble sort Bubble sort
Bubble sort
 
Selection sort
Selection sortSelection sort
Selection sort
 
The selection sort algorithm
The selection sort algorithmThe selection sort algorithm
The selection sort algorithm
 
Bubble sort algorithm
Bubble sort algorithmBubble sort algorithm
Bubble sort algorithm
 
3.4 selection sort
3.4 selection sort3.4 selection sort
3.4 selection sort
 
Selection sort
Selection sortSelection sort
Selection sort
 
Bubble sort a best presentation topic
Bubble sort a best presentation topicBubble sort a best presentation topic
Bubble sort a best presentation topic
 
Selection sort
Selection sortSelection sort
Selection sort
 
Selection sort
Selection sortSelection sort
Selection sort
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
 
3.1 bubble sort
3.1 bubble sort3.1 bubble sort
3.1 bubble sort
 
Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary Search
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
 
Sorting
SortingSorting
Sorting
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sort
 

Similaire à Sorting

Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing conceptsLJ Projects
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3infanciaj
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sortingFadhil Ismail
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisRadhika Talaviya
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingEduardo Bergavera
 
An Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List AlgorithmsAn Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List AlgorithmsBlue Elephant Consulting
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptxchin463670
 
Data analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptxData analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptxsgrishma559
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.pptLegesseSamuel
 
21. Heap_new.ppt
21. Heap_new.ppt21. Heap_new.ppt
21. Heap_new.pptAryanGour1
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptxVCE Unit 04vv.pptx
VCE Unit 04vv.pptxskilljiolms
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptxssuserd602fd
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sortKrish_ver2
 
searching techniques.pptx
searching techniques.pptxsearching techniques.pptx
searching techniques.pptxDr.Shweta
 

Similaire à Sorting (20)

Unit vii sorting
Unit   vii sorting Unit   vii sorting
Unit vii sorting
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
 
Algorithms - "heap sort"
Algorithms - "heap sort"Algorithms - "heap sort"
Algorithms - "heap sort"
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
Unit viii searching and hashing
Unit   viii searching and hashing Unit   viii searching and hashing
Unit viii searching and hashing
 
(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting(Data Structure) Chapter11 searching & sorting
(Data Structure) Chapter11 searching & sorting
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
 
An Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List AlgorithmsAn Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List Algorithms
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
 
Data analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptxData analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptx
 
Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 
21. Heap_new.ppt
21. Heap_new.ppt21. Heap_new.ppt
21. Heap_new.ppt
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptxVCE Unit 04vv.pptx
VCE Unit 04vv.pptx
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
 
3.8 quick sort
3.8 quick sort3.8 quick sort
3.8 quick sort
 
searching techniques.pptx
searching techniques.pptxsearching techniques.pptx
searching techniques.pptx
 

Plus de vatsaanadi

Plus de vatsaanadi (7)

Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Social networking
Social networkingSocial networking
Social networking
 
Ds
DsDs
Ds
 
Save the change
Save the changeSave the change
Save the change
 
Windows vs linux
Windows vs linuxWindows vs linux
Windows vs linux
 
Sampling
SamplingSampling
Sampling
 
Dbms
DbmsDbms
Dbms
 

Dernier

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Dernier (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

Sorting

  • 1. SORTING By:- Kumar siddharth bansal- 100101114 Mansi mahajan -100101126 Anadi vats- 100101030 Jishnu v. nair- 100101100 Anele kingsley .c- 100101033 Emiri Charles Ugo- 100101085 Johnson Barimlenea Dandy- 100101102
  • 2. WHAT IS SORTING??? Sorting is the process of putting a list or a group of items in a specific order. Some common sorting criteria are: alphabetical or numerical.
  • 3. SHELL SORT • Use increment sequence h 1, h2, …ht. After phase using increment hk, a[i] <= a[i+ hk] for each hk for i = hk to a.size() tmp = a[i] for j = i j >= hk && tmp < a[j- hk] j-= hk a[j] = a[j- hk ] a[j] = tmp
  • 4. BUBBLE SORT • This algorithm sorts the array A with the N elements. 1. Initialise Set I=0 2. Repeat steps 3 to 5 until I<N • 3. Set J=0 • 4. Repeat step 5 until J<N-i-1 • 5. If A[J]> A[J+1] then • Set temp= A[J] • Set A[J]=A[J+1] • Set A[J+1]= temp • END IF • 6. exit
  • 5. QUICK SORT • Quicksort (a,l,h) • Where • a: represents the list of elements. • l: represents the position of the first element in the list (only at the starting point , it’s value changes during the execution of the function) . • h: represents the position of the last element in the list. • 1: (Initially) • low=l • high=h key=a[(1+h)/2] { for middle element of the list} • 2: Repeat through step 7 while (low <=high) • 3: Repeat 4 while (a([low]<key) • 4: low=low+1 • 5: Repeat 6 while (a([high]<key)) • 6: high=high-1
  • 6. 7: if(low<=high) • (a) temp=a[low] • (b) a[low]=a[high] • (c) a[high]=temp • (d) low=low+1 • (e) high=high-1 • 8: if(l<high) Quick_sort(a,l,high) • 9: if(low<h) Quick_sort(a,low,h) • 10: Exit
  • 7. SELECTION SORT • 1. Repeat steps 2 & 3 for k=1,2,…,n-1: • 2. Call min(a,k,n,loc). • 3. [Interchange a[k] and a[loc].] • • Set temp: = a[k] • a[k]= a[loc] • a[loc]= temp • [END OF STEP 1] • 4. Exit
  • 8. RADIX SORT 1. Find the largest element of the array. 2. Find the total number of digits num in the largets digit. set digit =num 3. Repeat steps 4,5 for pass=1 to num 4.Initialise buckets for i=1 to (n-1) Set num=obtain digit number pass of a[i] Put a[i] in bucket number digit [END OF FOR LOOP] 5. Calculate all numbers from the bucket in order. 6. Exit.
  • 9. MERGE SORT • If the list is of length 0 or 1, then it is already sorted. Otherwise: • Divide the unsorted list into two sublists of about half the size. • Sort each sublist recursively by re-applying the merge sort. • Mergr the two sublists back into one sorted list. • Merge sort incorporates two main ideas to improve its runtime: • A small list will take fewer steps to sort than a large list. • Fewer steps are required to construct a sorted list from two sorted lists than from two unsorted lists. For example, you only have to traverse each list once if they're already sorted.
  • 10. HEAP SORT • The heap data structure is an array object which can be easily visualized as a complete binary tree. There is a one to one correspondence between elements of the array and nodes of the tree. The tree is completely filled on all levels except possibly the lowest, which is filled from the left upto a point. All nodes of heap also satisfy the relation that the key values at each node is at least as large as the value at its children
  • 11. ALGORITHM • The user inputs the size of the heap (within the specified limit). The program generates a corresponding binary tree with the nodes having randomly generated key values • Build heap operation: Let n be the number of nodes in the tree and I be the key of a tree. For this, the program uses operation heapify, when Heapify is called both the left and right subtree of the I are heaps. The function of heapify is to let I settle down to a position (by swapping itself with the larger of its children, whenever the heap property is not satisfied) till the heap property is satisfied in the tree which was rooted at i. • Remove maximum element: The program removes the largest element of the heap (the root) by swapping it with the last element. • The program executes Heapify (new root) so that the resultig tree satisfies the heap property • Goto step iii till heap is empty