mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-02-13 13:54:36 +00:00
[OTHER] Linear search not returning index #209
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Lk-ux on GitHub (Dec 23, 2025).
What would you like to share?
Hi, I'm new to this repo. So please enlighten me if that's just the way things are done here.
In the linear search file, I noticed that it returns 1 when an element is found and 0 otherwise.
Not a fatal error per se, but isn't a searching algorithm supposed to return the position/index at which the required value was found, like done in other files? Why make a difference for a trivial linear search?
Additional information
No response
@PanicMike-9 commented on GitHub (Dec 23, 2025):
I was searching for the same answer, and if you look closely at the function, it's designed to return a true or false, or more simply a yes or no type of function, when I compiled to code, it's something like this:
Enter the size of the array:
10
Enter the contents for an array of size 10:
1 2 3 4 5 8 88 2 9 11
Enter the value to be searched:
33
Value 33 is not in the array.
So it says either the value is there or it isn't. I could be wrong about this, I am new too.
@iamxorum commented on GitHub (Dec 28, 2025):
Hi! I'm new to this repo too.
I wanted to mention that search algorithms don't always need to return the position of the item. Often, just knowing "Hey, the value was found" is more compatible with how we actually use these functions.
Think of it this way: If you are building a program and only need to check for existence, but the function returns an index, you have to write extra code just to handle that return value. You end up having to write logic that ignores the index, which feels like a "destructive" approach. If the function just returned true/false, the implementation would be much cleaner and "constructive."
I suggest would we update the function to take a parameter like returnIndex. Based on that flag, it can return either the index or a boolean. This looks better to me and keeps the script backwards compatible!
@github-actions[bot] commented on GitHub (Jan 28, 2026):
This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.