Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I really have trouble understanding this find min recursion. This recursive method finds the minimum number in an array. This is how I understand it.

image text in transcribed

I really have trouble understanding this find min recursion. This recursive method finds the minimum number in an array.

This is how I understand it.

Suppose I have a array 5, 3 , -5, 8, and startIndex is 0, endIndex is 3

First time, midIndex = (0+3)/2 =1. So it divided between 3 and -5.

And then it goes to findMin, so it passes Array, 0, 1 back to findMin.

Then, the midIndex = (0+1)/2 = 0. And passes Array, 0, 0 back to findMin.

Since startIndex 0 = endIndex 0, return numbers[startIndex](which is 5?).

I can't really figure out how this method finds the minimum number. Since the startIndex is alway 0, why does it need to return numbers[startIndex]? Can you please write step by step how this method works? Thank you.

public static int findin (int numbers int startIndex, int end Index) f if (startIndex end Index) return numbers[startIndex else int mid Index (startIndex end Index) 2 int leftMin findMin (numbers start Index mid Index) int rightMin findMin (numbers midIndex 1, end Index) if (leftMin rightMin) return leftMin; else return rightMin

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

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions