Search code examples
searchbinary-search

What is the fastest searching algorithm in unsorted linked list


Currently using liner search for unsorted linked list. Just thinking is there any faster way of searching algorithm for unsorted linked list.


Solution

  • When you have unsorted data and you want to get an item from this unsorted collection, you could apply following technique to get item in faster way:

    1. make a Balanced Binary Search Tree (i.e, Red-Black Tree) and traverse the tree, which would give you O(N * log(N)) where O(N) for travering N items from the unsorted-collection of data, and O(logN) for inserting and searching the data.

    2. sort the collection of data (using quick or merge sort technique) and apply Binary search on sorted data, this would give you O(N * log(N)) complexity again.

    3. you can come up with some other technique like Heap-like data structure, this too would also give you O(N * log(N)) complexity.

    4. only if you have unique items in your unsorted collection then you can come-up with O(N) solution by creating HashSet -like data structure and return the key's value in O(1) time.