Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Simple program to implement binary search |
| Date | 2015-11-12 18:41 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <n22mci$9np$1@dont-email.me> (permalink) |
| References | <af16475b-9f9c-46f8-98c5-9353f82423da@googlegroups.com> <n22fv5$d16$1@reader1.panix.com> <68d1f41e-cda0-4a41-8bc4-8cdff64dac97@googlegroups.com> <n22koi$29t$1@dont-email.me> <2396d114-8e60-4e8a-8375-a32b71726099@googlegroups.com> |
On 12/11/15 18:24, Alla _ wrote: > On Thursday, November 12, 2015 at 10:13:56 PM UTC+4, Richard Heathfield wrote: >> On 12/11/15 18:11, Alla _ wrote: >>> Of course! How could I miss that? Thank you! I have forgotten >>> that recursion requires return. >> >> Whatever gave you that idea? >> >> *This* recursion requires a return value to be returned and tested, >> because it was designed that way. That doesn't mean that all recursive >> functions need to have their return values tested. > > All right. This tells me that I will see that when I do more exercises. The *really* important thing to remember about recursion is that you have to remember to make it stop at some point. This is normally done (I say "normally" because if I don't, I'm sure somebody will come up with a counter-example) by defining a "base case". For example, in your binary search algorithm the base case was that the maximum value was less than the minimum value. This ensured that the algorithm terminated even if the search key wasn't found in the array. Without the base case (or some other way to stop the recursion), the recursion will proceed indefinitely... until the machine runs out of resources, at which point Something Drastic will happen. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Simple program to implement binary search Alla _ <modelling.data@gmail.com> - 2015-11-12 08:12 -0800
Re: Simple program to implement binary search Frank Tetzel <s1445051@mail.zih.tu-dresden.de> - 2015-11-12 17:45 +0100
Re: Simple program to implement binary search John Gordon <gordon@panix.com> - 2015-11-12 16:49 +0000
Re: Simple program to implement binary search Alla _ <modelling.data@gmail.com> - 2015-11-12 10:11 -0800
Re: Simple program to implement binary search Richard Heathfield <rjh@cpax.org.uk> - 2015-11-12 18:13 +0000
Re: Simple program to implement binary search Alla _ <modelling.data@gmail.com> - 2015-11-12 10:24 -0800
Re: Simple program to implement binary search Richard Heathfield <rjh@cpax.org.uk> - 2015-11-12 18:41 +0000
Re: Simple program to implement binary search Chad <cdalten@gmail.com> - 2015-11-12 11:56 -0800
Re: Simple program to implement binary search Richard Heathfield <rjh@cpax.org.uk> - 2015-11-12 16:53 +0000
Re: Simple program to implement binary search Alla _ <modelling.data@gmail.com> - 2015-11-12 10:23 -0800
Re: Simple program to implement binary search Richard Heathfield <rjh@cpax.org.uk> - 2015-11-12 18:35 +0000
Re: Simple program to implement binary search Alla _ <modelling.data@gmail.com> - 2015-11-12 10:50 -0800
Re: Simple program to implement binary search supercat@casperkitty.com - 2015-11-12 11:17 -0800
Re: Simple program to implement binary search Barry Schwarz <schwarzb@dqel.com> - 2015-11-12 11:20 -0800
Re: Simple program to implement binary search Alla _ <modelling.data@gmail.com> - 2015-11-12 23:20 -0800
Re: Simple program to implement binary search Richard Heathfield <rjh@cpax.org.uk> - 2015-11-13 07:23 +0000
Re: Simple program to implement binary search Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-12 10:20 -0800
Re: Simple program to implement binary search Alla _ <modelling.data@gmail.com> - 2015-11-12 10:57 -0800
Re: Simple program to implement binary search Richard Heathfield <rjh@cpax.org.uk> - 2015-11-12 19:01 +0000
Re: Simple program to implement binary search Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-14 11:19 -0800
Re: Simple program to implement binary search Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-14 12:52 -0800
Re: Simple program to implement binary search Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-15 12:48 -0800
Re: Simple program to implement binary search raltbos@xs4all.nl (Richard Bos) - 2015-11-17 22:54 +0000
Re: Simple program to implement binary search Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-20 13:47 -0800
Re: Simple program to implement binary search "Charles Richmond" <numerist@aquaporin4.com> - 2015-11-21 18:26 -0600
Re: Simple program to implement binary search Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-22 08:19 -0500
Re: Simple program to implement binary search mark.bluemel@gmail.com - 2015-11-26 01:08 -0800
Re: Simple program to implement binary search Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-22 13:42 -0800
Re: Simple program to implement binary search "Charles Richmond" <numerist@aquaporin4.com> - 2015-11-23 15:47 -0600
Re: Simple program to implement binary search Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-24 08:44 -0800
Re: Simple program to implement binary search Les Cargill <lcargill99@comcast.com> - 2015-11-16 22:52 -0600
Re: Simple program to implement binary search Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-17 01:02 -0800
Re: Simple program to implement binary search Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-20 13:27 -0800
Re: Simple program to implement binary search Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-13 21:41 -0800
csiph-web