im a beginner of coding and using python.
Im trying to code for a linear search but I don't know how to:(
qqabb
0
Newbie Poster
Recommended Answers
Jump to PostFirst of all, why linear search? That's like the worst algorithm to use ever.
But if you don't want to use the Python internal algorithm, a for loop can do it:
def findValue(v, li): for i in len(li): if v == len[i]: return i return -1
But that's such …
Jump to Postdef binary_search(a, n, required): start = 0 end = n - 1 answer = 0 while start <= end: middle = (end + start) / 2 if a[middle] == required: answer = middle break else: if required < a[middle]: end = middle - 1 else: start = …
All 7 Replies
Gribouillis
1,391
Programming Explorer
Team Colleague
ultimatebuster
14
Posting Whiz in Training
Gribouillis
1,391
Programming Explorer
Team Colleague
vegaseat
commented:
good catch
+10
ultimatebuster
14
Posting Whiz in Training
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
-ordi-
6
Junior Poster in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.