0 votes
in Other by

How to find low/High index

1 Answer

0 votes
by

You can use these algorithms to find low and high indexes.

For Low Index:

Consider the range between low and high indexes at each step and then find the mid-index.

If the element at the mid Index is lower than the key, low will become mid + 1. This allows you to move towards the beginning of the range.

If the mid element >= the key, the high will be mid - 1. The low Index will remain the same.

If the low > high, it would indicate the first appearance of the key.

Return -1 if the key does not match the element at the low.

For High Index:

Similar results can be obtained by slightly altering the condition above for high Index

Switch the low Index to middle + 1 if the key Index of an element is lower than or equal to the Index at mid.

Switch the high Index to middle - 1 if the key element is larger than the mid.

...