Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1: (15 marks) What is the running time (Big-O notation) for each of the following program fragments? Explain your result in each part. a-

Question 1: (15 marks)
What is the running time (Big-O notation) for each of the following program fragments?
Explain your result in each part.
a- public static String reverse3(String s)
{
int N = s.length();
char[] a = new char[N];
for (int i = 0; i < N; i++)
a[i] = s.charAt(N-i-1);
return new String(a);
}
b- int sum = 0;
for(int i=1;i
for(int j=1;j
for(int k=1;k
if (j % i==1)
sum++;
c- public static String reverse1(String s)
{
int N = s.length();
count=0;
String reverse = " ";
for (int i = 0; i < N; i++)
reverse = s.charAt(i) + reverse;
for (int j=0;j
count++;
return reverse;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago