5 Lecture

CS502

Midterm & Final Term Short Notes

Linear Time Sorting

Linear time sorting is a class of sorting algorithms that have a time complexity of O(n), where n is the number of elements being sorted. These algorithms are particularly useful for large datasets as they have a much faster runtime than traditi


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. Which of the following is a linear time sorting algorithm? a) Quick sort b) Merge sort c) Counting sort d) Selection sort Answer: c) Counting sort Which of the following is not a linear time sorting algorithm? a) Bucket sort b) Radix sort c) Quick sort d) All of the above Answer: c) Quick sort What is the worst-case time complexity of counting sort? a) O(n) b) O(n log n) c) O(n^2) d) It depends on the input Answer: a) O(n) Which of the following sorting algorithms is not comparison-based? a) Bucket sort b) Radix sort c) Quick sort d) All of the above Answer: d) All of the above Which of the following is an advantage of linear time sorting algorithms? a) They have a faster runtime than comparison-based sorting algorithms. b) They work for all types of data. c) They have a lower memory usage than comparison-based sorting algorithms. d) They are more accurate than comparison-based sorting algorithms. Answer: a) They have a faster runtime than comparison-based sorting algorithms. Which of the following sorting algorithms is based on dividing elements into buckets? a) Counting sort b) Radix sort c) Bucket sort d) Selection sort Answer: c) Bucket sort Which of the following sorting algorithms is based on comparing digits or characters? a) Counting sort b) Radix sort c) Bucket sort d) Selection sort Answer: b) Radix sort Which of the following sorting algorithms requires additional memory for the buckets? a) Counting sort b) Radix sort c) Bucket sort d) Selection sort Answer: c) Bucket sort Which of the following is an example of an input that counting sort cannot sort in linear time? a) An array of integers b) A string of characters c) A binary tree d) A linked list Answer: b) A string of characters Which of the following is not a stable sorting algorithm? a) Counting sort b) Radix sort c) Bucket sort d) Selection sort Answer: d) Selection sort



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is linear time sorting? Answer: Linear time sorting is a class of sorting algorithms that can sort a given set of data in linear time, meaning the time complexity is proportional to the number of elements being sorted. What is the time complexity of counting sort? Answer: The time complexity of counting sort is O(n), where n is the number of elements being sorted. What is the difference between comparison-based sorting algorithms and linear time sorting algorithms? Answer: Comparison-based sorting algorithms compare elements to determine their order, while linear time sorting algorithms use other methods to determine their order, such as counting or bucketing. Can counting sort be used to sort negative integers? Answer: No, counting sort cannot be used to sort negative integers because it requires non-negative integers as input. What is the purpose of the bucket sort algorithm? Answer: The bucket sort algorithm divides the input data into a number of smaller buckets, which are then sorted using another algorithm. The sorted buckets are then concatenated to form the final sorted output. What is the time complexity of radix sort? Answer: The time complexity of radix sort is O(d(n+k)), where d is the number of digits in the maximum element, n is the number of elements being sorted, and k is the maximum value of a digit. Is radix sort a stable sorting algorithm? Answer: Yes, radix sort is a stable sorting algorithm because it maintains the relative order of equal elements. How does counting sort work? Answer: Counting sort works by counting the number of occurrences of each element in the input, and then using this information to determine the final sorted order. What is the difference between bucket sort and radix sort? Answer: Bucket sort divides the input into a fixed number of equally sized buckets, while radix sort divides the input into a variable number of buckets based on the value of a digit. Can linear time sorting algorithms be used for all types of data? Answer: No, linear time sorting algorithms have certain restrictions on the types of data they can sort, such as requiring non-negative integers for counting sort.

Linear time sorting algorithms are a class of sorting algorithms that have a time complexity of O(n), where n is the number of elements being sorted. This makes them particularly useful for large datasets as they have a much faster runtime than traditional comparison-based sorting algorithms such as quicksort and mergesort. Some examples of linear time sorting algorithms include counting sort, radix sort, and bucket sort. Counting sort works by counting the number of occurrences of each element in the input, and then using this information to determine the final sorted order. It requires non-negative integers as input and has a time complexity of O(n+k), where k is the maximum value of an element in the input. Radix sort works by sorting elements based on their individual digits or characters. It has a time complexity of O(d(n+k)), where d is the number of digits or characters in the maximum element. Radix sort can be used for both integers and strings, making it a versatile sorting algorithm. Bucket sort works by dividing the input into a fixed number of equally sized buckets, which are then sorted using another algorithm such as insertion sort or quicksort. The sorted buckets are then concatenated to form the final sorted output. Bucket sort has a time complexity of O(n+k), where k is the number of buckets used. One limitation of linear time sorting algorithms is that they have certain restrictions on the types of data they can sort. For example, counting sort requires non-negative integers, and radix sort requires elements to have a fixed number of digits or characters. However, for data that meets these restrictions, linear time sorting algorithms can offer significant performance benefits over comparison-based sorting algorithms. In summary, linear time sorting algorithms provide a faster runtime than comparison-based sorting algorithms for certain types of data. Counting sort, radix sort, and bucket sort are examples of linear time sorting algorithms, each with their own strengths and limitations.