We have different types of data structures like array, linked list, tree etc but which one is better so this is basic question that comes in mind every time when we have large data set.
In this post we can find out the best data structure type in various conditions :
Type Search Insertion Deletion Traverse
Array O(N) O(1) O(1) ------
LinkedList O(N) O(1) O(N) O(N)
Binary Tree O(logn) O(logn) O(logn) O(logn)
HashTable O(1) O(1) O(1) O(1)
We know that a algo is to be fast and efficient if it takes less time to execute and takes less space so algo is measured based on time complexity and space complexity.
Arrays : If fast insertion is needed and you don't want to traverse in specific order then you should choose unordered arrays. If we are talking about ordered array then search ll be easy but insertion and deletion ll be relatively slow.
LinkedList : I you need flexible structure that don't require to know the size ahead of time then use linked list. Linkedlist is faster than arrays because during insertion there is no need of shifting elements like arrays only reference is changed for operation. Deletion also take O(N) time because you have to search item first.
Binary Tree : This one is better than linkedlist because it takes O(logn) time for operations but tree should be binary or balanced otherwise in worst it ll perform O(N) time complexity in that case regular binary tree might be sufficient solution.
HashTable : HashTable is faster than others because it takes only O(1) time in any operations but load factor should not be too big so it is expected to have a rough idea of how many items you would be expecting.