473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

A question: Is 200,000 element array worth sorting and search?

The topic comes from a question:

Would you rather wait for the results of a quicksort, a linear search,
or a bubble sort on a 200000 element array?
1Quicksort
2Linear Search
3Bubble Sort

The answer is 2Linear Search

Could someone explain why Linear Search, not the other two options?
Or I misunderstood the original question?

Thanks you guys!
Jun 27 '08 #1
26 2543
On 4 May, 23:27, mike-yue <needpass...@gmail.comwrote:
The topic comes from a question:

Would you rather wait for the results of a quicksort, a linear search,
or a bubble sort on a 200000 element array?
1Quicksort
2Linear Search
3Bubble Sort

The answer is 2Linear Search

Could someone explain why Linear Search, not the other two options?
Well, it's a poor question: asking what /you/ would prefer to do; but
presuming you want to wait as little time as possible wouldn't option
2 finish soonest? The fact that sorting and searching accomplish
different things also seems to be there to confuse.

You might be better asking questions on programming (i.e. not on C) in
comp.programming.

--
Jun 27 '08 #2
mike-yue said:
The topic comes from a question:

Would you rather wait for the results of a quicksort, a linear search,
or a bubble sort on a 200000 element array?
1Quicksort
2Linear Search
3Bubble Sort

The answer is 2Linear Search

Could someone explain why Linear Search, not the other two options?
Or I misunderstood the original question?
The question is testing your knowledge of algorithmic complexity.

As the number of data items rises (especially past the limit where you can
reasonably think of all numbers as being basically the same size), you can
begin to ignore minor factors like the cost of overheads (e.g. opening a
file) and even, to some extent, the machine speed! All that matters, for
large N, is how this N affects the algorithm.

Quicksort is O(N * log N). Linear search is O(N). Bubble sort is O(N * N).

To understand, plot the graphs.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #3
mike-yue wrote:
The topic comes from a question:

Would you rather wait for the results of a quicksort, a linear
search, or a bubble sort on a 200000 element array?
1Quicksort
2Linear Search
3Bubble Sort

The answer is 2Linear Search

Could someone explain why Linear Search, not the other two options?
Or I misunderstood the original question?
Given that 1 and 3 are sorts, and 2 is a search, and given that it's
far from clear what 'result' you're supposedly waiting for, I'd say
you have misunderstood, or you've mis-remembered it.

In any case, this is a general programming question, not a question
on the C language.

--
Peter
Jun 27 '08 #4
All very good answers. many thanks for you guys,
In a word, the Liner Search is the cheapest method to search. the
other two are complicated and expensive.

I know it is about algorithmic complexity, but I totally forget the
defination of the O, even the Log. University time seems a century ago
I almost forget everything.

I think it is useless for 99% programmer jobs, unfortunately it's
always been asked. Once a interviewer asked me to explain the
algorithmic complexity of quick sort!
Thanks again
Jun 27 '08 #5
mike-yue said:
All very good answers. many thanks for you guys,
In a word, the Liner Search is the cheapest method to search. the
other two are complicated and expensive.
Whilst your claim is true, it is meaningless. Linear search is a search
technique. The other two are sorting techniques. It's tempting to say that
you're comparing apples with oranges, but it's more like comparing apples
with October.
I know it is about algorithmic complexity, but I totally forget the
defination of the O, even the Log. University time seems a century ago
I almost forget everything.

I think it is useless for 99% programmer jobs,
That's only true because 99% of programming jobs don't actually require
very much programming skill.
unfortunately it's
always been asked. Once a interviewer asked me to explain the
algorithmic complexity of quick sort!
Well, that's a reasonable question, isn't it? And hardly difficult.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #6
mike-yue <ne*********@gmail.comwrites:
All very good answers. many thanks for you guys,
In a word, the Liner Search is the cheapest method to search. the
other two are complicated and expensive.
Please quote some context when you post a followup.

The missing context is the question in your original article:

| Would you rather wait for the results of a quicksort, a linear search,
| or a bubble sort on a 200000 element array?
| 1Quicksort
| 2Linear Search
| 3Bubble Sort

but neither Quicksort nor Bubblesort is a searching algorithm. Since
they do entirely different things, asking which one you'd rather wait
for doesn't make a whole lot of sense.
I know it is about algorithmic complexity, but I totally forget the
defination of the O, even the Log. University time seems a century ago
I almost forget everything.

