Skip to main content
Cooper Levi
Choose A Good Heart Not a Good Face.
Asked a question 2 years ago

when to use different data structures

Where am I?

In answerQA you can ask and answer questions and share your experience with others!

Life Is Not About Waiting For The Storm To Pass, But Learning To Dance In The Rain

Any engineer's primary data structures should know Array, Tree, Stack and Queue, Graph, Hash Table, and Linked List. 

Arrays: The array is the most basic data structure, merely a list of data elements that you can access by an index, which is the data’s position inside the array. Arrays are quite efficient at searching if the elements in the array are ordered. However, insertion and deletion are not as efficient since you have to shift all elements when you delete or insert an item.

Hash Table: Hashtable is a list of paired values, the first item in the pair is the key, and the second item is the value. With a hash table, you can access objects by the key, so this structure is high-speed for lookups. Hash tables are faster than the arrays for lookups. Also, quick for inserting and deleting objects; however, a hash table doesn’t maintain any order.

Stacks & Queues: Stacks and queues are arrays; however, there are some restrictions on how to use them. These data structures are beneficial as a temporary container that allow you to handle the data in order. Let’s say you would like to store the charges in a restaurant. It would be vital that you processed the orders in the same order as received.

Linked List: A linked List is a node-based data structure. A linked list is similar to an array in the sense that it represents a list of elements. However, linked List manages memory differently. Unlike the arrays, the memory cells are not next to each other but spread across different cells.

Trees: Trees are also node-based structures, with every tree has a root node with 0 or more child nodes. A tree cannot contain cycles. There are several types of trees, and one of them is the Binary Tree. In binary Trees, each node has up to two nodes.

Graphs: A graph is a collection of nodes with edges in between. A tree is a graph with some restrictions. In other words, it is a connected graph without cycles. A graph could be directed, which means the nodes are connected in one direction, like a one-way street. You can also have an undirected graph, which means nodes are connected in both directions.