Ravi Ranjan

Ravi Ranjan

About

Hello readers, I am a technical content engineer having expertise in front-end web development and C++.

117 Articles Published

Articles by Ravi Ranjan

Page 4 of 12

C++ Program to Search for an Element in a Binary Search Tree

Ravi Ranjan
Ravi Ranjan
Updated on 16-Jun-2025 3K+ Views

A Binary Search Tree (BST) is a type of binary tree such that the left subtree has elements smaller than the root element and the right subtree has elements greater than the root element. In this article, our task is to search for an element in the given Binary Search Tree. Characteristics of Binary Search Tree Here are some of the characteristics of the BST: The left subtree of the BST has elements less than the root element. The right subtree of the BST has elements greater than the root ...

Read More

Calling a member function on a NULL object pointer in C++

Ravi Ranjan
Ravi Ranjan
Updated on 13-Jun-2025 1K+ Views

You can call a class member function using a NULL object pointer in C++. This is an undefined behavior and there is no guarantee about the execution of the program. The actual results depend on the compiler used. Class Member Function A class member function is a function that is defined either inside a class or outside a class using a scope resolution operator. Example Here is an example of class member functions in C++ where the print() function is an example of the Inside class function and the print2() function is ...

Read More

Minimum removals to make array sum even in C++

Ravi Ranjan
Ravi Ranjan
Updated on 12-Jun-2025 310 Views

In this article, we have an array arr[] of N integers. Our task is to write a program to find the minimum number of elements needed to be removed from the given array so that the sum of the remaining elements is even. Example The following example demonstrates the minimum number of elements we need to remove from the array for the sum to be even: Input: arr = {12, 23, 40, 53, 17} Output: 1 Input: arr = {20, 11, 13, 40, 24} Output: 0 The explanation of ...

Read More

Minimum removals to make array sum odd in C++

Ravi Ranjan
Ravi Ranjan
Updated on 12-Jun-2025 326 Views

In this article, we have an array arr[] of N integers. Our task is to write a program to find the minimum number of elements needed to be removed from the given array so that the sum of the remaining elements is odd. Example The following example demonstrates the minimum number of elements we need to remove from the array for the sum to be odd: Input: arr = {12, 23, 40, 53, 17} Output: 0 Input: arr = {20, 11, 13, 40, 24} Output: 1 The explanation of the above example is ...

Read More

Count elements smaller than or equal to x in a sorted matrix in C++

Ravi Ranjan
Ravi Ranjan
Updated on 12-Jun-2025 329 Views

In this article, we are given a matrix of size m x n and an integer variable X. The row elements and the first column of the matrix are sorted in increasing order. Our task is to count the number of elements that are equal to or less than the given X value. Counting Elements Smaller Than X in a Sorted MatrixHere are the approaches for counting elements smaller than X in a sorted matrix: Using Linear Search Using Staircase Search Using Linear ...

Read More

Count distinct elements in an array in C++

Ravi Ranjan
Ravi Ranjan
Updated on 11-Jun-2025 8K+ Views

In this article, we have an unsorted array of integers having repetitive elements. Our task is to count the distinct elements in the given array in C++. Example Here is an example of counting the unique number in the given array: Input: array = {4, 2, 32, 26, 57, 52, 40, 2, 57, 40, 33} Output: Distinct elements in the array: 8 Here is a list of approaches for counting distinct elements in the given array: Using Nested for Loop Using Sorting ...

Read More

A Sum Array Puzzle in C++?

Ravi Ranjan
Ravi Ranjan
Updated on 11-Jun-2025 328 Views

In this article, we will solve a sum array puzzle, where we have an array with n elements. We have to create another array of n elements such that the 'ith' position of the second array will hold the sum of all elements of the first array except the 'ith' element. We have one constraint, we cannot use the subtraction operator in this problem. Example Here is an example of calculating the sum of array elements except for the ith element: Input: arr[] = {5, 6, 7, 8} Output: res[] = ...

Read More

Count elements less than or equal to a given value in a sorted rotated array in C++

Ravi Ranjan
Ravi Ranjan
Updated on 10-Jun-2025 620 Views

A sorted and rotated array is an array that is sorted in ascending or descending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. Example Here is an example of counting elements less than or equal to a given value in the sorted and rotated array: Case 1 The given array is: 30 40 50 10 20 Given value = 25 Output Count: 2 (10, 20) Case 2 The given array is: 10 20 30 40 ...

Read More

Find the number of elements greater than k in a sorted array using C++

Ravi Ranjan
Ravi Ranjan
Updated on 10-Jun-2025 1K+ Views

In this problem, we are given an array arr[] consisting of N sorted integer values and an integer k. Our task is to Find the number of elements greater than k in a sorted array. Example Here are some examples of counting the array elements greater than the given target element: Input: arr = {6, 12, 16, 23, 32, 45, 48, 50} target = 20 Output: 5 Input: arr = {6, 12, 15, 20, 32, 45, 48, 50} target = 20 Output: 4 Finding number of elements greater than k in a sorted arrayHere is a list of ...

Read More

JavaScript Program for Number of Local Extrema in an Array

Ravi Ranjan
Ravi Ranjan
Updated on 09-Jun-2025 324 Views

JavaScript Program for the Number of local extrema in an array is a common problem in the field of computer science and data analysis. Local extrema are the peaks and valleys in a sequence of numbers. In this article we are having two arrays, our task is to write a Javascript program for number of local extrema in an array. Example Input: arr1 = [1, 2, 3, 2, 1, 4, 5, 6, 5, 4, 3, 2, 1]; First local extrema: 3, {2 < 3 > 2} Second local extrema: 1, {2 > 1 < 4} Third local ...

Read More
Showing 31–40 of 117 articles
« Prev 1 2 3 4 5 6 12 Next »
Advertisements