Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following function. Given an array A [ 1 . . n ] of numbers and an input integer m ( 1 = m

Consider the following function. Given an array A[1..n] of numbers and an input integer m (1= m = n), return the sum: A[1]+...+ A[m].
F(A, n, m)// Add A[1] to A[m]{
sum =0;
for i =1 to m {
sum = sum + A[i];
}
return sum;
}
a) What values of m will be the (a) worst case; (b) best case? And how many statements will be executed in these two cases?
b) Based on the following probabilities, calculate the average number of statements to be executed in the average case. The probabilities that the value of m will be: Prob(m =1)=1/2, Prob(m = n)=1/3, Prob(m = other values, i.e.,2 or 3 or ... or n-1)=1/[6(n-2)].
image text in transcribed

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

Discuss the key ambient conditions and their effects on customers.

Answered: 1 week ago

Question

Be familiar with the integrative servicescape model.

Answered: 1 week ago

Question

Understand the role of corporate design in communications.

Answered: 1 week ago