3. For each of the following situations, name the best sorting algorithm we studied. (For one or two questions, there may be more than one answer deserving full credit, but you only need to give one answer for each.) The array is mostly sorted already (a few elements are in the wrong place).
(a) You need an O(n log n) sort even in the worst case and you cannot use any extra space except for a few local variables.
(b) The data to be sorted is too big to fit in memory, so most of it is on disk.
(c) You have many data sets to sort separately, and each one has only around 10 elements.
(d) Instead of sorting the entire data set, you only need the k smallest elements where k is an input to the algorithm but is likely to be much smaller than the size of the entire data set.
Q.a ) You need an O(n log n) sort even in the worst case and you cannot use
any extra space except for a few local variables.
Ans :- Heap sort
Time Complexity T(n) = O(nlogn)
Explanation : In form virtual binary-tree like structure, I said virtual because to form tree it
doesn't uses extra space to store address of child. Here child of an array[ I ] are
array[ 2*I +1 ] and array[ 2*I + 2 ].
Comparison takes place between it's child, parent will smaller than child.
Q.b ) The data to be sorted is too big to fit in memory, so most of it is on disk.
Ans :- Merge Sort
Time Complexity T(n) = O(nlogn)
Explanation : Since merge sort uses two extra array as left_array[ L ] and right_array[ R ]
to store sorted elements on left side and sorted elements of right side and finally comparison
takes and merged together to form third array of size L+R which sorted.
So for this purpose merge sort uses large amount of memory. That's why it uses external space
Disk or tape.
Q.c ) You have many data sets to sort separately, and each one has only around 10
elements.
Ans :- Bucket sort
Time Complexity T(n) = O(k + n)
Explanation : Bucket sort is an algorithm for sort uniformly separated packet of elements.
here what we do..
Q.d ) Instead of sorting the entire data set, you only need the k smallest elements
where k is an input to the algorithm but is likely to be much smaller than the
size of the entire data set.
Ans :- Bubble sort
Time Complexity T(n) = O(k*n)
Explanation : In Bubble sort, let arr[n] be an array of size n. We have two loops
1) outer loop varies from 0 to k-1. it runs only k times. Iterator as I i.e. for( I = 0; I < K; I++)
2) inner loop varies from n-1 to 0. it runs n times. Iterator as J i.e. for( J = n-1; J > 0; J--)
3) on every iteration of I,comparison takes place from last element i.e. Jth & (J-1)th element.
a) we check arr[J-1] > arr[J], if holds true swap then
b) this will continues till value of J became 0.
4) finally we iterator for I =0 to I = K-1 and prints each elements as they are K smallest elements.
Please upvote if it helps. Feel free to comment if you have any query.
***thank you***
3. For each of the following situations, name the best sorting algorithm we studied. (For one...
Data Structures: For each of the following situations, name the best sorting algorithm we studied. (For one or two questions, there may be more than one answer deserving full credit, but you only need to give one answer for each.) (a) The array is mostly sorted already (a few elements are in the wrong place). (b) You need an O(n log n) sort even in the worst case and you cannot use any extra space except for a few local...
Sorting: (40 points) a. We studied several sorting algorithms. Every sorting algorithm has their own special reason where it can only use. Can you explain carefully in which situation the following algorithms would be best sorting algorithm to use in an application. (10 points) i. Insertion sort ii. Selection sort iii. Merge sort iv. Quick sort b. You are given a string of elements as below, Canopus, Mimosa, Betelgeuse, Deneb, Stars, Pollux, Antares, Sirius, Hader i. Your task is to...
a. We studied several sorting algorithms. Every sorting algorithm has their own special reason where it can only use. Can you explain carefully in which situation the following algorithms would be best sorting algorithm to use in an application. (10 points) i. Insertion sort ii. Selection sort iii. Merge sort iv. Quick sort b. You are given a string of elements as below, Canopus, Mimosa, Betelgeuse, Deneb, Stars, Pollux, Antares, Sirius, Hader i. Your task is to insert the above...
QUESTION 3 Suppose that you have been running an unknown sorting algorithm. Out of curiosity, you once stopped the algorithm when it was part-way done and examined the partially sorted array. You discovered that the last K elements of the array were sorted into ascending order, but the remainder of the array was not ordered in any obvious manner. Based on this, you guess that the sorting algorithm was (select all that apply): heapsort insertion sort mergesort quicksort Shell's sort...
please I need it urgent thanks algorithms
2.1 Searching and Sorting- 5 points each 3. What is the worst case for quick sort? What is the worst case time com- plexity for quick sort and why? Explain what modifications we can make to quick sort to make it run faster, and why this helps. 4. Give pseudocode for an algorithm that will solve the following problem. Given an array AlL..n) that contains every number between 1 and n +1 in...
Java Match the sorting algorithm with its time complexity, where n is the number of elements in the collection and k is the range of values. (This is a one-for-one match where an answer can only match one description.) Group of answer choices selection sort [ Choose ] O(n + k) O(n) to O(n^2) O(n log n) O(n^2) bubble sort [ Choose...
1.3 Which of the following is true about sorting functions?A.The most optimal partitioning policy for quicksort on an array we know nothing about wouldbe selecting a random element in the array.B.The fastest possible comparison sort has a worst case no better than O(n log n).C.Heapsort is usually best when you need a stable sort.D.Sorting an already sorted array of size n with quicksort takes O(n log n) time.E.When sorting elements that are expensive to copy, it is generally best to...
You are working as the software developer and need to identify the best sorting algorithm. Please refer to the following URL: https://www.geeksforgeeks.org/sorting-algorithms/ You can pick any two-sorting algorithm. You need to determine which sorting algorithm is the best to sort the array of 10k elements. Use the following steps to help with your solution: Create C++ functions for any two-sorting algorithm. Write down the random array generation function to generate at least 10k elements. Pass the same array into both...
2.1 Searching and Sorting- 5 points each 1. Run Heapsort on the following array: A (7,3, 9, 4, 2,5, 6, 1,8) 2. Run merge sort on the same array. 3. What is the worst case for quick sort? What is the worst case time com- plexity for quick sort and why? Explain what modifications we can make to quick sort to make it run faster, and why this helps. 4. Gi pseudocode for an algorithm that will solve the following...
I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonical zing data and for producing human-readable output. More formally, the output must satisfy...