In: Computer Science
Respond to the following in a minimum of 175 words:
Discuss what you consider to be the first and second priority in a sorting algorithm and justify a key word or phrase to place in the string that is crucial.
Provide a short pseudocode example in your discussion post to defend your thoughts.
Explain your reasoning for selecting your first and second priorities.
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
First priority is given to the time requirement of the execution of algorithm, that is known as time complexity of the algorithm.
Time complexity represents the time requirement for the execution of the algorithm related to the input size. Time complexity of various algorithms are O(n2 ),O(n log n) etc. if the time complexity is O(n2 ) , it represents that the time required to execute the algorithm directly proportional to the square of the input size.
for eg: the pseudo code for bubble sort algorithm is
for(i=0;i<=n-2;i++)
{
for (j=0;j<=n-2-i; j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
} } }
here ‘n’ represents the number of inputs. this algorithm take the time directly proportional to the square of its input size.
other sorting methods like bucket sort algorithm has the complexity O(n+k) in average case. this means that , the algorithm take a time proportional to size of number of inputs (n) and the bucket size (k). so this algorithm is much faster than bubble sort algorithm in case of large inputs.
Second priority given to the way of implementation:
The way of implementation means, some algorithms are very simple to implement such as bubble sort even though they are slow in execution. Similarly some algorithms are difficult to implement, but they are fast in execution such as quicksort algorithm. If the input size is small bubble sort algorithm is good , because of simple implementation. In case of large input size quick sort algorithm is good, because of its faster execution.
Kindly revert for any queries
Thanks.