. Calculate complexity of following code. Also explain best case, average case and worst-case complexity of code
. Calculate complexity of following code. Also explain best case, average case and worst-case complexity of code
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
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; i++)
{
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.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps