Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17447

i need to write a code of almost sorted list search problem , not the linear solution .. i tried the binary search but it did not work [closed]

$
0
0

i need the code to return true if the target is in list and false otherwiselst=[0, 1, 2, 3, 697, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48]for example this is an almost sorted list the character 697 is misplacedthe input is always an almost sorted list (woth one misplaced character )

i tried to binary search the misplaced index or char but it didnt work because in binary search we 'halve ' the mid value or the interval we are looking into but there is no assurance that the target will be found at the new searching area , for example the target can be smaller than the char in the mid index and also smaller than the median but misplaced at the last index (n-1 for a list of length n )i need ideas or to provide me a code


Viewing all articles
Browse latest Browse all 17447

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>