DEV Community

Kiprotich kimutai
Kiprotich kimutai

Posted on

Data structures and algorithms

Laptop photo
Introduction to data structures and algorithms
Data structures and algorithms sound scary,right? Luckily, I'll give an easier overview of each with simple examples.

Data structures
Data Structure is basically a way to store and organize data for efficient use. Organized data is easier to use than unorganized data. For example, assuming the dictionary was not organized according to alphabets, would it be easy to find a word from it? The same way in a computer we need to organize data for efficient and easy use; data structure is the answer.
Data structures can either be linear or non linear.
Some of the examples of data structures are;

  1. Array An array is a collection of elements of the same data type such as an integer and a string.The operations that can be done on arrays are;
  • Transversal - it is a process of visiting each element once
  • Insertion -It is the process of including one or more elements in an array.It can be at the beginning,end or a given index
  • Deletion -It is the process of removing the desired element and re-organizing it
  • Searching -Looking for a specific element in an array
  • sorting -It is the process in which it sorts elements in a user-defined order
  1. LinkedList A linked list is a collection of objects linked together by references from one object to another object. Linkedlists have the following operations -Deleting - Removing an element from a linked list. -Searching - Find the first element that matches a condition in the given linked list by a simple linear search. -Inserting - Add a key to the linked list 3.Stack A stack follows the principle of Last In First Out (LIFO). This means the last element inserted inside the stack is removed first. The operations are; -Push - Insert an element on to the top of the stack. -Pop - remove the topmost element and return it.
  2. Queue A queue follows the FIFO (First In First Out) method and is open at both of its ends. Data insertion is done at one end rear end or the tail of the queue while deletion is done at the other end called the front end or the head of the queue. Operations that can be done on a queue are: -Enqueue - Insert an element to the end of the queue. Dequeue - Delete the element from the beginning of the queue.

*What are algorithms *

Algorithm picture
an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input and produces a desired output. For example,

  • An algorithm to add two numbers:

  • Take two number inputs

  • Add numbers using the + operator

  • Display the result

Discussion (0)