DSA GRIND #6

DSA GRIND by Ashur Baroutta

        This week's problem is a classic! I wanted to tackle another Binary Search problem. So our problem statement reads -

    "Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1."

    So after spending a bit of time trying to figure out how to do this i settled on using a twopointer combined with a while loop setup and setting a variable to target the middle of the array and comparing our index of mid to our target and incrementing/decrementing based off the result of the comparisons. I can see why its a classic. While it may not be as widespread now, I think this type of search is useful in returning specific data from a smaller dataset. It probably doesn't scale too well for super large datasets.


Comments

  1. I find this as an interesting way to extract data from other data and could be the foundation for greater applications!

    ReplyDelete

Post a Comment

Popular posts from this blog

IP #6 : Reversing an Integer

DSA GRIND #9