Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java 5Consider the same method again: public boolean isprefix(String s1, String s2) { int i = 0; if(s1.length > s2.length) return false; while(i < s1.length)

  1. java
  2. 5Consider the same method again:

public boolean isprefix(String s1, String s2) { int i = 0; if(s1.length > s2.length) return false; while(i < s1.length) { if(s1[i] != s2[i]) return false; i++; } return true; }

Use the active operation approach and determine the exact number of times the active operation is executed in the worst case. Express your answer in terms of n, the length of the string s1.

Hint: simplify your final answer as much as possible, and do not put spaces in your answer. Use juxtaposition for the multiplication operator, for example to write "nine times n" write "9n" not "9xn" or "9*n"; to write "four times (n+2)" write "4(n+2)", not "4x(n+2)" or "4*(n+2)". Do not write your answer in Big-O notation. Write the exact number of lines executed.

6 Consider the following method:

public void v(String a[]) { for(int i = 0; i < a.length; i++) { a[i] = reverse(a[i]); } }

Assume that the method reverse() has a time complexity of O(n). If we use the active operation approach to determine the time complexity of this method, which line should we choose as the active operation?

Group of answer choices

for(int i = 0; i < a.length; i++) {

a[i] = reverse(a[i]);

7 Consider the following method:

public void v(String a[]) { for(int i = 0; i < a.length; i++) { a[i] = reverse(a[i]); } }

Again, assuming that the method reverse() has a time complexity of O(log n), what is the overall time complexity of this method in Big-O notation (where n is the length of the string array a?

Group of answer choices

O(n)

O(log(n))

O(nlog(n))

O(n^2)

8.Simplify the following expression using the rules on slide 11 of the Topic 3 exercise pack.

O(n) + O(n) + O( n^2 ) * O(n) + 42O(log n)

Hint: simplify your final answer as much as possible, and do not put spaces in your answer. Use juxtaposition for the multiplication operator, for example to write "nine times n" write "9n" not "9xn" or "9*n"; to write "four times (n+2)" write "4(n+2)", not "4x(n+2)" or "4*(n+2)".

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_2

Step: 3

blur-text-image_step3

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

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

ISBN: 1844804526, 978-1844804528

More Books

Students also viewed these Databases questions