I think it is useless for 99% programmer jobs, unfortunately it's
always been asked. Once a interviewer asked me to explain the
algorithmic complexity of quick sort!
And this was a problem? That's certainly something I'd expect any
good programmer to know. If you're going to be writing code that does
sorting and searching, and you don't know this stuff, there's an
excellent chance your code is going to be unacceptable slow.

(Quicksort is O(N log N) best case and average case; a straightforward
implementation is O(N**2) worst case, but it can be made O(N log N)
with a little tweaking.)

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #7
>>>>"my" == mike-yue <ne*********@gmail.comwrites:

myThe topic comes from a question: Would you rather wait for the
myresults of a quicksort, a linear search, or a bubble sort on a
my200000 element array?

I myself would rather wait for the results of a bubble sort; this
means I have much more chance of my tea being ready before the result
set is.

Charlton

--
Charlton Wilbur
cw*****@chromatico.net
Jun 27 '08 #8
Richard Heathfield wrote:
mike-yue said:
>All very good answers. many thanks for you guys,
In a word, the Liner Search is the cheapest method to search. the
other two are complicated and expensive.

Whilst your claim is true, it is meaningless. Linear search is a search
technique. The other two are sorting techniques. It's tempting to say that
you're comparing apples with oranges, but it's more like comparing apples
with October.
>I know it is about algorithmic complexity, but I totally forget the
defination of the O, even the Log. University time seems a century ago
I almost forget everything.

I think it is useless for 99% programmer jobs,

That's only true because 99% of programming jobs don't actually require
very much programming skill.
Or in my case, 99% of programming has been making hardware or web pages
tick, without a bit O in sight!

--
Ian Collins.
Jun 27 '08 #9
mike-yue wrote:
>
The topic comes from a question:

Would you rather wait for the results of a quicksort, a linear
search, or a bubble sort on a 200000 element array?
1Quicksort
2Linear Search
3Bubble Sort

The answer is 2Linear Search

Could someone explain why Linear Search, not the other two
options? Or I misunderstood the original question?
It's a poor question. Quicksort is O(nLOGn), Linear search is
O(n), and bubble sort is O(n*n), where n is the size of the array,
here 200000. However linear searching doesn't require sorting, it
only requires examining each member of the original array for
equality. Since you get the linear answer quickest, and don't need
the array sorted, that is the optimum answer. The code is also the
simplest:

for (i = 0; i <= 200000; i++) {
if (a[i] == item) break;
}
if ((i <= 200000) && (a[i] == item)) return i;
else /* failure */ return -1;

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #10
CBFalconer said:

<snip>
It's a poor question. Quicksort is O(nLOGn), Linear search is
O(n), and bubble sort is O(n*n), where n is the size of the array,
here 200000. However linear searching doesn't require sorting, it
only requires examining each member of the original array for
equality. Since you get the linear answer quickest, and don't need
the array sorted, that is the optimum answer. The code is also the
simplest:

for (i = 0; i <= 200000; i++) {
Rookie error...
if (a[i] == item) break;
}
if ((i <= 200000) && (a[i] == item)) return i;
....repeated.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #11
Richard Heathfield wrote:
CBFalconer said:

<snip>
>It's a poor question. Quicksort is O(nLOGn), Linear search is
O(n), and bubble sort is O(n*n), where n is the size of the array,
here 200000. However linear searching doesn't require sorting, it
only requires examining each member of the original array for
equality. Since you get the linear answer quickest, and don't need
the array sorted, that is the optimum answer. The code is also the
simplest:

for (i = 0; i <= 200000; i++) {

Rookie error...
> if (a[i] == item) break;
}
if ((i <= 200000) && (a[i] == item)) return i;

...repeated.
You didn't think. This was deliberate, since as I read it the
original asked for an array that could hold a[200000]. For demo
purposes the idea is to use the original constant. The code within
the loop is the only thing that affects the speed, in practice.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #12
CBFalconer said:
Richard Heathfield wrote:
>CBFalconer said:

