'How to count this operation for (int interval = n/2; interval > 0; interval /= 2) using counting primitive operation?
I was confused how to label this for (int interval = n/2; interval > 0; interval /= 2) with counting operation and estimating this operation
so that I can get that exact Running time of this shell short algorithm
for (int interval = n/2; interval > 0; interval /= 2)
{
for (int i = interval; i < n; i += 1)
{
/* store a[i] to the variable temp and make the ith position empty */
int temp = a[i];
int j;
for (j = i; j >= interval && a[j - interval] > temp; j -= interval)
a[j] = a[j - interval];
// put temp (the original a[i]) in its correct position
a[j] = temp;
}
}
1 (1 or log base 2)?
int interval = n / 2
now here with condition that I am referring as i < 0 which is n+1 in other operation sample.
(n+1)
interval > 0
I know that the operation of this is log base2
log base 2
interval /= 2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
