Question

QUESTION 8

  1. What is the worst-case complexity of line 7 of function bar?

1 2 int bar (int* A, int* B, int N) { int count = 0; for (int i = 0; i < N; ++i) O vouw int x = A[i]; int pos = binarySearch

A.

O(1)

B.

O(N)

C.

O(i)

D.

O(log N)

E.

O(sqrt N)

F.

O(A[i])

G.

O(N sqrt N)

H.

O(N log N)

I.

O(N^2)

J.

O(i^2)

K.

None of the above

QUESTION 9

  1. What is the worst-case complexity of lines 6-11 of function bar?

1 2 int bar (int* A, int* B, int N) P { int count = 0; for (int i = 0; i < N; ++i) 00 voow int x = A[i]; int pos = sequential

A.

O(1)

B.

O(N)

C.

O(i)

D.

O(log N)

E.

O(sqrt N)

F.

O(A[i])

G.

O(N sqrt N)

H.

O(N log N)

I.

O(N^2)

J.

O(i^2)

K.

None of the above

QUESTION 10

  1. What is the worst-case complexity of lines 4-12 of function bar?

1 2 int bar (int* A, int* B, int N) P { int count = 0; for (int i = 0; i < N; ++i) 00 voow int x = A[i]; int pos = sequential

A.

O(1)

B.

O(N)

C.

O(i)

D.

O(log N)

E.

O(sqrt N)

F.

O(A[i])

G.

O(N sqrt N)

H.

O(N log N)

I.

O(N^2)

J.

O(i^2)

K.

None of the above

0 0
Add a comment Improve this question Transcribed image text
Answer #1
QUESTION 8
Time complexity of binary search is O(logn)
Line 7 runs for n times.
So, total time complexity = O(nlog(n))
Answer:
O(N log N)

QUESTION 9
Time complexity of sequentialOrderSearch is O(n)
Each Line from 6-11 runs for n times.
So, total time complexity = O(n*n) = O(n^2)
Answer:
O(N^2)

QUESTION 10
Time complexity of sequentialOrderSearch is O(n)
Each Line from 4-12 runs for n times.
So, total time complexity = O(n*n) = O(n^2)
worst-case complexity of lines 4-12 of function bar = O(n^2) 
Answer:
O(N^2)
Add a comment
Know the answer?
Add Answer to:
QUESTION 8 What is the worst-case complexity of line 7 of function bar? A. O(1) B....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT