Articles for category: Data Structures and Algorithms

Types of Sorting in Data Structures

Sorting is the act of arranging data in ascending or descending order based on linear relationships among data items. It is possible to sort by name, number, and record. Sorting reduces the difficulty of finding information: for example, looking up a friend’s phone number from a telephone dictionary is relatively straightforward because the names in ...

Sorting Techniques in Data Structures

Data structures are formats for organizing, processing, storing, and retrieving data. They can range from simple integer or character data types to more complex structures such as trees and maps. When we run a computer program, we might need to sort the data in a certain order. This is where sorting algorithms come into use. ...

Remove Duplicates from String

Problem Statement Given a string, we have to remove duplicate characters from the string such that each character appears only once (all the characters in the string should become unique). We can print the resultant string in any order. Example Input : “aaabbccd”Output : “abcd” Explanation As we can see the frequency of all the ...

Sieve of Eratosthenes

The Sieve of Eratosthenes is a classic method for efficiently finding prime numbers up to a given limit, crucial in cryptography for securing data like credit card numbers. This ancient algorithm sieves out non-prime numbers, leaving behind the primes. By understanding this algorithm, we unlock a powerful tool for various mathematical applications, from fraction conversion ...

Circular Linked List

Circular linked list is a linked list where all nodes are connected to form a circle. There is no NULL at the end. A circular linked list can be a singly circular linked list or a doubly circular linked list. Before reading this article, you should have some understanding of the following Data Structures topics: ...

Binary Exponentiation

Binary Exponentiation is a technique of computing a number raised to some quantity, which can be as small as $0$ or as large as $10^{18}$ in a fast and efficient manner. It utilises the property of exponentiation and the fact that any number can be represented as sum of powers of two depending on its ...

String in Data Structure

A string is generally considered as a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding. Scope Takeaways Library Functions Introduction A String is seen anywhere and everywhere. Right from when you login onto your device, you ...

Z Algorithm for Pattern Searching

Z algorithm is an algorithm for searching a given pattern in a string. It is an efficient algorithm as it has linear time complexity. It has a time complexity of O(m+n), where m is the length of the string and n is the length of the pattern to be searched. Introduction to the Z Algorithm ...

Dijkstra’s Algorithm

Dijkstra Algorithm is a graph algorithm for finding the shortest path from a source node to all other nodes in a graph(single source shortest path). It is a type of greedy algorithm. It only works on weighted graphs with positive weights. It has a time complexity of $O(V^2)$ using the adjacency matrix representation of graph. ...

Dynamic Programming

The dynamic programming algorithm tries to find the shortest way to a solution when solving a problem. It does this by going from the top down or the bottom up. The top-down method solves equations by breaking them into smaller ones and reusing the answers when needed. The bottom-up approach solves equations by breaking them ...