SlideShare a Scribd company logo
Lower bound for Sorting We use only comparisons between elements to gain order information about an input sequence a 1 ,a 2 ,………… a n .
The decision tree model A decision tree is a fully binary tree that represents the comparisons between elements that are performed by a particular sorting algorithm operating on an input of a given size
The decision tree model 1:2 2:3 1:3 1:3 2:3 <1,2,3> <1,3,2> <2,1,3> <3,2,1> <2,3,1> <3,1,2> ≤ ≤ ≤ ≤ ≤ > > > > >
A lower bound for the worst case The length of the longest path from the root of a decision tree to any of its reachable leaves represents the worst-case number of  comparisons that the corresponding sorting algorithm performs.
Counting Sort The basic idea of counting sort is to determine, for each input element x, the number of elements less than x. This information can be used to place element x directly into its position in the output array.
Counting Sort COUNTTING-SORT(A, B, k) for i   0 to k do C[i]    0 for j    1 to length[A] do C[A[j]]    C[A[j]]+1 for i   1 to k do C[i]    C[i] + C[i-1] for j    length[A] downto 1 do B[C[A[j]]]    A[j] C[A[j]]   C[A[j]]-1
Counting Sort (a) A 3 0 3 2 0 3 5 2 5 4 3 2 1  8 7 6 C 1 0 3 2 0 2 4 3 2 1 0 5
Counting Sort (b) C 8 7 7 4 2 2 4 3 2 1 0 5
Counting Sort (c) B 3 5 4 3 2 1  8 7 6 C 8 7 6 4 2 2 4 3 2 1 0 5
Counting Sort (d) B 3 0 5 4 3 2 1  8 7 6 C 8 7 6 4 2 1 4 3 2 1 0 5
Counting Sort (e) B 3 3 0 5 4 3 2 1  8 7 6 C 8 7 5 4 2 1 4 3 2 1 0 5
Counting Sort (f) B 5 3 3 3 2 2 0 0 5 4 3 2 1  8 7 6
How much time does Counting Sort require? The first for loop takes time  θ (k) second for loop takes time  θ (n) third for loop takes time  θ (k) fourth for loop takes time  θ (n) Thus the overall time is  θ (k+n).  In which case the running time is  θ (n.

More Related Content

PPTX
Radix sorting
PPT
Counting sort(Non Comparison Sort)
PPT
Counting Sort and Radix Sort Algorithms
PPTX
Radix sort concept
PPTX
Bucket sort- A Noncomparision Algorithm
PPTX
Counting sort
PDF
Algoritmo Counting sort
PPTX
Linear Sorting
Radix sorting
Counting sort(Non Comparison Sort)
Counting Sort and Radix Sort Algorithms
Radix sort concept
Bucket sort- A Noncomparision Algorithm
Counting sort
Algoritmo Counting sort
Linear Sorting

What's hot (20)

PPTX
Bucket sort
PPTX
Merge sort
PDF
Merge sort
PPTX
Lecture 12 data structures and algorithms
PPTX
SORTTING IN LINEAR TIME - Radix Sort
PPTX
Lecture 6 data structures and algorithms
PPTX
Merge sort code in C explained
PPT
Heaps & Adaptable priority Queues
PPT
Maps&hash tables
PPTX
Sorting2
PPT
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
PDF
Sorting
PPT
PPTX
Marge Sort
PDF
Sorting
PPT
lecture 15
PPT
Matrix Multiplication(An example of concurrent programming)
PPT
3.6 radix sort
PPT
Presentation on binary search, quick sort, merge sort and problems
Bucket sort
Merge sort
Merge sort
Lecture 12 data structures and algorithms
SORTTING IN LINEAR TIME - Radix Sort
Lecture 6 data structures and algorithms
Merge sort code in C explained
Heaps & Adaptable priority Queues
Maps&hash tables
Sorting2
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Sorting
Marge Sort
Sorting
lecture 15
Matrix Multiplication(An example of concurrent programming)
3.6 radix sort
Presentation on binary search, quick sort, merge sort and problems
Ad

Similar to chapter-8.ppt (20)

PPTX
Counting Sort
PPT
Counting Sort Lowerbound
PPTX
Advance Algorithm_unit_2_czcbcnhgjy.pptx
PPT
lecture 9
PPT
Top school in delhi ncr
PPT
Cis435 week06
PDF
06 Analysis of Algorithms: Sorting in Linear Time
PDF
Sienna 8 countingsorts
PDF
Demystifying Software Interviews
PPT
lecture 10
PPTX
ppt2- sorting data in design and anlysis.pptx
PPT
Insertion sort bubble sort selection sort
PPTX
Sorting ppt
PPTX
Data Structure and algorithms for software
PDF
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
PPTX
Counting sort
PPT
Sorting Algorithms
PDF
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
PPT
InsertionSortBubbleSortSelectionSort.ppt
PDF
BCS401 ADA Second IA Test Question Bank.pdf
Counting Sort
Counting Sort Lowerbound
Advance Algorithm_unit_2_czcbcnhgjy.pptx
lecture 9
Top school in delhi ncr
Cis435 week06
06 Analysis of Algorithms: Sorting in Linear Time
Sienna 8 countingsorts
Demystifying Software Interviews
lecture 10
ppt2- sorting data in design and anlysis.pptx
Insertion sort bubble sort selection sort
Sorting ppt
Data Structure and algorithms for software
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
Counting sort
Sorting Algorithms
Alg_Wks1_2.pdflklokjbhvkv jv .v.vk.hk kv h/k
InsertionSortBubbleSortSelectionSort.ppt
BCS401 ADA Second IA Test Question Bank.pdf
Ad

More from Tareq Hasan (20)

PPTX
Grow Your Career with WordPress
PDF
Caching in WordPress
PDF
How to Submit a plugin to WordPress.org Repository
PDF
Composer - The missing package manager for PHP
PDF
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
PPT
08 c++ Operator Overloading.ppt
PPT
02 c++ Array Pointer
PPT
01 c++ Intro.ppt
PPT
chapter22.ppt
PPT
chapter - 6.ppt
PPT
Algorithm.ppt
PPT
chapter23.ppt
PPT
chapter24.ppt
PPT
Algorithm: priority queue
PPT
Algorithm: Quick-Sort
PPT
Java: GUI
PPT
Java: Inheritance
PPT
Java: Exception
PPT
Java: Introduction to Arrays
PPT
Java: Class Design Examples
Grow Your Career with WordPress
Caching in WordPress
How to Submit a plugin to WordPress.org Repository
Composer - The missing package manager for PHP
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
08 c++ Operator Overloading.ppt
02 c++ Array Pointer
01 c++ Intro.ppt
chapter22.ppt
chapter - 6.ppt
Algorithm.ppt
chapter23.ppt
chapter24.ppt
Algorithm: priority queue
Algorithm: Quick-Sort
Java: GUI
Java: Inheritance
Java: Exception
Java: Introduction to Arrays
Java: Class Design Examples

chapter-8.ppt

  • 1. Lower bound for Sorting We use only comparisons between elements to gain order information about an input sequence a 1 ,a 2 ,………… a n .
  • 2. The decision tree model A decision tree is a fully binary tree that represents the comparisons between elements that are performed by a particular sorting algorithm operating on an input of a given size
  • 3. The decision tree model 1:2 2:3 1:3 1:3 2:3 <1,2,3> <1,3,2> <2,1,3> <3,2,1> <2,3,1> <3,1,2> ≤ ≤ ≤ ≤ ≤ > > > > >
  • 4. A lower bound for the worst case The length of the longest path from the root of a decision tree to any of its reachable leaves represents the worst-case number of comparisons that the corresponding sorting algorithm performs.
  • 5. Counting Sort The basic idea of counting sort is to determine, for each input element x, the number of elements less than x. This information can be used to place element x directly into its position in the output array.
  • 6. Counting Sort COUNTTING-SORT(A, B, k) for i  0 to k do C[i]  0 for j  1 to length[A] do C[A[j]]  C[A[j]]+1 for i  1 to k do C[i]  C[i] + C[i-1] for j  length[A] downto 1 do B[C[A[j]]]  A[j] C[A[j]]  C[A[j]]-1
  • 7. Counting Sort (a) A 3 0 3 2 0 3 5 2 5 4 3 2 1 8 7 6 C 1 0 3 2 0 2 4 3 2 1 0 5
  • 8. Counting Sort (b) C 8 7 7 4 2 2 4 3 2 1 0 5
  • 9. Counting Sort (c) B 3 5 4 3 2 1 8 7 6 C 8 7 6 4 2 2 4 3 2 1 0 5
  • 10. Counting Sort (d) B 3 0 5 4 3 2 1 8 7 6 C 8 7 6 4 2 1 4 3 2 1 0 5
  • 11. Counting Sort (e) B 3 3 0 5 4 3 2 1 8 7 6 C 8 7 5 4 2 1 4 3 2 1 0 5
  • 12. Counting Sort (f) B 5 3 3 3 2 2 0 0 5 4 3 2 1 8 7 6
  • 13. How much time does Counting Sort require? The first for loop takes time θ (k) second for loop takes time θ (n) third for loop takes time θ (k) fourth for loop takes time θ (n) Thus the overall time is θ (k+n). In which case the running time is θ (n.