comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Algorithms Homework Help?!?!
Date: Wed, 16 Jan 2013 13:19:28 -0800 (PST)
Date: 2013-01-16T13:19:28-08:00	[thread overview]
Message-ID: <183f4095-ac19-4396-a910-ba9cadfb958b@googlegroups.com> (raw)
In-Reply-To: <wcc622wgbae.fsf@shell01.TheWorld.com>

On Wednesday, January 16, 2013 11:47:37 AM UTC-8, Robert A Duff wrote:
> 
> > Then do my binary search based on this helper function(Posted below). 
> > --This problem MUST include Binary Search in some way.
> 
> That seems like an odd requirement.  Taken literally, it would mean
> you could do a binary search on some unrelated data structure,
> throw away the result, and then solve the real problem some other
> (slower) way.  But that's probably not what your teacher meant.  ;-)
> 
> If I were the teacher, I'd say:
> 
>     The program must run in O(log N) time, where N is ....
>     Note: binary search is an O(log N) algorithm.

When I studied computer science, binary search was something covered in, I think, one of the first-year introductory courses.  Algorithmic analysis was an upper-division course, which I think I took in my third year.  So I don't think this would work.  If this is (as I suspect) an introductory course, the students may not yet even know what O-notation is, let alone know what the expected running time for algorithms is.  (OK, you've given them the hint that binary search is O(log N); but if they don't know what the run time is for other algorithms, it won't help them if you say "You don't have to use binary search; you can use some other algorithm that runs in O(log N) time".)

On top of that, I don't think this homework assignment can be done with an O(log N) algorithm.  It takes an input array that isn't required to be sorted, so there has to be some part of the program that iterates through the entire array.  In the OP's first program, he put his binary search in a while loop, and the expected number of iterations would be O(log N) [I'm not sure what N is]; but his loop called a function that scanned through the array, so the actual time is O(N log N) or O(M log N) or something.  I haven't studied the problem in depth to figure out what the best running time is.  It's probably independent of the largest value in the array, while I think the binary search the OP came up with started with an interval based on the largest value in the array, and successively divided it in half to find the answer.

Anyway, I'd tend to agree that it seems odd to *require* binary search, especially since off the top of my head it doesn't seem appropriate for this particular problem.  But classroom problems do have to be contrived, sometimes.  

                         -- Adam




  reply	other threads:[~2013-01-16 21:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-15 21:52 Algorithms Homework Help?!?! willmann817
2013-01-15 22:50 ` Adam Beneschan
2013-01-15 23:50   ` willmann817
2013-01-15 23:43 ` Shark8
2013-01-15 23:54 ` Jeffrey Carter
2013-01-16  0:01   ` willmann817
2013-01-16  3:54     ` willmann817
2013-01-16 19:47 ` Robert A Duff
2013-01-16 21:19   ` Adam Beneschan [this message]
2013-01-16 22:27     ` Robert A Duff
2013-01-16 23:43       ` Adam Beneschan
2013-02-07  7:06 ` ajim
2013-02-07  7:10 ` ajim
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox