Data Structures and Algorithms

Shenal Akalanka
3 min readMar 7, 2023

--

Data Structures and Algorithms

✍What are Data Structures and Algorithms?

It is a method that is used to organize and store data in a computer system. It has many structures to save data on a system, such as arrays, linked lists, stacks, queues, trees, and graphs. It also has a variety of algorithms to store data, such as insertion, bubble, selection sort, and quick & merge sort. Insertion, bubble, and selection sort are simple algorithms, but quick & merge sort is an advanced algorithm.

💁Why do we need them?

Developers deal with data every day. So they need to store and retrieve data effectively. To overcome this problem, they should use data structures and algorithms. It helps them process data effectively. This is the most important aspect of computer science. It helps developers store data in a meaningful way.

We can identify three major reasons to learn data structures and algorithms. They are,

1. Data Search

Searching in a data structure refers to the process of finding the required information from a collection of items stored as elements in the computer's memory. When we deal with a large amount of data, data search might be a little difficult.

As an example, consider an inventory of one million items in a store and if an application searches for an item, it has to search for that item in all one million items. So we need to learn a new, efficient method to search data. Otherwise, as data grows, the search will become slower.

2. Process Speed

Even though the processor speed is really high, it becomes limited if the data expands to billion records. Multiple queries Even the fastest web server can fail when searching the data because thousands of users can do it at once.

3. Multiple Request

A web server will crash while looking for data when about 1000 of users are doing it at once, even if the server is extremely fast.

Characteristics of Data Structure

Characteristics of Data Structure

We can mainly identify three characteristics of data structure. They are,

1. Correctness

This is a property related to the algorithm of the data structure. It’s important that the implementation of a data structure implements its interface correctly.

2. Time Complexity

It’s a type of computational complexity that describes the time required to execute an algorithm. It talks about the amount of time it takes for each statement to be completed. This running/execution time of operations of the data structure must be as small as possible.

3. Space Complexity

Space Complexity discusses about the total amount of memory space used by the algorithm/ program. It also includes the memory space for input values for execution. Space Complexity is calculated by the space occupied by variables in an algorithm.

Types of Data Structure

There are two types of Data Structures:

  • Primitive Data Structure
  • Non—Primitive Data Structure

Primitive Data Structure

Primitive Data Structures run directly in accordance with the program's commands. Data types like int, float, double, char, and pointer can be considered primitive data types.

Non-Primitive Data Structure

These data types are more complex than primitive data types, and they are derived from primitive data structures. Further non-primitive data types can be divided into two categories.

  • Linear Data Structure
  • Non-Linear Data Structure

Linear Data Structure

Each data element in a linear data structure is connected to the element before it and the element after it in consecutive order. This kind of data structure is easy to implement as memory is additionally sequential. List, Queue, Stack, and Array are examples for linear data structures.

Non-Linear Data Structure

Non-linear data structures do not have any set of sequential connections among it’s elements. This kind of data structure supports multi-level storage and sometimes can’t be traversed in a single run. This kind of data structures are not easier than linear data structures, but it is more efficient in utilizing memory. Tree, BST, and Graph are examples for non-linear data structures.

--

--

Shenal Akalanka

B.Sc (Hons.) in Information Technology (UG) University of Moratuwa, Sri Lanka