You are on page 1of 4

7/10/2021 1.What Is The Asymptotic Complexity Of The Followi... | Chegg.

com

  Textbook Solutions Expert Q&A Study Pack Practice

Find solutions for your homework Search

home / study / engineering / computer science / computer science questions and answers / 1.what is the asymptotic complexity of the fo

Question: 1.What is the asymptotic complexity of the following


piece

1.What is the asymptotic complexity of the following

piece of code in Big-Oh notation? Motivate your

answer.

sum = 0;

for (j=1; j<=n; j++)

for (i=1; i<=j; i++)

sum++;

for (k=0; k<n; k++)

A[k] = k;
2. Sort the given array using insertion sort. Show the
steps of your simulation.
4 76 172 -1 87 -93 666
The Code:

class InsertionSort {

/*Function to sort array using insertion sort*/

void sort(int arr[])

int n = arr.length;

for (int i = 1; i < n; ++i) {

int key = arr[i];

int j = i - 1;

/* Move elements of arr[0..i-1], that are

greater than key, to one position ahead

of their current position */

while (j >= 0 && arr[j] > key) {

arr[j + 1] = arr[j];

j = j - 1;

arr[j + 1] = key;

Expert Answer

Anonymous answered this


Was this answer helpful? 0
1,124 answers

https://www.chegg.com/homework-help/questions-and-answers/1-asymptotic-complexity-following-piece-code-big-oh-notation-motivate-answer-sum-0… 1/4
7/10/2021 1.What Is The Asymptotic Complexity Of The Followi... | Chegg.com

  Textbook Solutions Expert Q&A Study Pack Practice

https://www.chegg.com/homework-help/questions-and-answers/1-asymptotic-complexity-following-piece-code-big-oh-notation-motivate-answer-sum-0… 2/4
7/10/2021 1.What Is The Asymptotic Complexity Of The Followi... | Chegg.com

As per the Chegg guidelines we are strictly instructed to answer


only the first most question only.
  Textbook Solutions
Kindly comment for queries, if any.
Expert Q&A Study Pack Practice

Thank you.

View comments (1)

Up next for you in Computer Science

Sort the given array using


1. i) Solve the following

insertion sort. Show the recurrence relations with

steps
Master Method and

of your simulation. 4 76 comment on the runtime

172 -1
complexities (i.e. Big- See more questions
87 -93 666 The Code: Theta).
for subjects you study
class
(a) T(n) = 9T(n/3) + n2 (b)
InsertionSort { /*Function T(n)

See answer See answer

Questions viewed by other students

Q: Sort the given array using insertion sort. Show the steps of
your simulation.
4 76 172  -1  87  -93  666
The Code: c
InsertionSort { /*Function to sort array using
insertion sort*/ void sort(int arr[]) { int n = arr.length; for
(int i = 1; i <
++i) { int key = arr[i]; int j = i - 1; /*
Move elements of arr[0..i-1], that are greater than key, to one...

A: See answer

Q: 1. i) Solve the following recurrence relations with Master


Method and comment on the runtime complexities
(i.e.
Theta).
(a) T(n) = 9T(n/3) + n2
(b) T(n) = 2T(n/2) + nlogn
ii) Solve the recurrence with iterative substitution
method
comment on the runtime complexities
(i.e. Big-Theta).
(a) T(n) = 2T(n/2) + cn
(b) T(n) = 2T(n/2) + n

A: See answer

https://www.chegg.com/homework-help/questions-and-answers/1-asymptotic-complexity-following-piece-code-big-oh-notation-motivate-answer-sum-0… 3/4
7/10/2021 1.What Is The Asymptotic Complexity Of The Followi... | Chegg.com

  Textbook Solutions Expert Q&A Study Pack Practice


COMPANY

LEGAL & POLICIES

CHEGG PRODUCTS AND SERVICES

CHEGG NETWORK

CUSTOMER SERVICE

© 2003-2021 Chegg Inc. All rights reserved.

https://www.chegg.com/homework-help/questions-and-answers/1-asymptotic-complexity-following-piece-code-big-oh-notation-motivate-answer-sum-0… 4/4

You might also like