<snip>
>>It's a poor question. Quicksort is O(nLOGn), Linear search is
O(n), and bubble sort is O(n*n), where n is the size of the array,
here 200000. However linear searching doesn't require sorting, it
only requires examining each member of the original array for
equality. Since you get the linear answer quickest, and don't need
the array sorted, that is the optimum answer. The code is also the
simplest:

for (i = 0; i <= 200000; i++) {

Rookie error...
>> if (a[i] == item) break;
}
if ((i <= 200000) && (a[i] == item)) return i;

...repeated.

You didn't think.
I didn't have to think very hard to see that the code is wrong. Given the
size of the array, the code is broken.
This was deliberate, since as I read it the
original asked for an array that could hold a[200000].
As you /wrote/ it, however, "n is the size of the array, here 200000". For
such an array, evaluating a[200000] is an error. I am not a mind-reader. I
can only go on what you write.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #13
CBFalconer <cb********@yahoo.comwrites:
Richard Heathfield wrote:
>CBFalconer said:

<snip>
>>It's a poor question. Quicksort is O(nLOGn), Linear search is
O(n), and bubble sort is O(n*n), where n is the size of the array,
here 200000. However linear searching doesn't require sorting, it
only requires examining each member of the original array for
equality. Since you get the linear answer quickest, and don't need
the array sorted, that is the optimum answer. The code is also the
simplest:

for (i = 0; i <= 200000; i++) {

Rookie error...
>> if (a[i] == item) break;
}
if ((i <= 200000) && (a[i] == item)) return i;

...repeated.

You didn't think. This was deliberate, since as I read it the
original asked for an array that could hold a[200000].
[...]

I'm curious how you inferred that from

| Would you rather wait for the results of a quicksort, a linear
| search, or a bubble sort on a 200000 element array?

There was no implication that a[200000] had to be valid.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #14
On 5 May 2008 at 0:13, Richard Heathfield wrote:
mike-yue said:
>All very good answers. many thanks for you guys,
In a word, the Liner Search is the cheapest method to search. the
other two are complicated and expensive.

Whilst your claim is true, it is meaningless. Linear search is a search
technique. The other two are sorting techniques. It's tempting to say that
you're comparing apples with oranges, but it's more like comparing apples
with October.
I think it's pretty obvious to anyone who isn't so literal-minded that
he stops with a syntax error at the first place where most humans would
be happy to read between the lines that implicit in the question is:
would you rather linearly search a list, or first sort it and then
perform a binary search?

To which the answer depends primarily on *how many* searches you're
going to perform.

Jun 27 '08 #15
On 5 May, 01:26, Keith Thompson <ks...@mib.orgwrote:
mike-yue <needpass...@gmail.comwrites:
....
I think it is useless for 99% programmer jobs, unfortunately it's
always been asked. Once a interviewer asked me to explain the
algorithmic complexity of quick sort!

And this was a problem? That's certainly something I'd expect any
good programmer to know. If you're going to be writing code that does
sorting and searching, and you don't know this stuff, there's an
excellent chance your code is going to be unacceptable slow.

(Quicksort is O(N log N) best case and average case; a straightforward
implementation is O(N**2) worst case, but it can be made O(N log N)
with a little tweaking.)
It's not difficult to /state/ the complexity of quicksort (assuming
one remembers it) but it is another thing to /explain/ it.

--
Jun 27 '08 #16
rio
"CBFalconer" <cb********@yahoo.comha scritto nel messaggio
news:48***************@yahoo.com...
for (i = 0; i <= 200000; i++) {
if (a[i] == item) break;
}
if ((i <= 200000) && (a[i] == item)) return i;
else /* failure */ return -1;
why not

if(a) for (i = 0; i<=200000; ++i)
{if (a[i] == item) return i;}
else return -1;
Jun 27 '08 #17
On May 4, 5:26*pm, Keith Thompson <ks...@mib.orgwrote:
mike-yue <needpass...@gmail.comwrites:
All very good answers. many thanks for you guys,
In a word, the Liner Search is the cheapest method to search. the
other two are complicated and expensive.

Please quote some context when you post a followup.

The missing context is the question in your original article:

