Articles for category: Data Structures and Algorithms

Maximum Sum Increasing Subsequence

Problem Statement An array of positive integers of size n is given. write a program to find the maximum sum increasing subsequence in the given array. The maximum sum increasing subsequence is a subsequence of an integer array where the sum is maximum and all of the elements are sorted in non decreasing order. Example ...

Prims and Kruskal Algorithm

Overview Prim’s algorithm and Kruskal’s algorithm are greedy algorithms used to find the minimum spanning tree in a weighted graph. Prim’s and Kruskal’s algorithms have many use cases they are used in solving traveling salesman problems, LAN networks, TV networks, and in general for any network where we need to find the least cost subset ...

Longest Palindromic Substring

Problem Statement The Longest Palindrome in a String in one of the most classic problems in DSA. The problem statement goes like this: Given a string, find the maximum length substring of it that is a palindrome. Input: String Output: String Before we move on to examples and the solution to this problem, make a note of the ...

Introduction to Logarithms

Overview In this article, we are going to learn about Logarithms in programming. Before getting started with the topic, let us get a short overview of what is Logarithms. Logarithms: In mathematics, the inverse of an exponential function is called the logarithmic function. In simple terms, the logarithm is the exponent or power of any ...

Insertion in linked list

Modify a Linked List by inserting a new node at the front, after a specified node, and at the end. These operations offer flexibility in updating the structure based on specific needs, enabling dynamic adjustments to the Linked List. Insertion at the Beginning of the Linked List Insertion at the Beginning of the Linked List ...

Binary Coded Decimal Addition

BCD addition transforms the simple sum of two numbers, A and B, into a binary-coded marvel, concatenating each digit’s binary form from their sum into a precise, digital-friendly format. What is BCD? BCD, or Binary Coded Decimal, is a unique encoding system where every decimal digit is represented by its 4-bit binary counterpart. This method ...

Boyer Moore Algorithm

Problem Statement We are provided with an input pattern and a text (or string), and we need to search and print all the occurrences of the pattern in the string. Note: Use Boyer Moore’s algorithm for searching the pattern in the string. Refer to the Example and Explanation sections for more details and the Approach section to understand the working of the Boyer Moore algorithm. ...

Level Order Traversal in Spiral Form

Problem Statement Given a root node of a binary tree, print its level order traversal in spiral order. Example InputLet’s assume we have the following binary tree – Note that only the address of the root node is provided as the input. Output Example Explanation The simple level order traversal of the tree is – ...

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

Check for BST

Problem Statement Given a binary tree, we have to determine if the tree is a binary search tree or not.A tree is said to be a valid binary search tree when, Example consider the following examplesexample-1 output: example-2 output: Example Explanation In example 1,Condition 1 is not satisfied. All the nodes in the left subtree ...