Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help with strings

Hello I need help with the following algorithm:


We have a sorted list of strings( as in dictionary) and a string (a

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [color=Blue]If you have a linked list - binary search will not be effective, because it requires that collection be accessed with an index and linked list does not have that ability. You need an array here.

    Once you have an array filled and sorted - you should be able to use binary search. In callback function for a search you need to check not the whole string, but only its prefix - it should be easy enough.

    And binary search will only give you the answer - if the prefix found or not. The full list of words starting with the prefix you will find using the found index. Go up the array (from index returned by BS) and find where the group of words begins (at which index), then go down the array (from index returned by BS) and find the end of the group.[/color]
Sign In or Register to comment.