| Would you rather wait for the results of a quicksort, a linear search,
| or a bubble sort on a 200000 element array?
| 1Quicksort
| 2Linear Search
| 3Bubble Sort
There is no missing context. The question is exactly the original
question, no more no less.
but neither Quicksort nor Bubblesort is a searching algorithm. *Since
they do entirely different things, asking which one you'd rather wait
for doesn't make a whole lot of sense.
I know it is about algorithmic complexity, but I totally forget the
defination of the O, even the Log. University time seems a century ago
I almost forget everything.
I think it is useless for 99% programmer jobs, unfortunately it's
always been asked. Once a interviewer asked me to explain the
algorithmic complexity of quick sort!

And this was a problem? *That's certainly something I'd expect any
good programmer to know. *If you're going to be writing code that does
sorting and searching, and you don't know this stuff, there's an
excellent chance your code is going to be unacceptable slow.
Seems I need pick up my old textbook again
>
(Quicksort is O(N log N) best case and average case; a straightforward
implementation is O(N**2) worst case, but it can be made O(N log N)
with a little tweaking.)

--
Keith Thompson (The_Other_Keith) <ks...@mib.org>
Nokia
"We must do something. *This is something. *Therefore, we must do this.."
* * -- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #18
On May 5, 3:43*am, James Harris <james.harri...@googlemail.comwrote:
On 5 May, 01:26, Keith Thompson <ks...@mib.orgwrote:
mike-yue <needpass...@gmail.comwrites:

...
I think it is useless for 99% programmer jobs, unfortunately it's
always been asked. Once a interviewer asked me to explain the
algorithmic complexity of quick sort!
And this was a problem? *That's certainly something I'd expect any
good programmer to know. *If you're going to be writing code that does
sorting and searching, and you don't know this stuff, there's an
excellent chance your code is going to be unacceptable slow.
(Quicksort is O(N log N) best case and average case; a straightforward
implementation is O(N**2) worst case, but it can be made O(N log N)
with a little tweaking.)

It's not difficult to /state/ the complexity of quicksort (assuming
one remembers it) but it is another thing to /explain/ it.

--
agree with you. it is more difficult to explain if you learned the
theory in other language, e.g. in Chinese.
I was wondering if it is a easy thing to explain algorithmic
complexity for a programmer whose mother language is English(excluding
the geeks who are crazy about algorithmic).
Jun 27 '08 #19
On May 5, 9:58*am, "rio" <a...@b.cwrote:
"CBFalconer" <cbfalco...@yahoo.comha scritto nel messaggionews:48***************@yahoo.com...* for (i = 0; i <= 200000; i++) {
* * *if (a[i] == item) break;
* }
* if ((i <= 200000) && (a[i] == item)) return i;
* else * * * */* failure */ * * * * * *return -1;

why not

* *if(a) for (i = 0; *i<=200000; ++i)
* * * * * * * * * * {if (a[i] == item) *return * i;}
* *else *return * -1;
Don't you think:
for (i = 0; i<200000; ++i)
if the condition i<=200000, the array will overflow.
Jun 27 '08 #20
mike-yue <ne*********@gmail.comwrites:
On May 4, 5:26*pm, Keith Thompson <ks...@mib.orgwrote:
>mike-yue <needpass...@gmail.comwrites:
All very good answers. many thanks for you guys,
In a word, the Liner Search is the cheapest method to search. the
other two are complicated and expensive.

Please quote some context when you post a followup.

The missing context is the question in your original article:

| Would you rather wait for the results of a quicksort, a linear search,
| or a bubble sort on a 200000 element array?
| 1Quicksort
| 2Linear Search
| 3Bubble Sort

There is no missing context. The question is exactly the original
question, no more no less.
Yes, and since you didn't quote it in your followup *that's* the
missing context.

Since you use Google Groups, you need to be aware that most of us
don't use a web-based interface to read Usenet. The article to which
you're replying may not be readily visible to someone reading your
followup; it might not be available at all. Because of this, you need
to provide enough context so that your followup makes sense on its
own. (But it's rarely necessary or appropriate to quote the *entire*
article.)

Once upon a time, Google Groups had a serious bug that made it
difficult to provide any context when posting a followup. Chris
F.A. Johnson put together a web page explaining how and why to work
around this bug. The bug was fixed some time ago, but the web page
and the ones it links to are still useful, particularly the links
under "Quoting".

<http://cfaj.freeshell.org/google/>

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #21
On May 5, 12:50*pm, Keith Thompson <ks...@mib.orgwrote:
mike-yue <needpass...@gmail.comwrites:
On May 4, 5:26*pm, Keith Thompson <ks...@mib.orgwrote:
mike-yue <needpass...@gmail.comwrites:
All very good answers. many thanks for you guys,
In a word, the Liner Search is the cheapest method to search. the
other two are complicated and expensive.
Please quote some context when you post a followup.
The missing context is the question in your original article:
| Would you rather wait for the results of a quicksort, a linear search,
| or a bubble sort on a 200000 element array?
| 1Quicksort
| 2Linear Search
| 3Bubble Sort
There is no missing context. The question is exactly the original
question, no more no less.

Yes, and since you didn't quote it in your followup *that's* the
missing context.

Since you use Google Groups, you need to be aware that most of us
don't use a web-based interface to read Usenet. *The article to which
you're replying may not be readily visible to someone reading your
followup; it might not be available at all. *Because of this, you need
to provide enough context so that your followup makes sense on its
own. *(But it's rarely necessary or appropriate to quote the *entire*
article.)

Once upon a time, Google Groups had a serious bug that made it
difficult to provide any context when posting a followup. *Chris
F.A. Johnson put together a web page explaining how and why to work
around this bug. *The bug was fixed some time ago, but the web page
and the ones it links to are still useful, particularly the links
under "Quoting".

<http://cfaj.freeshell.org/google/>

--
Keith Thompson (The_Other_Keith) <ks...@mib.org>
Nokia
"We must do something. *This is something. *Therefore, we must do this.."
* * -- Antony Jay and Jonathan Lynn, "Yes Minister"- Hide quoted text -

- Show quoted text -
glad to know the correct method to use google group.
I don't use google group very often, so sorry for that.

Jun 27 '08 #22
Keith Thompson wrote:
CBFalconer <cb********@yahoo.comwrites:
>Richard Heathfield wrote:
>>CBFalconer said:

<snip>

It's a poor question. Quicksort is O(nLOGn), Linear search is
O(n), and bubble sort is O(n*n), where n is the size of the array,
here 200000. However linear searching doesn't require sorting, it
only requires examining each member of the original array for
equality. Since you get the linear answer quickest, and don't need
the array sorted, that is the optimum answer. The code is also the
simplest:

for (i = 0; i <= 200000; i++) {

Rookie error...

if (a[i] == item) break;
}
if ((i <= 200000) && (a[i] == item)) return i;

...repeated.

You didn't think. This was deliberate, since as I read it the
original asked for an array that could hold a[200000].
[...]

I'm curious how you inferred that from

| Would you rather wait for the results of a quicksort, a linear
| search, or a bubble sort on a 200000 element array?

There was no implication that a[200000] had to be valid.
I don't remember. The original is long gone from here. The point
is that the code I published was self-consistent. If a[200000] in
inaccessible the coding is simpler.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #23
James Harris wrote:
Keith Thompson <ks...@mib.orgwrote:
mike-yue <needpass...@gmail.comwrites:

...
>>I think it is useless for 99% programmer jobs, unfortunately it's
always been asked. Once a interviewer asked me to explain the
algorithmic complexity of quick sort!

And this was a problem? That's certainly something I'd expect any
good programmer to know. If you're going to be writing code that does
sorting and searching, and you don't know this stuff, there's an
excellent chance your code is going to be unacceptable slow.

(Quicksort is O(N log N) best case and average case; a straightforward
implementation is O(N**2) worst case, but it can be made O(N log N)
with a little tweaking.)

It's not difficult to /state/ the complexity of quicksort (assuming
one remembers it) but it is another thing to /explain/ it.
Why? It is basically the same process for any algorithm based on
chop in half and solve the halves.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #24
CBFalconer said:
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:
>>Richard Heathfield wrote:
CBFalconer said:

<snip>

It's a poor question. Quicksort is O(nLOGn), Linear search is
O(n), and bubble sort is O(n*n), where n is the size of the array,
here 200000. However linear searching doesn't require sorting, it
only requires examining each member of the original array for
equality. Since you get the linear answer quickest, and don't need
the array sorted, that is the optimum answer. The code is also the
simplest:
>
for (i = 0; i <= 200000; i++) {

Rookie error...

if (a[i] == item) break;
}
if ((i <= 200000) && (a[i] == item)) return i;

...repeated.

