Data Structure Part 1

Jreyes
3 min readAug 30, 2021

I want to create a series for Data Structures as I did with the BIG O. I want to have something to come back when most need it. Let's start by answer this question:

What is Data Structure?

A data structure is a particular way of organizing data in a computer so that it can be used effectively. We can store a list of items having the same data type. There are many types of data structures.

What are the types of Data Structures?

Array data structure

Memory Location200 201 202 203 204 205...
[A, B, C, D, E, F...]
0 1 2 3 4 5...
INDEX

The above is an Array Data Structure which is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value.

An array contains a top-level view of a staircase where you are at the base of the staircase. Each element can be uniquely identified by its index in the array.

Linked List Data Structure

A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers as shown in the below example:

In simple words, a linked list consists of nodes where each node contains a data field and a reference(link) to the next node in the list. But what is a node you may ask?

A node is a basic unit of a data structure, such as a linked list or tree data structure. Nodes contain data and also may link to other nodes. Links between nodes are often implemented by pointers. Let us continue with another example.

Stack Data Structure

Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).

There are many real-life examples of a stack. Consider an example of plates stacked over one another in the kitchen. The plate which is at the top is the first one to be removed and the plate which has been placed at the bottommost position remains in the stack for the longest period of time. So, it can be simply seen to follow LIFO(Last In First Out)/FILO(First In Last Out) order.

Queue Data Structure

A Queue is a linear structure that follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first. The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added.

There are some other examples that we are going to visit next week. Stay in touch and happy coding.

--

--

Jreyes

I'm a software engineer making his way into the tech industry.