Articles for category: Data Structures and Algorithms

Suffix Arrays

Suffix arrays are very powerful data structures in terms of their applications in the field strings and string algorithms like pattern searching, string matching algorithms, the longest common prefix of two strings, counting the number of substrings, and in the field of biology some problems like DNA sequencing which uses suffix arrays to efficiently find the ...

Remove Duplicates from an Unsorted Linked List

Problem Statement Write a program to delete duplicate nodes present in an unsorted linked list. Print the original linked list, and the linked list obtained after the deletions. Example Consider the following linked list : After you remove duplicates from the linked list : Example Explanation The given unsorted linked list is : There are multiple occurrences ...

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 ...

Reverse a Linked List

Problem Statement The objective is to reverse a given linked list, which involves altering the pointers between nodes such that the last node becomes the new head node, and each subsequent node points to its predecessor. For Example: Input1 : Output1 : Input2 : Output2 : Input3 : Output3 : Approach 1 : Iterative Method ...

Reverse an Array

Problem Statement Given an array arr[] of length N, print the reverse of it. Example Consider the following example: After reversing this array,we have the new array as Example Explanation The initial array [1,2,3,4,5] when reversed gives [5,4,3,2,1]. Constraints $1 <= N <= 10^5$ There N is the length of the array. Approach 1- Recursive ...

Rearrange Array Alternately

Problem Statement We are provided with a sorted array of size n and we need to rearrange the array alternately. By rearrange array alternately, we should rearrange the array so that the first greatest element will come at the first position, and the first smallest element comes at the second position. Similarly, the second greatest element comes at ...

Serialize and Deserialize a Binary Tree

The need for data structures also demands the ability to convert them into a storable format and reconstruct back later. Serialization is the process of converting a data structure into a sequence of bits. And deserialization is the process of reconstructing the data structure from the serialized sequence. Introduction Data structures play a crucial role in designing efficient software, and ...

Rotate A Linked List

Problem Statement You are given the head of a singly linked list and an integer K, write a program to Rotate the Linked List in a clockwise direction by K positions from the last node. Example Input-1 Output-1 Explanation Here, we have rotated the linked list exactly 2 times. On the First rotation 5 becomes head and 4 becomes ...

Remove Duplicates from Array

Problem Statement Given an array of integers, we have to remove duplicates from array such that each element in the array appears only once (all the values in the array should become unique). Example Input : [1,2,2,3,4,4,4,5,5] Output : [1,2,3,4,5] Explanation As we can see the frequency of all the elements Element Frequency 1 1 2 2 3 1 ...