Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Analyze the running time of the following algorithm fooC in terms of n . 1 fooC ( C , n , x ) 2 /

Analyze the running time of the following algorithm fooC in terms of n.
1 fooC(C, n, x)
2// Input: An array C of n numbers and a character x
3 total =0
4 if x =='a'
5 for i =0 to n -1
6 total = total + C[i]
7 else if x =='b'
8 for i =0 to n -1
9 for j =1 to i
10 total = total + j * C[i]
11 print total
(1)(2.5 pts) What is the worst-case running time of fooC? You may use either Big-O or Big- notation. Explain what kind of input would lead to this worst-case running time.
(2)(2.5 pts) What is the best-case running time of fooC? You may use either Big-\Omega or Big- notation. Explain what kind of input would lead to this best-case running time.

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

Define Management or What is Management?

Answered: 1 week ago

Question

What do you understand by MBO?

Answered: 1 week ago

Question

Understand human resources role in performance appraisals

Answered: 1 week ago