IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Binary Search elements in upper half


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Girijesh

New User


Joined: 19 Sep 2008
Posts: 14

PostPosted: Sun Apr 05, 2009 4:40 pm
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sun Apr 05, 2009 7:01 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sun Apr 05, 2009 8:37 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Apr 06, 2009 3:19 am
Reply with quote

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
View user's profile Send private message
Girijesh

New User


Joined: 19 Sep 2008
Posts: 14

PostPosted: Mon Apr 06, 2009 11:00 am
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Mon Apr 06, 2009 12:27 pm
Reply with quote

Girijesh wrote:
Please allow some space here for some non-sense but important questions.
If something is nonsnese, how can it be important. . . icon_razz.gif . . . may be this question could be posted in "student Forum" . . . just a thought, please don't take it otherwise...
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Apr 06, 2009 12:56 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Mon Apr 06, 2009 1:05 pm
Reply with quote

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
View user's profile Send private message
Girijesh

New User


Joined: 19 Sep 2008
Posts: 14

PostPosted: Mon Apr 06, 2009 3:19 pm
Reply with quote

Accepted : not aware with posting rules, good reply, i must appreciate the way you did icon_evil.gif

I'll take care next time
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Mon Apr 06, 2009 8:53 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts first column truncated in search result IBM Tools 13
No new posts ISRSUPC search utility - using high l... TSO/ISPF 2
No new posts To search DB2 table based on Conditio... DB2 1
Search our Forums:

Back to Top