Articles for category: Data Structures and Algorithms

Flattening a Linked List

Problem Statement Given a Linked List of size N, where every node of the linked list has either of the two pointer or can have both pointer. The sublinked(vertical linked list) and the horizontal linked list is in sorted order.Flatten this linked list such that all the nodes appear in a single level(horizontally) and the ...

Leaders in an Array

Problem Statement Given an array arr of size n with all unique elements. Print all Leaders in the array in any order. Note: A leader is an element of the array if it is greater than all the elements to its right side in the array. The rightmost element is always a leader in an ...

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

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

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