You didn't think. This was deliberate, since as I read it the
original asked for an array that could hold a[200000].
[...]

I'm curious how you inferred that from

| Would you rather wait for the results of a quicksort, a linear
| search, or a bubble sort on a 200000 element array?

There was no implication that a[200000] had to be valid.

I don't remember.
You don't have to. He quoted the original for you.
The original is long gone from here.
He quoted it for you. And here's the message ID:

<d0**********************************@q24g2000prf. googlegroups.com>

And just to make it completely obvious, here's the thread subject line:

[Re: A question: Is 200,000 element array worth sorting and search?]
The point
is that the code I published was self-consistent.
No, the point is that the code you published was *wrong*.

If a[200000] in inaccessible the coding is simpler.
Which is why everyone is so puzzled that you got it wrong.

Well, we all make mistakes - but when people point out your mistake, it's
not wise to start firing off accusations at them, such as "you didn't
think". It is true that someone wasn't thinking, but that someone isn't
the someone you thought it was.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #25
Richard Heathfield wrote:
CBFalconer said:
Keith Thompson wrote:
CBFalconer <cb********@yahoo.comwrites:
Richard Heathfield wrote:
CBFalconer said:
.... snip ...
>>>
for (i = 0; i <= 200000; i++) {

Rookie error...

if (a[i] == item) break;
}
if ((i <= 200000) && (a[i] == item)) return i;

...repeated.

You didn't think. This was deliberate, since as I read it the
original asked for an array that could hold a[200000].
.... snip ...
>
No, the point is that the code you published was *wrong*.
If a[200000] in inaccessible the coding is simpler.

Which is why everyone is so puzzled that you got it wrong.

Well, we all make mistakes - but when people point out your mistake, it's
not wise to start firing off accusations at them, such as "you didn't
think". It is true that someone wasn't thinking, but that someone isn't
the someone you thought it was.
What's the error? My code handles an array whose last member is
indexed by 200000. The finalize stuff allows for the same max.
Yes, the code can be simpler, so what? The point was the O(n)
operation of the simple loop.

I have no objection to admitting errors. This is not one.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #26
CBFalconer said:
Richard Heathfield wrote:
>CBFalconer said:
<snip>
If a[200000] in inaccessible the coding is simpler.

Which is why everyone is so puzzled that you got it wrong.

Well, we all make mistakes - but when people point out your mistake,
it's not wise to start firing off accusations at them, such as "you
didn't think". It is true that someone wasn't thinking, but that someone
isn't the someone you thought it was.

What's the error?
Referencing an object that doesn't exist.
My code handles an array whose last member is indexed by 200000.
The array under discussion (see subject line and OP's text) is a
200000-element array, so there is no member in the array for which an
index of 200000 is legal.
The finalize stuff allows for the same max.
Yes, the code can be simpler, so what? The point was the O(n)
operation of the simple loop.

I have no objection to admitting errors. This is not one.
It has become *two* errors - the original error, and the rather graver
error of not recognising when one is in error.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #27

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LRW | last post by:
I have a page that's doing a search of a database, create an array and displays it. And I have it displaying the array just fine, but when I try to sort it, I get the error: Warning: sort()...
3
by: pertheli | last post by:
Hello, I have a large array of pointer to some object. I have to run test such that every possible pair in the array is tested. eg. if A,B,C,D are items of the array, possible pairs are AB, AC,...
4
by: John Bullock | last post by:
Hello, I am at wit's end with an array sorting problem. I have a simple table-sorting function which must, at times, sort on columns that include entries with nothing but a space (@nbsp;). I...
2
by: Roy Gourgi | last post by:
Hi, My program seems to slow down drastically because as I fill my array and table with many values, the program suffers tremendously. The first thing my program does is to search the jagged...
9
by: Chris | last post by:
Wondering the best way of storing my data. This is data pulled and stored in the database but a lot of data manipulation goes on the client side. I never have to remove items but will sometimes...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
27
by: karan.shashi | last post by:
Hey all, I was asked this question in an interview recently: Suppose you have the method signature bool MyPairSum(int array, int sum) the array has all unique values (no repeats), your...
18
by: Nobody | last post by:
I've been looking for a job for a while now, and have run into this interview question twice now... and have stupidly kind of blown it twice... (although I've gotten better)... time to finally...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.