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

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

Detect Loop in Linked List

Problem Statement Given a linked list, check whether the linked list is having a loop or not(detect loop in linked list). A cycle exists in a linked list if it contains a node that may be accessed again by following the next pointer. Example Input: Output: True Explanation: linked list is having 6 nodes and the next ...

Hamiltonian Cycle

What is Hamiltonian Cycle? Hamiltonian Cycle or Circuit is a path in an undirected graph that visits all the vertices in the graph exactly once and terminates back at the starting node. Problem Statement Given an undirected graph, our task is to determine whether the graph contains a Hamiltonian cycle or not. Example Explanation In the above example, ...

Digit DP

Digit Dp as the name suggests, is a technique of dynamic programming wherein we use the digits of the numbers to reach the final solution. This technique solves those problems which concern the digits between two specified integers. To find the solution, we try building all the integers between the two given integers and compute ...