Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1)race the following program fragment.Which of the following lists all the output of the program fragment? Stack st1= new Stack(); Stack st2= new Stack(); st1.push(Integer(2));

1)race the following program fragment.Which of the following lists all the output of the

program fragment?

Stack st1= new Stack();

Stack st2= new Stack();

st1.push(Integer(2));

st2.push(Integer(6));

System.out.print(st1.peek());

System.out.print(st2.pop());

st2.push(st1.peek());

st1.push(Integer(7));

System.out.print(st1.peek());

System.out.print(st2.pop());

System.out.print(st1.pop());

System.out.print(st1.peek());

Select one:

A.267272

B.267262

C.262772

D.267226

2)What is the average case time complexity of sequential search in sorted data?

Select one:

A.O(log n)

B.O(n)

C.O(1)

D.O(n log n)

3)Let say, we have an array named,int marks = {10, 30, 40, 20, 60, 50, 70}. Based on the data in the array, which item will represent the worst case time complexity for the sequential search?

Select one:

A.50

B.20

C.70

D.30

4)Let say, we have an array named,int marks = {10, 20, 30, 40, 50, 60, 70}. Based on the data in the array, which item will represent the best case time complexity for the binary search?

Select one:

A.40

B.10

C.30

D.50

5)Given the following calculateSum() method. The method is used to calculate the sum of numbers recursively.

public static intcalculateSum (int n)

{if (n = = 1) return 1;

else return n * calculateSum (n - 1);

}

Based on the given method:

Which of the following statements is the base case?

Select one:

A.return n * calculateSum(n - 1);

B.if (n == 1)return 1;

C.else return n * calculateSum(n - 1);

D.return 1;

6)Given the following calculateSum() method. The method is used to calculate the sum of numbers recursively.

public static intcalculateSum (int n)

{if (n = = 1) return 1;

elsereturn n * calculateSum (n - 1);

}

Based on the given method:

7)Which of the following statements is the recursive case?

Select one:

A.if (n == 1)return 1;

B.return 1;

C.else return n * calculateSum(n - 1);

D.return n * calculateSum(n - 1);

8)Given the following calculateSum() method. The method is used to calculate the sum of numbers recursively.

public static intcalculateSum (int n)

{if (n = = 1) return 1;

else return n * calculateSum (n - 1);

}

Based on the given method:

By using a stack of activation records in tracing the recursive method, what is the value returned by the method if n = 3?

Select one:

A.24

B.18

C.2

D.6

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_2

Step: 3

blur-text-image_3

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions