Introduction to Data Structures

Sachini Amarasinghe
Nerd For Tech
Published in
6 min readJun 4, 2022

--

Photo by Author

Hello Readers!

This is the first article of the data structures article series. Through this article, I hope to lay the foundation of the topic of Data Structures you must need to know as a beginner. Let’s get started!

What is a Data Structure?

Simply a data structure is a way of organizing data so that it can be used efficiently and effectively. By organizing data in some fashion, later on, it can be accessed, queried, or perhaps even updated quickly and easily.

According to that, there are many ways of organizing data in the memory. These are arrays, Linked lists, Stacks, Queues, Trees, and Graphs, etc. I will explain all those things later on.

Another important thing is data structure is not a programming language, it is a set of algorithms that we can use in any programming language to structure the data in the memory.

What is Abstract Data Type, and how does it differ from a data structure?

An abstract data type is an abstraction of a data structure, which provides only the interface to which that data structure must adhere. The interface does not give any specific details on how a specific data structure should be implemented, or in what programming language.

Example: Suppose that your abstract data type is for a mode of transportation to get from point A to point B. There are many modes of transportation to get from one place to another. Some specific modes of transportation might be walking, biking, perhaps even taking a train, and so on, these specific modes of transportation would be analogous to the data structures themselves. We want to get from one place to another through some mode of transportation, that was our abstract data type. How did we do that? That is the data structure.

Why Data Structures?

  • Data structures are essential ingredients in creating fast and powerful algorithms.
  • They help us manage and organize our data in a very natural way and allow efficient storing of data thus allowing disk space-saving.
  • Data structures allow multiple data processing requests. It means they allow multiple users to handle, access and modify data simultaneously.
  • They make code cleaner and easier to understand.

What are the advantages of Data Structures?

Data Organization — We need a technique for properly arranging data so that it can be accessed quickly when we need it. DS offers a variety of data organization options, allowing us to store data in a variety of data structures depending on our needs.

Efficiency — The primary purpose of data organization is to increase efficiency. Why do we need linked lists and other data structures even if we could store the data in arrays? because when we need to perform multiple operations on arrays, such as add, remove, update, and search, arrays take much longer than alternative data structures. As a result, we’re interested in various data structures due to their efficiency.

Reusability — It is possible to reuse a data structure. Once a data structure has been implemented, it can be reused later.

Abstraction — Data structure hides (abstracts) the implementation details from the user. The user interacts with the data through an interface and benefits from data structures; however, the user is unaware of the important implementation details.

Classification of Data Structure

Classification of Data Structure

Data structures can be divided into two major categories.

  • Primitive Data Structures
  • Non-Primitive Data Structures

Primitive Data Structures are primitive data types. As an example, int, float, char, double, and pointer are the primitive data structures. They hold a single value. Non-Primitive Data Structures are divided into two types according to the arrangement of the data.

  • Linear Data Structures
  • Non-Linear Data Structure

When all elements of a data structure are arranged in a sequential manner (linear), we call it a Linear Data Structure. The elements of Linear Data Structures are stored in a non-hierarchical manner, with each element having successors and predecessors except the first and last. Non-Linear Data Structures do not have a sequence. Each element is connected with two or more other items.

Linear Data Structures can be classified into two types.

  • Static Data Structures
  • Dynamic Data Structures

In Static Data Structures, the size is allocated at the compile-time whereas the size is allocated at the run time in Dynamic Data Structures. Therefore, the maximum size is fixed in Static Data Structures and the maximum size is flexible in Dynamic Data Structures.

Types of Static Data Structures:

  • Arrays

Arrays — An array is a collection of data elements of similar types, each of which is referred to as an element of the array. The element’s data type can be any valid data type, such as char, int, float, or double. The array’s elements all have the same variable name, but each one has a different subscript number (index). One-dimensional, two-dimensional, or multidimensional arrays are all possible.

Dynamic Data Structures can be classified into three types.

  • Linked-Lists
  • Stacks
  • Queues

Linked-Lists — A linked list is a type of linear data structure that is used to keep track of a list in memory. It’s a collection of nodes that are stored in non-contiguous memory locations. Each node in the list has a pointer to the node next to it.

Stacks — A stack is a linear list with only one end, termed the top, where insertions and deletions are permitted. A stack is an abstract data type (ADT) that can be used in a variety of programming languages. Stacks follow Last-In-First-Out (LIFO) methodology for storing the data items. It behaves like a real-world stack. Example: a pile of books or plates.

Queues — A queue is a linear list in which elements can only be inserted at one end, called the rear, and deleted at the other end, called the front. It’s a data structure that’s similar to a stack. Because the queue is open on both ends, the data items are stored using the First-In-First-Out (FIFO) approach.

Non-Linear Data Structures are classified into two types.

  • Trees
  • Graphs

Trees — Trees are multilevel data structures containing nodes that have a hierarchical relationship between them. Leaf nodes are at the bottom of the hierarchical tree, whereas root nodes are at the top. Each node has pointers that point to other nodes. The parent-child relationship between the nodes is the basis of the tree data structure. Except for the leaf nodes, each node in the tree can have several children, although each node can only have one parent, except the root node.

Graphs — Graphs can be defined as a graphical representation of a collection of elements connected by edges. A graph differs from a tree in the sense that a graph can have a cycle, but a tree cannot.

Yep!

We have reached the end of the article, and this is just an introduction to Data Structures. I will discuss all the types of Data Structures I have mentioned above in future articles under the Data Structures article series. Hope you got something important! Let’s meet soon with the next article and keep in touch!

--

--

Sachini Amarasinghe
Nerd For Tech

Former Trainee Software Engineer at Creative Software | Final Year Undergraduate at University of Moratuwa, Sri Lanka. https://sachiniamarasinghe.vercel.app/