Upcoming SlideShare
Loading in …5
×

# Sorting

1,978 views
1,906 views

Published on

Published in: Education, Technology, Business
0 Comments
3 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

No Downloads
Views
Total views
1,978
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
144
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

### Sorting

1. 1. SORTINGBy:-Kumar siddharth bansal- 100101114Mansi mahajan -100101126Anadi vats- 100101030Jishnu v. nair- 100101100Anele kingsley .c- 100101033Emiri Charles Ugo- 100101085Johnson Barimlenea Dandy- 100101102
2. 2. WHAT IS SORTING??? Sorting is the process ofputting a list or a group ofitems in a specific order.Some common sorting criteriaare: alphabetical or numerical.
3. 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. 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. 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. 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. 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. 8. RADIX SORT1. Find the largest element of the array.2. Find the total number of digits num in the largets digit. set digit =num3. Repeat steps 4,5 for pass=1 to num4.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. 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 theyre already sorted.
10. 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. 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