Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.I'm confused why we need a +1 in C(n-1)+1. and in recurrence algorithm. 2.Some function have F(n-1)+2, some have F(n-1) +n, some have F(n-1)+n-1. How

1.I'm confused why we need a +1 in C(n-1)+1. and in recurrence algorithm.

2.Some function have F(n-1)+2, some have F(n-1) +n, some have F(n-1)+n-1. How do I know which numbers are added?

image text in transcribedimage text in transcribed

Consider the following recursive algorithm. ALGORITHM Riddle(Ap.n-1]) I/Input: An array A[O..n 1 of real numbers ifn = 1 return A[0] else temp -Riddle(AOn-2]) if temp 1 Where, C(n-1) number of comparisons required to find the smallest number among the n-1 numbers. One comparison is required to find the smallest number between last number in the array(AIn-1]) and the smallest number among the first n-1 numbers(temp) Since, the algorithm stops when n-1 and no comparison happens when n-1, the initial condition will be as follows: Apply substitution method to obtain the solution of the recurrence relation C(n) C(n-1)+1 C(n-2)+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: 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

Students also viewed these Databases questions