SlideShare a Scribd company logo
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

More Related Content

PPT
Counting Sort Lowerbound
PPTX
Radix sort
PPTX
Radix and shell sort
PPTX
Counting sort
PDF
Heapsort quick sort
PPTX
Quick and Heap Sort with examples
PPTX
SORTTING IN LINEAR TIME - Radix Sort
PPT
3.6 radix sort
Counting Sort Lowerbound
Radix sort
Radix and shell sort
Counting sort
Heapsort quick sort
Quick and Heap Sort with examples
SORTTING IN LINEAR TIME - Radix Sort
3.6 radix sort

What's hot (20)

PPTX
Heap sort
PPT
PPTX
Heap Sort in Design and Analysis of algorithms
PDF
Array linear data_structure_2 (1)
PDF
Heap, quick and merge sort
PPTX
Sorting and hashing concepts
PDF
PPT
PDF
Linked list
PDF
Python List Comprehensions
PDF
Heap and heapsort
PPT
Heap sort
PPT
Data Structures - Searching & sorting
PPTX
Unit 7 sorting
PPTX
Heap sort
PPT
Array 2
PPTX
Heap sort
Heap sort
Heap Sort in Design and Analysis of algorithms
Array linear data_structure_2 (1)
Heap, quick and merge sort
Sorting and hashing concepts
Linked list
Python List Comprehensions
Heap and heapsort
Heap sort
Data Structures - Searching & sorting
Unit 7 sorting
Heap sort
Array 2
Heap sort
Ad

Viewers also liked (20)

PDF
sort search in C
PPT
Linear and Bianry search
PPT
Bubble sort
PPT
Selection sort
PPTX
The selection sort algorithm
PPTX
Bubble sort algorithm
PPT
3.4 selection sort
DOC
Selection sort
PPT
Bubble sort a best presentation topic
PPTX
Selection sort
PPTX
Selection sort
PPTX
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
PPT
3.1 bubble sort
PPT
Linear Search & Binary Search
PDF
Linear search algorithm
PPTX
Linear Search Data Structure
PPT
Sorting
PDF
Sorting algorithms
PPT
Sorting Algorithms
PPTX
Bubble Sort
sort search in C
Linear and Bianry search
Bubble sort
Selection sort
The selection sort algorithm
Bubble sort algorithm
3.4 selection sort
Selection sort
Bubble sort a best presentation topic
Selection sort
Selection sort
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
3.1 bubble sort
Linear Search & Binary Search
Linear search algorithm
Linear Search Data Structure
Sorting
Sorting algorithms
Sorting Algorithms
Bubble Sort
Ad

Similar to Sorting (20)

PPTX
2.Problem Solving Techniques and Data Structures.pptx
PPTX
Analysis and Design of Algorithms -Sorting Algorithms and analysis
PPTX
data structures and algorithms Unit 3
PDF
Chapter 8 advanced sorting and hashing for print
PDF
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
PPTX
Data Structure and algorithms for software
PPT
Advanced s and s algorithm.ppt
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
PPTX
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
PPT
Unit 7 sorting
PPTX
Unit III Version I.pptx
PPTX
sorting-160810203705.pptx
PPTX
Ch2 Part III-Advanced Sorting algorithms.pptx
PPTX
All Searching and Sorting Techniques in Data Structures
PPTX
Data structure using c module 3
PPTX
Sorting2
PPT
search_sort search_sortsearch_sort search_sortsearch_sortsearch_sortsearch_sort
PPT
search_sort_v1.pptgghghhhggggjjjjjjllllllllvbbbbbcfdsdfffg
2.Problem Solving Techniques and Data Structures.pptx
Analysis and Design of Algorithms -Sorting Algorithms and analysis
data structures and algorithms Unit 3
Chapter 8 advanced sorting and hashing for print
Sorting-algorithmbhddcbjkmbgjkuygbjkkius.pdf
Data Structure and algorithms for software
Advanced s and s algorithm.ppt
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
UNIT V Searching Sorting Hashing Techniques [Autosaved].pptx
Unit 7 sorting
Unit III Version I.pptx
sorting-160810203705.pptx
Ch2 Part III-Advanced Sorting algorithms.pptx
All Searching and Sorting Techniques in Data Structures
Data structure using c module 3
Sorting2
search_sort search_sortsearch_sort search_sortsearch_sortsearch_sortsearch_sort
search_sort_v1.pptgghghhhggggjjjjjjllllllllvbbbbbcfdsdfffg

More from vatsaanadi (7)

PPTX
Virtual memory
PPT
Social networking
PPTX
PPTX
Save the change
PPTX
Windows vs linux
PPTX
Sampling
PPTX
Virtual memory
Social networking
Save the change
Windows vs linux
Sampling

Recently uploaded (20)

PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Classroom Observation Tools for Teachers
PPTX
Lesson notes of climatology university.
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Pharma ospi slides which help in ospi learning
2.FourierTransform-ShortQuestionswithAnswers.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pre independence Education in Inndia.pdf
Sports Quiz easy sports quiz sports quiz
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
VCE English Exam - Section C Student Revision Booklet
Microbial diseases, their pathogenesis and prophylaxis
Classroom Observation Tools for Teachers
Lesson notes of climatology university.
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Final Presentation General Medicine 03-08-2024.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
TR - Agricultural Crops Production NC III.pdf
Computing-Curriculum for Schools in Ghana
Pharma ospi slides which help in ospi learning

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