06-22-2018 12:21 PM
I was experimenting on binary search.
I found that binary search is perfectly working on ascending order internal table,
but does not work in descending order internal table.
Why binary search does not support descending order internal table?
06-22-2018 3:02 PM
Hi Subrata,
It is about nature of binary search,not only Sap. You should search and learn about binary search ,for example : https://www.tutorialspoint.com/data_structures_algorithms/binary_search_algorithm.htm
06-22-2018 12:27 PM
Because it is designed and documented to work on ascending sort order.
06-07-2022 7:09 PM
You just saved my day!!!!
This is the correct answer for this query and not the one which is marked as "Best Answer" here.
In my academics what I had learnt is BINARY Search works well for Ascending and Descending Order.
But in ABAP we have an exception and that is it works for Ascending Order only.
Thanks,
Sijin
06-22-2018 3:02 PM
Hi Subrata,
It is about nature of binary search,not only Sap. You should search and learn about binary search ,for example : https://www.tutorialspoint.com/data_structures_algorithms/binary_search_algorithm.htm
06-22-2018 3:10 PM
Erm, no. The "nature of binary search" has nothing to do with the order.
There's nothing stopping you from coding a binary search function yourself that supports descending order.
06-22-2018 3:58 PM
Of course there is nothing to do stop your going further but when we use a bicycle , we could not complain that why it doesnt fly.The nature of those things ,we should go to a ticket for airplane.
06-22-2018 4:33 PM
We can sort ascending and descending, so it is perfectly reasonable to question if we can binary search both variants. Algorithmically it is exactly the same process, nothing unnatural about that, and no flying involved. SAP has decided not to implement it, it's as simple as that.
08-28-2020 12:38 PM
Only Ascending is possible.
Descending is not possible means In binary search ( like 1 2 3 4 5 6 7 ) I need to search 7
In Descending order ( 7 6 5 4 3 2 1 ) it picked 4 it is middle so its checking greaterthan first 3 values it is not considering . Its search next three values. next three value is Min number of 4