Q. Calculate complexity of following code. Also explain best case, average case and worst-case complexity of code. void sort(){ inti, k, cnt; for (i = 1; i { k = arr[i]; cnt = i - 1; do { arr[cnt + 1]...



Q.
Calculate complexity of following code. Also explain best case, average case and worst-case complexity of code.


void sort()
{
    inti, k, cnt;
    for (i = 1; i < n;="">
    {
         k = arr[i];
         cnt = i - 1;
         do
         {
             arr[cnt + 1] = arr[cnt];
             cnt = cnt - 1;
         } while (cnt>= 0 &&arr[cnt] > k);
         arr[cnt + 1] = k;
    }
 }



Attaching the image below too.


(b)<br>Calculate complexity of following code. Also explain best case, average case and<br>worst-case complexity of code<br>void sort()<br>{<br>inti, k, cnt;<br>for (i = 1; i<n; i++)<br>{<br>k = arr[i];<br>cnt = i - 1;<br>do<br>{<br>arr[cnt + 1] = arr[cnt];<br>cnt = cnt -1;<br>} while (cnt>= 0 &&arr[cnt] > k);<br>arr[cnt + 1] = k;<br>}<br>}<br>

Extracted text: (b) Calculate complexity of following code. Also explain best case, average case and worst-case complexity of code void sort() { inti, k, cnt; for (i = 1; i= 0 &&arr[cnt] > k); arr[cnt + 1] = k; } }

Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here