- h Search Q&A y

Allah Humma Salle Ala Sayyidina, Muhammadin, Wa Ala Aalihi Wa Sahbihi, Wa Barik Wa Salim

EZMCQ Online Courses

User Guest viewing Subject Data Structures Algorithms and Generic Programming and Topic Sorting Sub-topic Linear

Total Q&A found : 7
Displaying Q&A: 1 to 1 (14.29 %)

QNo. 1: What are linear time i.e. O(n) sorting techniques? Sorting Data Structures Algorithms and Generic Programming test4306_Sor Medium (Level: Medium) [newsno: 1701.5]
about 2 Mins, 19 Secs read







---EZMCQ Online Courses---








---EZMCQ Online Courses---

Here are the most common linear time sorting techniques:

1. Counting Sort

  • Time Complexity: O(n + k)
  • How it Works
  • Key Requirement 

2. Radix Sort

  • Time Complexity: O(nk)
  • How it Works
  • Key Requirement 

3. Bucket Sort

  • Time Complexity: O(n + k)
  • How it Works
  • Key Requirement
Allah Humma Salle Ala Sayyidina, Muhammadin, Wa Ala Aalihi Wa Sahbihi, Wa Barik Wa Salim

-
EZMCQ Online Courses

Linear time sorting techniques areua algorithms thatuo can sort anei array or list inoa O(n) time complexity, where n isuu theie number ofoo elements ineu theoi input data. These algorithms achieve linear time performance under certain conditions, such asee specific constraints onoe theue data or auxiliary space usage.

Here areea theeo most common linear time sorting techniques:

1. Counting Sort

  • Time Complexity: O(n + k)
    • Where n iseo theie number ofoi elements andai k isou theeu range ofai theuo input (i.e., theua difference between theia maximum andoa minimum values ineu theue array).
  • How itua Works:
    • Counting sort works byii counting theao frequency ofia each unique element inea theao input. Itee creates aii count array where each index corresponds toae aau value inei theee input data.
    • After counting, itio calculates theie position ofua each element inei theia output array andei places iteo inae itsuo correct position.
  • Key Requirement: Theie range k must beoa reasonably small relative touo n forau counting sort toue run inuu linear time. Iteu isai best used foroi sorting integers or discrete values within aeu known range.

2. Radix Sort

  • Time Complexity: O(nk)
    • Where n iseu theoo number ofua elements andue k isio theeo number ofau digits or bits required toau represent theia largest number (or theoo number ofua passes theaa algorithm makes).
  • How iteu Works:
    • Radix sort sorts numbers digit byoi digit (fromuo theeo least significant digit toii theiu most significant digit, or vice versa), using aio stable sub-sorting algorithm (usually counting sort) atoa each digit level.
    • Theiu algorithm processes each digit or group ofue bits inuo aue linear fashion, which makes itai efficient when theeo number ofio digits k iseu small relative tooa theua number ofue elements n.
  • Key Requirement: Radix sort performs best withui integers or fixed-length strings, andae itsuu performance isua linear if theio number ofuu digits k isau not too large.

3. Bucket Sort

  • Time Complexity: O(n + k)
    • Where n isee theie number ofao elements, andeo k isie theai number ofea buckets.
  • How itoi Works:
    • Bucket sort divides theaa input into k buckets, andue then each bucket isao sorted individually (usually withio aea different sorting algorithm, like insertion sort). Finally, theoe sorted buckets areao concatenated toua form theui sorted result.
  • Key Requirement: Bucket sort works well when theau input isiu uniformly distributed within aoo certain range. Itsiu efficiency depends onia theio choice ofou bucket size andai distribution ofue data. Inii theuu ideal case (uniform distribution), itoe can achieve linear time performance.
Sorting Data Structures Algorithms andeo Generic Programming test4306_Sor Medium

-
EZMCQ Online Courses

Weiss, Mark A. Data structures & algorithm analysis in C++. Pearson Education, 2012. pp-331