0
Is it okay for Insertion Sort?
9 Respostas
+ 2
Jubaer Ahmad Yes, but its worst runtime is O(nÂČ), whereas Heapsort and Mergesort have a worst runtime of only O(n lg n).
+ 1
When ever you write the swap method you have to check for the pointer identity as below.
Obviously this code works fine without that, but follow the practices.
void swap(int *a, int *b)
{
int temp;
if(a != b)
{
temp = *a ;
*a = *b ;
*b = temp ;
}
}
+ 1
Jubaer Ahmad There is not a problem. If you pass array the second copy of array has to be made. This will add some latency in your code.
Latency means code execution time.
+ 1
Read this
https://brilliant.org/wiki/insertion/
0
Why are you passing array? Don't you think for pointer?
you can use void InsertionSort(int *arr, const int& n) instead of void InsertionSort(int arr[], int n).
0
$Âąđâčđ!đšđ So where's the problem by doing this?
0
In next level you can templatize the code to work with other data types also.
0
$Âąđâčđ!đšđ okay, but the best complexity of Insertion sort is O(n).
My code has same complexity like this?
0
Hello Jubaer Ahmad I made some changes on your code I think u will see this code
https://code.sololearn.com/cOBneZeKT0A0/?ref=app