Articles for category: Data Structures and Algorithms

Check If Two Strings are Anagram

An anagram string is a rearrangement of the letters of a given string to form another word or phrase, using all the original letters exactly once. For example, “listen” and “silent” are string anagrams of each other. In this article, we will be delving into what is anagram string. Problem Statement Given two strings consisting ...

Iterative Inorder Traversal

In the iterative inorder traversal of a binary tree, nodes are visited in the left, root, right sequence without using recursion. This traversal, which uses a stack for managing node sequence, is a key approach in processing binary trees, characterized by their two-node structure. We’ll explore how this method works and analyze its time and ...

What is an Internal Sorting Algorithm?

Any sorting algorithm that uses the main memory exclusively during the sort is known as an internal sorting algorithm. In Internal sorting, the data can be accessed extremely fast and randomly. The internal sorting technique is used when data items are less than enough to be held in the main memory (RAM). Algorithms Used for ...

Preorder to Postorder Traversal

Problem Statement Given an array that represents the preorder traversal of a binary search tree, write a program to find the postorder traversal of the BST. Example The preorder of a BST is given below:preorder[] = {10, 5, 8, 25, 47}The postorder for the example will be:postorder[] = {8, 5, 47, 25, 10} Example Explanation ...

Naive String Matching Algorithm

Problem Statement The problem states that we are given a text string (let’s say text) having the length n and a pattern string (let’s say pattern) having the length m. We need to write a function that takes these two strings (pattern, and text) and prints all the occurrences of the pattern string in the text string. Note: ...

Morris Traversal

Problem Statement Given a binary tree, we need to traverse the tree (visit and print the nodes of the need) without using a stack or recursion. Note: Use the Morris traversal to traverse the binary tree without using any extra data structure and recursion. Example Input tree is: Output: The Morris traversal (in order) of the ...

Longest Common Substring

Problem statement: Given two strings string_1 and string_2 of size N and M respectively. Find the length of the longest common substring. The problem statement says that we are given two strings and we need to return the length of the longest common substring from the given strings. For example: Input: Output: Explanation: The longest common substring from string_1 and string_2 of lengths N ...

Find Duplicates in Array

Problem Statement Given an array A of size N + 1. Each element in array A is between 1 and N. Write a program to find one of the duplicates in array A. If there are multiple answers, then print any. Example 1 Input:N = 5A = [1, 2, 5, 3, 4, 3]Output3 ExplanationIn this ...

Palindrome Linked List

Problem Statement We are provided with a linked list (singly linked list) and we need to check whether the provided linked list is a palindrome linked list or not. Now, palindrome means any word or sequence that reads the same forwards as backward. For example mom is a palindrome as it reads the same forwards ...

Postorder Traversal without Recursion

Problem Statement Given a tree, we need to traverse the tree in a post-order traversal way and print the nodes of the tree in the post-order traversal order. The traversal should be done without using recursion. In order to proceed with the problem, we need to understand how post-order traversal is done over the tree. ...