Hafeezul Kareem has Published 328 Articles

Kth smallest element after every insertion in C++

Hafeezul Kareem

Hafeezul Kareem

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

235 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

289 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

338 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

108 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

642 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

416 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

3K+ 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

K’th Smallest/Largest Element using STL in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 12:58:23

849 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.Initialise a empty ordered set.Iterate over the array and insert each element to the array.Iterate over the set from 0 ... Read More

K’th Smallest/Largest Element in Unsorted Array in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 12:37:28

230 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.ExampleLet's see the code. Live ... Read More

K’th Least Element in a Min-Heap in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 09-Apr-2021 12:37:03

529 Views

In this tutorial, we are going to write a program that finds the k-th least element from the min-heap.We will use priority queue to solve the problem. Let's see the steps to complete the program.Initialise the min-heap with correct values.Create a priority queue and insert the root node of the ... Read More

Advertisements