I was researching about binary search of a number within a list and came across this discussion
Somewhere else I it was mentioned about going for even and odd numbered list separately. But is that language specific? The information is little confusing.
For Binary search , I know high-level I need to carry out following steps,
- sort the list in ascending order
- Check for middle item within a list if thats the number we are done
- if not , if the number is greater than the middle number, get rid of lower half
- if searched number is lower than middle number , get rid of uppeer half
- keep repeating until number is found
The list can be ascending or descending order and can be of float of int numbers.
what's pythonic way of carrying out above pseudocode?
I am using python 2.7.x on windows.
** EDIT **
The mentioned discussion does not cover even and odd list (at least I couldn't see any
I would like to request more clarifications on that such as,
- If I need to treat even odd list differently
- Is there a way in python that will take care of that
bisectsource.evenandoddlist. my answer covers that.even , oddlist part of the question. Will the integer division work for both integers as well as float list. I will try out your code.10 /3 will be still equal to 3. Also, you will need to replace main function accordingly to generate float list and float random number.Hope this helps.