• About WordPress
    • WordPress.org
    • Documentation
    • Support
    • Feedback
  • Log In
  • Register
  • Home
  • Courses
  • Past Paper
  • FYP
  • Interview Questions
  • University Events
  • Contact
  • Quiz & Assignment
Cuitutorial
  • Home
  • Courses
  • Past Paper
  • FYP
  • Interview Questions
  • University Events
  • Contact
  • Quiz & Assignment

Data Structure

Home » Blog » Counting Sort

Counting Sort

  • Posted by saqib
  • Categories Data Structure
  • Date December 6, 2022
  • Comments 0 comment

Counting sort is a type of Linear Time Sort

  • Counting Sort was invented by H.H.Seward in 1954
  • All the sorting algorithms introduced so far share an                                                interesting property: the sorted order they determine is based only on comparison between the input elements

Assumption of Counting Sort

  • Counting sort assumes that each of the element is an integer and lies in the range 1 to k, for some integer k
  • When k=O(n) then sort runs in O(n) time.
  • Determine how many elements are less than an element x
  • Then place x directly on its correct position
Counting sort
Counting sort working
Counting sort
Counting sort time complexity
Counting sort
Counting sort example

Running Time

  • T(n) = O(k) + O(n) + O(k) + O(n)

= O(k+n+k+n) = O(2k + 2n)

Assumption: k is O(n)

Hence T(n) = O(n)

Thus Counting Sort beats the running time of “nlogn” as it is not a comparison based sort

 

Related links 

Single link list                 Stack              AVL Trees             Binary search          Counting Sort

Doubly link list               Queue              Graphs                  Bubble Sort               Radix sort

Circular link list              Binary search tree       Hashing         Insertion Sort         Bucket Sort

Josephus Problem          Tree Traversal              Heaps                Quick Sort              Merge Sort

 

At Cui tutorial, courses, past papers and final year projects

#tutorial #cui #pastpaper #courses #finalyearproject

 

 

  • Share:
author avatar
saqib

Previous post

Insertion Sort
December 6, 2022

Next post

Drawer in Flutter
December 8, 2022

You may also like

Insertion Sort
6 December, 2022

Insertion Sort using loop and recursive function complete code On the ith pass we “insert” the ith element A[i] into its rightful place among A[1],A[2],…A[i-1] which were placed in sorted order. After this insertion A[1],A[2],…A[i] are in sorted order. Time …

Bubble Sort using C++
6 December, 2022

Bubble sort using loop and bubble sort in link list One of the simplest sorting methods. The basic idea is to move required value (smallest or highest ) to the top. Compare adjacent values (all elements) Swap values if required …

Sorting and searching in data structure
6 December, 2022

What is Sorting? Sorting is the process of ordering a list of objects, according to some linear order, such as £ for numbers. Sorting can be divided into two types i.e. internal and external. Internal sorting takes place in main …

Leave A Reply Cancel reply

You must be logged in to post a comment.

admin@cuitutorial.com
Facebook-f Twitter Youtube Linkedin Instagram Stack-overflow Pinterest Github Quora Whatsapp
Courses
  • All Courses
  • Past Paper
  • Final year projects
  • Interview Questions
  • Contact
Important Pages
  • Privacy Policy
  • Terms of Service
  • Cookie Policy
Links
  • University Events
  • Team
Education & learning platform for All Computer science subjects
Final year projects
Past Paper
Interview questions
Programming, C/C++, Asp.net/MVC. Android, MySql, Jquery, Ajax, javascript, Php, Html5, Bootstrap4.
NTS, GAT, PPSC, FPSC

Copyright © 2021 | Cuitutorial