Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

if i have 10 fields in a table . i sorted a table w.r .t 1,2 field. can b

Former Member
0 Kudos

if i have 10 fields in a table . i sorted a table w.r .t 1,2 field. can binary search work on second field.

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

Hi Sreedhar,

No. It will not work.(It may still give the correct output, but the performance improvement that is expected will not be there).

Regards,

Ravi

6 REPLIES 6

Former Member
0 Kudos

Hi,

binary search will give good performance when u use the keys which u specified in the SORT. So sort the table with the keys which you will use to read the table for better performance outcome.

regards,

madhumitha

former_member181962
Active Contributor
0 Kudos

Hi Sreedhar,

No. It will not work.(It may still give the correct output, but the performance improvement that is expected will not be there).

Regards,

Ravi

0 Kudos

Hi ,

the output may not be correct if u sort with X1,x2 and read it with x2. the output will be correct one incase x1 is constant. otherwise you will not get the desired output.

regards,

madhu

Former Member
0 Kudos

Hi,

The binary search will ot work.

but if you are sort with

sort int by a b.

and then reading with

read int with key a =some value

b = some value.

It will work.

Former Member
0 Kudos

Hi sreedar,

it won't work ... if you want to read with one key then sort the table with the same key only .. then it'll work. because sorting with fields a and b. whereas reading the table with key b and binary search addition requires sorted table in ascending order of b alone ...

Sort the table with key a b alone ... then it'll work..

Former Member
0 Kudos

Hello,

In your case doing binary search on 2nd field alone will not work out and performance will be defínitely bad.

Regs,

Venkat Ramanan N