SlideShare uma empresa Scribd logo
1 de 13
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.

Mais conteúdo relacionado

Mais procurados

Lecture 12 data structures and algorithms
Lecture 12 data structures and algorithmsLecture 12 data structures and algorithms
Lecture 12 data structures and algorithmsAakash deep Singhal
 
SORTTING IN LINEAR TIME - Radix Sort
SORTTING IN LINEAR TIME - Radix SortSORTTING IN LINEAR TIME - Radix Sort
SORTTING IN LINEAR TIME - Radix SortDevanshu Taneja
 
Lecture 6 data structures and algorithms
Lecture 6 data structures and algorithmsLecture 6 data structures and algorithms
Lecture 6 data structures and algorithmsAakash deep Singhal
 
Merge sort code in C explained
Merge sort code in C explained Merge sort code in C explained
Merge sort code in C explained Mohit Tare
 
Heaps & Adaptable priority Queues
Heaps & Adaptable priority QueuesHeaps & Adaptable priority Queues
Heaps & Adaptable priority QueuesPriyanka Rana
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaPriyanka Rana
 
lecture 15
lecture 15lecture 15
lecture 15sajinsc
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Pramit Kumar
 
3.6 radix sort
3.6 radix sort3.6 radix sort
3.6 radix sortKrish_ver2
 
Presentation on binary search, quick sort, merge sort and problems
Presentation on binary search, quick sort, merge sort  and problemsPresentation on binary search, quick sort, merge sort  and problems
Presentation on binary search, quick sort, merge sort and problemsSumita Das
 

Mais procurados (20)

Bucket sort
Bucket sortBucket sort
Bucket sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Lecture 12 data structures and algorithms
Lecture 12 data structures and algorithmsLecture 12 data structures and algorithms
Lecture 12 data structures and algorithms
 
SORTTING IN LINEAR TIME - Radix Sort
SORTTING IN LINEAR TIME - Radix SortSORTTING IN LINEAR TIME - Radix Sort
SORTTING IN LINEAR TIME - Radix Sort
 
Lecture 6 data structures and algorithms
Lecture 6 data structures and algorithmsLecture 6 data structures and algorithms
Lecture 6 data structures and algorithms
 
Merge sort code in C explained
Merge sort code in C explained Merge sort code in C explained
Merge sort code in C explained
 
Heaps & Adaptable priority Queues
Heaps & Adaptable priority QueuesHeaps & Adaptable priority Queues
Heaps & Adaptable priority Queues
 
Maps&hash tables
Maps&hash tablesMaps&hash tables
Maps&hash tables
 
Sorting2
Sorting2Sorting2
Sorting2
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
 
Sorting
SortingSorting
Sorting
 
Nikit
NikitNikit
Nikit
 
Bucket sort
Bucket sortBucket sort
Bucket sort
 
Marge Sort
Marge SortMarge Sort
Marge Sort
 
Sorting
SortingSorting
Sorting
 
lecture 15
lecture 15lecture 15
lecture 15
 
Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)Matrix Multiplication(An example of concurrent programming)
Matrix Multiplication(An example of concurrent programming)
 
3.6 radix sort
3.6 radix sort3.6 radix sort
3.6 radix sort
 
Presentation on binary search, quick sort, merge sort and problems
Presentation on binary search, quick sort, merge sort  and problemsPresentation on binary search, quick sort, merge sort  and problems
Presentation on binary search, quick sort, merge sort and problems
 

Semelhante a chapter-8.ppt

Semelhante a chapter-8.ppt (20)

Cis435 week01
Cis435 week01Cis435 week01
Cis435 week01
 
03
0303
03
 
Ee693 sept2014midsem
Ee693 sept2014midsemEe693 sept2014midsem
Ee693 sept2014midsem
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
Cis435 week06
Cis435 week06Cis435 week06
Cis435 week06
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
 
Analysis of Algorithum
Analysis of AlgorithumAnalysis of Algorithum
Analysis of Algorithum
 
Lec7
Lec7Lec7
Lec7
 
Lec7.ppt
Lec7.pptLec7.ppt
Lec7.ppt
 
Lec7.ppt
Lec7.pptLec7.ppt
Lec7.ppt
 
analysis of algorithms
analysis of algorithmsanalysis of algorithms
analysis of algorithms
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
Counting Sort Lowerbound
Counting Sort LowerboundCounting Sort Lowerbound
Counting Sort Lowerbound
 
Lec1
Lec1Lec1
Lec1
 
Slide2
Slide2Slide2
Slide2
 
LalitBDA2015V3
LalitBDA2015V3LalitBDA2015V3
LalitBDA2015V3
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Ashish garg research paper 660_CamReady
Ashish garg research paper 660_CamReadyAshish garg research paper 660_CamReady
Ashish garg research paper 660_CamReady
 
Sensor Fusion Study - Ch3. Least Square Estimation [강소라, Stella, Hayden]
Sensor Fusion Study - Ch3. Least Square Estimation [강소라, Stella, Hayden]Sensor Fusion Study - Ch3. Least Square Estimation [강소라, Stella, Hayden]
Sensor Fusion Study - Ch3. Least Square Estimation [강소라, Stella, Hayden]
 

Mais de Tareq Hasan

Grow Your Career with WordPress
Grow Your Career with WordPressGrow Your Career with WordPress
Grow Your Career with WordPressTareq Hasan
 
Caching in WordPress
Caching in WordPressCaching in WordPress
Caching in WordPressTareq Hasan
 
How to Submit a plugin to WordPress.org Repository
How to Submit a plugin to WordPress.org RepositoryHow to Submit a plugin to WordPress.org Repository
How to Submit a plugin to WordPress.org RepositoryTareq Hasan
 
Composer - The missing package manager for PHP
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHPTareq Hasan
 
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
WordPress Theme & Plugin development best practices - phpXperts seminar 2011WordPress Theme & Plugin development best practices - phpXperts seminar 2011
WordPress Theme & Plugin development best practices - phpXperts seminar 2011Tareq Hasan
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.pptTareq Hasan
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array PointerTareq Hasan
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.pptTareq Hasan
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queueTareq Hasan
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-SortTareq Hasan
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
Java: Class Design Examples
Java: Class Design ExamplesJava: Class Design Examples
Java: Class Design ExamplesTareq Hasan
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object ReferencesTareq Hasan
 

Mais de Tareq Hasan (20)

Grow Your Career with WordPress
Grow Your Career with WordPressGrow Your Career with WordPress
Grow Your Career with WordPress
 
Caching in WordPress
Caching in WordPressCaching in WordPress
Caching in WordPress
 
How to Submit a plugin to WordPress.org Repository
How to Submit a plugin to WordPress.org RepositoryHow to Submit a plugin to WordPress.org Repository
How to Submit a plugin to WordPress.org Repository
 
Composer - The missing package manager for PHP
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHP
 
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
WordPress Theme & Plugin development best practices - phpXperts seminar 2011WordPress Theme & Plugin development best practices - phpXperts seminar 2011
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
 
chapter22.ppt
chapter22.pptchapter22.ppt
chapter22.ppt
 
chapter - 6.ppt
chapter - 6.pptchapter - 6.ppt
chapter - 6.ppt
 
chapter23.ppt
chapter23.pptchapter23.ppt
chapter23.ppt
 
chapter24.ppt
chapter24.pptchapter24.ppt
chapter24.ppt
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Java: Exception
Java: ExceptionJava: Exception
Java: Exception
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Java: Class Design Examples
Java: Class Design ExamplesJava: Class Design Examples
Java: Class Design Examples
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 

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.