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 7 of 12

C++ Program to Find the peak element of an array using Binary Search approach

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

The peak element in an array is an element that is greater than its neighbor elements i.e., its left and right element. If the peak element is the starting element, then it should be greater than the next element (second element). If the peak element is the last element, then it should be greater than its previous value i.e., the second last element. In this article, we have an array of integers. Our task is to use the binary search algorithm to find the peak element present in the given array. Example Here are two examples to understand the ...

Read More

C++ Program to Find the Minimum element of an Array using Binary Search approach

Ravi Ranjan
Ravi Ranjan
Updated on 04-Jun-2025 345 Views

The binary search works on the divide and conquer principle as it keeps dividing the array into half before searching. For applying the binary search algorithm, the given array should be sorted. Since the array is sorted we do not need to search the minimum element in the array. In this article, the given array has strictly decreasing elements in the left sub-array till it reaches the minimum element and the right sub-array has strictly increasing elements. For example: {40, 30, 20, 10, 25, 35}. In this example, the array is decreasing till it ...

Read More

C++ Program to Find Maximum Element in an Array using Binary Search

Ravi Ranjan
Ravi Ranjan
Updated on 04-Jun-2025 597 Views

The binary search works on the divide and conquer principle as it keeps dividing the array into half before searching. For applying the binary search algorithm, the given array should be sorted. Since the array is sorted we do not need to search the maximum element in the array. Here, the given array is a Bitonic array. A bitonic array is an array in which the left sub-array has strictly increasing elements till it reaches the peak element and the right sub-array has strictly decreasing elements. For example: {10, 20, 30, 40, 35, 25}. In this example, the array is ...

Read More

C++ Program to Implement Booth’s Multiplication Algorithm for Multiplication of 2 signed Numbers

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

Booth's algorithm is a multiplication algorithm that multiplies two signed binary numbers in 2's complement notation. Booth used desk calculators that were faster at shifting than adding and created the algorithm to increase their speed. In this article, we have an array of multiplicand bits and an array of multiplier bits. Our task is to use Booth's algorithm to find the multiplication of these two binary numbers. Example of Booth's Algorithm In this example, we have used Booth's algorithm to calculate the multiplication of two signed binary numbers mathematically. Input: Multiplier(M): 01011 = 11 Multiplicand(Q): 01110 = 14 ...

Read More

C++ Program to Implement Naor-Reingold Pseudo Random Function

Ravi Ranjan
Ravi Ranjan
Updated on 02-Jun-2025 273 Views

The Naor-Reingold pseudo-random function uses a mathematical formula for generating random numbers using an array of secret keys('a') and bits of an input number('x'). The generated random numbers can be repeated based on the array of secret keys. In this article, our task is to generate random numbers using the Naor-Reingold pseudo-random function. Formula of Naor-Reingold function The formula for generating random numbers using Naor-Reingold Pseudo-Random Function is given below: Example Here is an example of generating 5 random numbers using Naor-Reingold Function: Input: p = 31, g = 3, n = 4, a = [1, ...

Read More

C++ Program to Check the Connectivity of Directed Graph Using DFS

Ravi Ranjan
Ravi Ranjan
Updated on 30-May-2025 907 Views

To check if a directed graph is connected or not, we need to check if there exists a path between every pair of vertices. A directed graph (or digraph) is a graph where each edge has a direction, edges are in ordered pairs, and edges traverse from the source vertex (the tail) to the destination vertex (the head). In this article, we have a directed graph with five vertices and its respective adjacency matrix. Our task is to use Depth-first Search(DFS) to check the connectivity of the given graph. Example of Connected Graph In the figure given below, we have ...

Read More

Check if a graph is strongly connected - Set 1 (Kosaraju using DFS) in C++

Ravi Ranjan
Ravi Ranjan
Updated on 30-May-2025 466 Views

To check a strongly connected graph using Kosaraju's algorithm, we need to understand the strongly connected graph and Kosaraju's algorithm. For a graph to be strongly connected, it should be a directed graph, and for any pair of vertices u and v in the directed graph, there exists a directed path from u to v and a directed path from v to u. In this article, we have a directed graph with five vertices. Our task is to use Kosaraju's algorithm to check if the given graph is strongly ...

Read More

C++ Program to Check Whether a Directed Graph Contains a Eulerian Cycle

Ravi Ranjan
Ravi Ranjan
Updated on 28-May-2025 732 Views

The Euler path is a path by which we visit every edge exactly once. We can use the same vertices for multiple times. The Euler Circuit is a special type of Euler path. When the starting vertex of the Euler path is also connected with the ending vertex of that path, then it is called the Euler Cycle. In this article, our task is to check if the Eulerian cycle exists in the given directed graph or not. In the above figure, there is a directed graph and its respective adjacency matrix. The Eulerian path respective to the ...

Read More

C++ Program to Check Whether a Directed Graph Contains a Eulerian Path

Ravi Ranjan
Ravi Ranjan
Updated on 28-May-2025 645 Views

The Euler path is a path using which we can visit every edge exactly once in a graph. The same vertex can be used for multiple times. The source and destination nodes in the Euler path are different. If the source and destination node become the same, then the Eulerian path is also an Eulerian cycle. In this article, our task is to check if there exists an Eulerian path in the given directed graph. Example of Eulerian Path The figure below displays that an Eulerian path exists in the given directed graph. We can see that the starting ...

Read More

C++ Program to Represent Graph Using 2D Arrays

Ravi Ranjan
Ravi Ranjan
Updated on 26-May-2025 2K+ Views

The graph can be represented using various ways. One of the technique is to use a 2D array, also known as adjacency matrix. The adjacency matrix is a square matrix of size V x V to represent a finite graph data structure using a 2D array, where V is the number of nodes/vertex of the graph. In an undirected non-weighted graph, if there is an edge between vertex i and vertex j, the value at matrix[i][j] is 1 and if no edge exists, the value is 0. In this article, our task is to represent the graph using 2D arrays. ...

Read More
Showing 61–70 of 117 articles
« Prev 1 5 6 7 8 9 12 Next »
Advertisements