0

Anyone knows how to do binary search 🤨 using for loop in python

plzz answer*******😟🎷

27th Nov 2018, 12:50 AM
Naveen
Naveen - avatar
16 odpowiedzi
+ 2
I think this works. I only changed one line in a typical binary search algorithm. As mentioned before, I just calculated the number of iterations in the worst case, and used a for loop with that range. Let me know if you find any bugs. Cheers! https://code.sololearn.com/cgy1UH9euwnE/?ref=app
15th Dec 2018, 4:42 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
NASH if you don't mind, could you please share the code? Thanks!
3rd Feb 2019, 11:48 AM
Kishalaya Saha
Kishalaya Saha - avatar
27th Nov 2018, 1:39 AM
AL Araf
AL Araf - avatar
+ 1
AL Araf the code in your link uses while loop for the binary search. NASH, it's possible to calculate how many iterations of the loop the binary search would need in the worst case, and then use a for loop with that range. But why do you want to use a for loop when while loop or recursion are simpler choices here?
27th Nov 2018, 2:58 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
Great! Then you can try what I suggested. If I do it for you, you won't learn as much 😊
2nd Dec 2018, 4:33 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
The main function is in lines 8-19. The rest is for testing that it works. If this looks too long, why don't you share your favorite binary search code that uses a while loop, and I'll turn it into a for loop version having the same number of lines? Like I said before, I only modified one line in a typical binary search code.
18th Dec 2018, 5:08 PM
Kishalaya Saha
Kishalaya Saha - avatar
0
Ahh experiment with all format guys when you learn any lang
2nd Dec 2018, 4:28 PM
Naveen
Naveen - avatar
0
😕😕 so Saha I quit!!!😵 if you know this solution you tell me if not this becomes all okk👻
15th Dec 2018, 1:25 AM
Naveen
Naveen - avatar
0
thxx but this big chunk of code I couldn't handle☺️☺️
18th Dec 2018, 4:54 PM
Naveen
Naveen - avatar
0
do it shory
18th Dec 2018, 4:55 PM
Naveen
Naveen - avatar
0
do it short
18th Dec 2018, 4:55 PM
Naveen
Naveen - avatar
0
yaa of course
20th Dec 2018, 12:44 AM
Naveen
Naveen - avatar
0
burrah i do it
3rd Feb 2019, 9:36 AM
Naveen
Naveen - avatar
0
finally i got this right
3rd Feb 2019, 9:36 AM
Naveen
Naveen - avatar
0
after long time
3rd Feb 2019, 9:36 AM
Naveen
Naveen - avatar
0
okk friend
9th Feb 2019, 2:48 AM
Naveen
Naveen - avatar