Could someone run through or submit an answer for Chapter 2
Could someone run through or submit an answer for Chapter 2, Excercies 2, part a in Data Structures and Algorithm Analysis in C++, 4th ed by Mark Weiss. It\'s asking for the run-time complexities (in BigO notation) of a few C++ coding segments, and I want to make sure my analysis is correct.
Solution
Let’s suppose that we want to create a function that, when given an array of integers greater than 0, will return the integer that is the smallest in that array.
In order to best illustrate the way Big-O analysis works, we will come up with twodifferent solutions to this problem, each with a different Big-O efficiency.
Here’s our first function that will simply return the integer that is the smallest in the array. The algorithm will just iterate through all of the values in the array and keep track of the smallest integer in the array in the variable called curMin.
Let’s assume that the array being passed to our function contains 10 elements – this number is something we arbitrarily chose. We could have said it contains 100, or 100000 elements – either way it would have made no difference for our purposes here.
we want to show you another solution to the problem. In this solution, we will use a different algorithm - we will soon compare the big O Notation of the two different solutions below. What we do for our second solution to the problem is compare each value in the array to all of the other numbers in the array, and if that value is less than or equal to all of the other numbers in the array then we know that it is the smallest number in the array.
