Articles for author: Sushant Gaurav

Next Greater Element

Problem Statement We are given an array of integers, and we need to find the next greater element of every array elements. So, we need to find and print the next greater element of every array element. Note: Refer to the Example and Example Explanation sections for more details and the Approach section to understand how to find the next greater ...

Graph Coloring Problem

Problem Statement We are given a graph, we need to assign colors to the vertices of the graph. In the graph coloring problem, we have a graph and m colors, we need to find a way to color the vertices of the graph using the m colors such that any two adjacent vertices are not ...

kth Largest Element in BST

Problem Statement We are provided with a Binary Search tree and the task is to find the $k^{th}$ largest element in BST (Binary Search Tree). Refer to the Example and Example Explanation sections for more details and the Approach section to understand how to find the $k^{th}$ largest element in bst. Example Example 1: The ...

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

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

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

What is Number System?

A number system, or numeral system, is a method for representing numbers using symbols, crucial in mathematics and programming for data representation. It involves using digits to construct numbers, where each digit’s value is determined by its position and the base value of the system. While computers primarily use the binary system of 0s and 1s, ...

What are the Advantages of Data Structure?

Before learning about the advantages of data structure, we should first understand a data structure and a data type and why we need them. Data types are nothing but the classification or categorization of the data items. Data types represent the kind of value and also tell what operations can be performed on a particular data. Various programming ...

Ugly Numbers

Problem Statement We are provided with a number n. We need to print the n-th ugly number. An ugly number is a number whose prime factors are 2, 3, or 5 only. Note: $1$ is considered as an ugly number (conventionally). Refer to the Example and Explanation sections for more details and the Approach section ...