Catalan Numbers are sequences of natural numbers that gives the number of BST (Binary Search Tree) possible with n Values. So, the Catalan number is a full binary tree with n+1 leaves.Some applications of Catalan Numbers are counting the pairs of nested parentheses, valid mountain ranges etc.For n = 5, C = (C(0) * C(4)) + (C(1) * C(3)) + (C(2) * C(2)) + (C(3) * C(1)) + (C(4)* C(0))Thus, we can see that Catalan numbers are in the form of a recursive relation, i.e., for the nth term, the Catalan number Cn is, ... Read More
Let’s suppose we have given an array of integers. The task is to find the index of a particular element in the given array. For example, Input-1 −N = 8 A[ ] = { 1, 2, 4, 3, 3, 1, 1, 5}Output −1Explanation − In the given array of integers, the most appearing number is ‘1’. Thus the output is ‘1’.Input-2 −N = 6 A[ ] = {1, 5, 4, 4, 1, 1}Output −1Explanation − In the given array of integers, the most appearing number is ‘1’. Thus we can return the output ‘1’.Approach to solve this problemThe given array ... Read More
A linked List is a linear data structure that has multiple nodes that are connected with each other. Each node consists of two fields Data Field and address of the next node.Let us assume we have given a singly linked list the task is to insert a node at the beginning of the given linked list. For example, Input-1 − 1 → 2 → 3 → 4Insert ‘5’ at the head or beginning of the given linked list.Output − 5 → 1 → 2 → 3 → 4Explanation − After inserting the node at the beginning of the linked list ... Read More
Red Black Tree is a Self-Balanced Binary Search Tree in which each node of the tree is colored with either Red or Black. There are three types of operations we can perform on a Red Black Tree – Searching, Insertion and Deletion.Let us suppose we have to insert an element in the following Red Black Tree.To insert an element in a red-black tree the idea is very simple − we perform insertion just like we insert in a regular binary tree. We start off from the root node by checking the color of the node and insert it into a ... Read More
Pandigital Number − In Mathematics, a Pandigital number is an integer that in a given base has among its significant digits each digit used in the base at least once.Pandigital numbers are the integers in which each digit is used as the base at least one time.For example, 1245678 is a pandigital number.Approach to solve this problemTake Input a number and a base.Check the base if it is less than 2 and greater than 10 then return 1 otherwise check the number if it is pandigital or not.An Integer function is_pandigital(long long n, int base) takes a number and a ... Read More
Let’s Suppose we have given two strings ‘a’ and ‘b. We have to check that the given two strings are anagram of each other or not. Two Strings are said to be anagram of each other if one string contains the same character as another.For ExampleInput-1 −a= anagram b= gnaramaOutput −TrueExplanation − String ‘gnarama’ has the same character as String ‘anagram’ has. Hence we return True.Input-2 −a= programmer b= mprogretmrqpOutput −FalseExplanation − String ‘b’ has more characters than the string ‘a’ and thus we can say that the length of the string is different. Thus we return False.The approach used ... Read More
Given an array of sorted numbers containing only 0s and 1s, find the transition point. A transition point is the index of the first ‘1’ appearing in the array. For example, Input-1 −N = 6 arr[ ] = {0, 0, 0, 0, 1, 1}Output −4Explanation − Since in the given array containing 0’s and 1’s we can see that the element at the index ‘4’ is having the number ‘1’.Input-2 −N = 5 arr[ ] = {0, 0, 1, 1, 1}Output −2Explanation − In the given array containing 0’s and 1’s, we can see that the element at the index ... Read More
Floyd Cycle is one of the cycle detection algorithms to detect the cycle in a given singly linked list.In the Floyd Cycle algorithm, we have two pointers that initially point at the head. In Hare and Tortoise’s story, Hare moves twice as fast as Tortoise, and whenever the hare reaches the end of the path, the tortoise reaches the middle of the path.AlgorithmInitialize Hare and Tortoise at the head node of the List.Initially, the hare moves twice as fast as the tortoise.Move the hare and tortoise both and find if the hare reaches the end of the Linked List, return ... Read More
Suppose we have an array of integers of size N and a key K. Our task is to print the top K most frequent element of the array. For example, Input-1 −N = 6 K = 2 arr[ ] = {1 ,1, 1, 2, 2, 3}Output −1 2Explanation − In the given array of integers, the top K=2 elements whose frequency is most in the array are {1, 2}.Input-2 −N = 2 K = 1 arr[ ] = {1, 2}Output −1Explanation − In the given array of integers, the top K=1 elements whose frequency is most in the array are ... Read More
Let’s suppose we have an array of integers of size N. The task is to find the most frequent element present in the given array of integers. For example, Input-1 −N = 8 A[ ] = {1, 2, 4, 3, 3, 1, 1, 5}Output −1Explanation − In the given array of integers, the most appearing number is ‘1’. Thus the output is ‘1’.Input-2 −N = 6 A[ ] = {1, 4, 4, 4, 1, 1}Output-a −1Output-b −4Explanation: In the given array of integers, the most appearing number is ‘1’ and ‘4’. Thus we can return the output to any one ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP