View previous topic :: View next topic
|
Author |
Message |
Girijesh
New User
Joined: 19 Sep 2008 Posts: 14
|
|
|
|
Hi , i was asked a question in CSC:
Binary search divides a table in 2 halves, how many elements in upper half and how many in lower half, if there are :
1. 25 elements, and
2. 26 elements
i am unable to find answer, please let me know
____________________________
Thanks |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
I wonder.....
If you created a table with 25/26 entries consisting of two fields, a key and a sequence number and did a binary search that hit on the first attempt you could find which was the middle yourself.
I'd think that even if the keys were identical the search would always start in the middle. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
this is a mainframe collection of forums not a MATH one
the question is just nonsense
statistically there will always be a 50% probabilty ( odd and even occurrences per table segment )
that one <half> of the table at any stage will contain one element more than the other one
which one and when
depends on odd/even count and if You consider the delimiting element as part of one of the two <halves>
for 25 elements
the first element checked will be ( 1 + 25 ) / 2 = 13
for 26 elements ....
( 1 + 26 ) / 2 = 13
/ ==> integer division
the element checked will be the same, but...
meditate ... meditate ... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hwllo,
Quote: |
Hi , i was asked a question in CSC: |
Suggest one appropriate answer is that when using the built-in binary search function in cobol (SEARCH ALL) it doean't matter. . . It is all automatic. . .
If "they" are basing any hiring decisons on that type of question, i'm rather happy that i do not work there. . . |
|
Back to top |
|
|
Girijesh
New User
Joined: 19 Sep 2008 Posts: 14
|
|
|
|
Well thanks to all of you for your effort to answer this.
It really helped me a lot to understand the complexity of this question.
and Mr. Enrico-sorichetti i knew it is a collection of Mainframes not the MATH one , but i searched all the web , manuals and finally diverted here to get best response.
Please allow some space here for some non-sense but important questions.
It really helped to broaden my thought process,amazing ,so thanks again to all. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Girijesh wrote: |
Please allow some space here for some non-sense but important questions. |
If something is nonsnese, how can it be important. . . . . . may be this question could be posted in "student Forum" . . . just a thought, please don't take it otherwise... |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
It really helped me a lot to understand the complexity of this question.
|
just curious, where is the complexity....
also I do not see how You could not find anything,
I just tried googling with binary search algorithm
and I found quite a number of links with exhaustive info on binary search
the first hit
en.wikipedia.org/wiki/Binary_search has a very good explanation
but again the question You were asked is just nonsense |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Quote: |
but again the question You were asked is just nonsense |
Some times these question come from interviewer side and I met many such individuals.. even in my little experience . . . and as a newbie we feel if some one is interviewing us, he is senior (at least age-wise . . . grin) and asking the right thing . . . |
|
Back to top |
|
|
Girijesh
New User
Joined: 19 Sep 2008 Posts: 14
|
|
|
|
Accepted : not aware with posting rules, good reply, i must appreciate the way you did
I'll take care next time |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
I agree with the others who stated this is an inappropriate interview question concerning a binary search. A better question would have been, "Describe briefly the difference between a serial search and a binary search" or "When is one preferable over the other?" or "What are the requirements necessary in order to use a binary search?". |
|
Back to top |
|
|
|