4 Lecture
CS502
Midterm & Final Term Short Notes
Sorting
Sorting is the process of arranging items in a particular order. It is a fundamental concept in computer science and used in various applications such as database management, data analysis, and algorithm design. There are numerous sorting algori
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- Which of the following is not a sorting algorithm?
a) Merge sort
b) Bubble sort
c) Hash sort
d) Quick sort
Solution: c) Hash sort
Which sorting algorithm has the worst-case time complexity of O(n^2)?
a) Quick sort
b) Merge sort
c) Bubble sort
d) Radix sort
Solution: c) Bubble sort
Which of the following sorting algorithms is a stable sort?
a) Heap sort
b) Insertion sort
c) Quick sort
d) Selection sort
Solution: b) Insertion sort
Which sorting algorithm is used by the C++ STL sort() function?
a) Quick sort
b) Merge sort
c) Heap sort
d) Bubble sort
Solution: a) Quick sort
Which sorting algorithm is often used for sorting linked lists?
a) Quick sort
b) Merge sort
c) Bubble sort
d) Selection sort
Solution: b) Merge sort
Which of the following sorting algorithms has a worst-case time complexity of O(n log n)?
a) Quick sort
b) Bubble sort
c) Insertion sort
d) Selection sort
Solution: a) Quick sort
Which sorting algorithm works by repeatedly finding the minimum element from the unsorted part of the array and putting it at the beginning?
a) Merge sort
b) Quick sort
c) Selection sort
d) Bubble sort
Solution: c) Selection sort
Which of the following is a disadvantage of using quick sort?
a) Worst-case time complexity is O(n^2)
b) It is not a comparison-based sorting algorithm
c) It requires extra space for the temporary array
d) It is not an in-place sorting algorithm
Solution: a) Worst-case time complexity is O(n^2)
Which sorting algorithm can be used for sorting strings in lexicographic order?
a) Bubble sort
b) Quick sort
c) Insertion sort
d) Radix sort
Solution: d) Radix sort
Which sorting algorithm is based on the divide-and-conquer strategy?
a) Bubble sort
b) Selection sort
c) Merge sort
d) Quick sort
Solution: c) Merge sort
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is sorting? Answer: Sorting is the process of arranging items in a specific order, typically numerical or alphabetical order, to make them easier to access, search, and analyze. What is the difference between stable and unstable sorting algorithms? Answer: Stable sorting algorithms maintain the relative order of equal elements in the sorted output, while unstable sorting algorithms do not guarantee this. What is the worst-case time complexity of bubble sort? Answer: The worst-case time complexity of bubble sort is O(n^2), where n is the number of items being sorted. What is quick sort, and how does it work? Answer: Quick sort is a divide-and-conquer sorting algorithm that works by partitioning an array into two sub-arrays, one containing elements less than a pivot element, and the other containing elements greater than the pivot. It then recursively sorts the sub-arrays. What is the difference between in-place and out-of-place sorting algorithms? Answer: In-place sorting algorithms sort the input array by modifying it, while out-of-place sorting algorithms sort the input array by creating a new, sorted array. What is insertion sort, and how does it work? Answer: Insertion sort is a simple sorting algorithm that works by iterating through an array, comparing each element with the preceding elements, and swapping them if they are out of order. What is the difference between comparison-based and non-comparison-based sorting algorithms? Answer: Comparison-based sorting algorithms compare elements in the input array to determine their order, while non-comparison-based sorting algorithms use other methods, such as counting or hashing, to sort the elements. What is merge sort, and how does it work? Answer: Merge sort is a divide-and-conquer sorting algorithm that works by dividing an array into two halves, recursively sorting each half, and then merging the two sorted halves into a single sorted array. What is radix sort, and how does it work? Answer: Radix sort is a non-comparison-based sorting algorithm that works by sorting elements based on their digits or characters, from the least significant to the most significant. What is the best-case time complexity of quick sort? Answer: The best-case time complexity of quick sort is O(n log n), where n is the number of items being sorted.