Hafeezul Kareem has Published 344 Articles

Lagrange’s Interpolation in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 13:16:03

1K+ Views

In this tutorial, we are going to write a program that finds the result for lagranges's interpolation formula.You don't have write any logic for the program. Just convert the formula into code. Let's see the code.Example Live Demo#include using namespace std; struct Data {    int x, y; }; double interpolate(Data ... Read More

Lagrange’s four square theorem in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 13:11:26

270 Views

In this tutorial, we are going to learn about largrange's four square theorem.The lagranges's four square theorem states that every natural number can be written as sum of squares of 4 numbers.The following code finds the 4 numbers which satisfies the above condition for the given number n.ExampleLet's see the ... Read More

kth smallest/largest in a small range unsorted array in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 13:10:55

76 Views

In this tutorial, we are going to write a program that finds the k-th smallest number in the unsorted array.Let's see the steps to solve the problem.Initialise the array and k.Sort the array using sort method.Return the value from the array with the index k - 1.Let's see the code.Example Live ... Read More

Kth smallest element after every insertion in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 13:10:29

167 Views

In this tutorial, we are going to find the k-th smallest element after every insertion.We are going to use the min-heap to solve the problem. Let's see the steps to complete the program.Initialise the array with random data.Initialise the priority queue.Till k - 1 there won't be any k-th smallest ... Read More

Kth prime number greater than N in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 13:10:07

219 Views

In this tutorial, we are going to write a program that finds the k-th prime number which is greater than the given number n.Initialise the number n.Find all the prime numbers till 1e6 and store it in a boolean array.Write a loop that iterates from n + 1 to 1e6.If ... Read More

Kth odd number in an array in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 13:09:45

254 Views

In this tutorial, we are going to write a program that finds the k-th odd number from the given array.Let's see the steps to solve the problem.Initialise the array and k.Iterate over the array.If the current element is odd, then decrement the value of k.If k is 0, then return ... Read More

Kth node in Diagonal Traversal of Binary Tree in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 13:01:01

63 Views

In this tutorial, we are going to write a program that finds the k-th node in the diagonal traversal of a binary tree.Let's see the steps to solve the problem.Initialise the binary tree with some sample data.Initialise the number k.Traverse the binary tree diagonally using the data structure queue.Decrement the ... Read More

Klee’s Algorithm (Length Of Union Of Segments of a line) in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 12:59:57

346 Views

In this tutorial, we are going to write a program that finds the length of union of segments of a line.We are given starting and ending points of the line segment and we need to find the length of union of segments of the line.The algorithm that we are going ... Read More

Keith Number in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 12:59:34

264 Views

In this tutorial, we are going to write a program that checks whether the given number is Keith Number or not.The number n is called Keith number if it appears in the sequence generated using its digits. The sequence has first n terms as digits of the number n and ... Read More

Kaprekar Number in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 12:59:13

2K+ Views

In this tutorial, we are going to write a program that finds whether the given number is kaprekar number or not.Take a number. Find the square of that number. Divide the number into two parts. If the sum of the two parts is equal to the original number, then the ... Read More

Advertisements