DEV Community

Cover image for DATA STRUCTURES 101: Introduction to Data Structures and Algorithms
Dorothy
Dorothy

Posted on

DATA STRUCTURES 101: Introduction to Data Structures and Algorithms

The day-to-day life of a software engineer/developer revolves around solving problems. In order to solve a problem, a software engineer must first understand what the problem is and then highlight the steps to finding a solution. A developer also needs to ensure that the solution is optimal, in that, it is the most efficient way and the quickest way to solve that problem. This is where the concept of Data structures and Algorithms comes in. This concept is important in understanding a problem and how to come up with a solution to the problem.

Data Structures and Algorithms..What are they?

A data structure is a way in which data is organized in a computer in order to be used efficiently. A data structure provides a way for organizing, managing, storing and retrieving data in the most efficient way. By applying data structures in a program, its performance will be greatly improved.

Classification of Data Structures

There are primitive and non-primitive data structures. Primitive data structures operate according to the machine's instructions such as integers, characters, floats and pointers.
Non-primitive data structures are complex data structures that are derived from primitive data structures. The non-primitive data structures are divided into:

  1. Linear Data Structures-elements are arranged in one dimension eg: arrays, linked lists, stacks and queues
  2. Non-Linear Data Structures-elements are arranged in one-many, many-one, many-many dimensions eg: trees

Types of data structures

  1. Array-a collection of data items stored at contiguous memory locations. This means that the elements of an array are stored sequentially.
  2. Linked Lists-elements are stored randomly in containers called nodes which are linked to one another using pointers.
  3. Stack- elements are attached one on top of the other and the elements are accessed using the LIFO method.
  4. Queue- elements are sequentially organized and follows FIFO order to perform operations.
  5. Hashing: data is organized in form of key-value pairs. It uses the Hash function to map a given value with a particular key.
  6. Matrix-a collection of numbers arranged in rows and columns
  7. Binary Tree-a tree in which each node has at most two children(left child and right child)
  8. Binary search tree- a binary tree in which the left subtree of a node contains only nodes with keys less than the node’s key and the right subtree of a node contains only nodes with keys greater than the node’s key
  9. Heap: special tree-based data structure in which the tree is a complete binary tree

Algorithms

Once the data is organized and easily retrieved, the data needs to be processed. An algorithm is a set of instructions used to process the data in a meaningful way.

Writing an algorithm depends on the type of problem and resources at hand. Therefore, a problem can have multiple ways/algorithms of arriving at the solution. In order to write an efficient algorithm, you need to have a very good understanding of the problem.

Properties of an algorithm:

  • Input: there should be 0 or more inputs supplied to an algorithm
  • Output: there should be at least 1 output
  • Definiteness: each instruction of the algorithm should be unambiguous and well-defined
  • Finiteness: the algorithm should be terminated after a finite number of steps
  • Correctness: every step of the algorithm should be correct

Algorithm analysis
Since there are many ways to write an algorithm for a given problem, you need to ensure that the algorithm you've used will result in an optimal solution. An efficient algorithm is one that is executed fastest and uses the least resources.
Algorithm analysis deals with the execution time of the operations involved. This will look into the following components:

  1. Time Complexity-represents the amount of time required by an algorithm to run to completion
  2. Space Complexity-this represents the amount of memory space required by an algorithm

CONCLUSION

There are many data structures and algorithm methods to choose from as highlighted above. The choice of data structures will depend on the type of problem want to solve and how you would want to store the data in order to ensure the data is retrieved and processed in the most efficient manner.

Top comments (0)