❔ Learning binary searching
i linked the txt file for my entire page
the part im stuck on is
6 Replies
unsure how to binary search through this
First binary search works on sorted arrays so make sure your items are sorted
Second binary search works by comparing the value we are searching for with the middle value for the current subset
If our value is large than the current mid, we go to the right and get the middle of it
If it's smaller we go to the left and get the middle of it
We keep doing that till either the value is found or there are no more subsets to check
i think my bunary is setup worng but dont know how to fix it as well
i want to search through a hero array with a string
but unsure how to use less than or greater than when comparing element locations
You don't compare element location, you compare the items and then move accordingly
well, that's the point that Kouhai made. You don't compare locations, you compare elements
so, A) your elements need to be comparable, and B) they need to be already-sorted, within the array under search
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.