DEV Community

Cover image for Data structure for newbies
diegotco
diegotco

Posted on • Updated on

Data structure for newbies

...Far beyond list, dictionaries, sets, and tuples.

Data structures are ways of organizing and storing data in a way that makes it easy to access and modify. There are many different data structures, and each one has its own advantages and disadvantages in different situations.

Classification of Data Structure[1]Classification of Data Structure.

Why learn about Data Structure:

I always thought that carrying out a search, insert or delete action in a list will involve the same effort, and therefore the same speed at getting the things done. I was totally wrong. So this is why I decided to learn more about Data Structure.

Here are some of the most common data structures and their typical use:

Arrays:

Arrays are very fast for accessing any particular element, but they are not efficient for inserting or deleting elements, since we have to move all the subsequent elements in the array to make space or close the gap.

Linked lists:

The advantage of linked lists is that they are very efficient for inserting and deleting elements, since we only need to change a few links to add or remove an element. However, they are slower for accessing specific elements, since we need to follow the links from the beginning to reach the desired element.

Stacks:

A stack is a data structure where we can only add or remove elements from one end, known as the "top of the stack". This means that if we want to add an element to the stack, we do it at the top; and if we want to remove an element, we do it from the top as well.

A stack is very useful when we need to maintain a specific order for processing elements, such as when we evaluate a mathematical expression or when we do undo/redo in a text editor.

Queues:

A queue is a data structure where elements are added to one end (called the "back of the queue") and removed from the other end (called the "front of the queue"). This means that the first person in a queue is the first one out, which is known as "first-in, first-out" (FIFO).

Queues are useful in many situations, such as when we want to process elements in the order they were received, or when we want to limit access to a shared resource.

Trees:

A tree is a hierarchical data structure where each element (called a "node") has one or several "child" elements below it. The node at the top of the tree is called the "root", and nodes with no children are called "leaves".

Trees are very useful for organizing and searching data efficiently, since we can keep dividing the data into smaller branches as we go down the tree. For example, in a search tree, we can compare the value of each node to the value we are looking for, and advance to the right or left branch as needed until we find the correct node.

Data Structures & Algorithms Animation/Visualization

Data structures animations and visualizations [2]Bubble sort.

If you are the type of person who learn by watching, then you'll love these two amazing tools: Youtube videos[2] and Interactive programs[3].

The Bible of Data Structure

Image description

The book written by Robert Lafore[4] is one of the most popular, and easiest books to read even for a beginner, and it does't matter if you are learning/using other language than Java. My advice is: Get the book and read the whole book, skip the code if you want. Yeah, it has a lot of pages but again, the book is easy to understand.

I want to share with you one of the final conclusions in the book:

[At implementation]...start by considering the simple data structures... If it runs in acceptable time, look no further. Why slave away on a balanced tree when no one would ever notice if you used an array instead? Even if you must deal with thousands or tens of thousands of items, it's still worthwhile to see how well an array or linked list will handle them. Only when experimentation shows their performance to be too slow should you revert to more sophisticated data structures.[5]

Hope you have found this article valuable and enjoyable 😁



References:
[1]https://www.geeksforgeeks.org/data-structures/?utm_source=pocket_reader
[2]https://www.youtube.com/watch?v=hj3Rm3liN0o
[3]https://visualgo.net/en
[4]Data Structures and Algorithms in Java.
[5]One of my life hacks: KISS. "Keep It Simple Stupid".

Note:
The cover image was generated by https://labs.openai.com/

Top comments (0)