Ravi Ranjan has Published 148 Articles

Binary Search Tree to Greater Sum Tree in C++

Ravi Ranjan

Ravi Ranjan

Updated on 04-Sep-2025 15:02:56

343 Views

In this article, we are given a binary search tree. Our task is to transform the given BST to a Greater Sum tree. A Greater Sum Tree with respect to the given BST is a tree where each node's value is replaced by the sum of all values greater ... Read More

Binary search in C#

Ravi Ranjan

Ravi Ranjan

Updated on 21-Aug-2025 19:19:17

12K+ Views

The binary search algorithm works on the divide and conquer principle as it keeps dividing the array in half before searching. To search for an element in an array using binary search, the array should be sorted. In the sorted array, we find the middle element and compare it with ... Read More

Binary Search program in JavaScript

Ravi Ranjan

Ravi Ranjan

Updated on 21-Aug-2025 19:19:04

759 Views

The binary search algorithm works on the divide and conquer principle as it keeps dividing the array in half before searching. To search for an element in an array using binary search, the array should be sorted. In the sorted array, we find the middle element and compare it with ... Read More

Difference Between Linear Search and Binary Search

Ravi Ranjan

Ravi Ranjan

Updated on 21-Aug-2025 19:18:50

3K+ Views

A linear search compares the target element with each array element, while a binary search uses divide-and-conquer method to efficiently search for the target element. In this article, we will compare linear search and binary search. What is Linear Search? Linear search is a sequential searching algorithm where we ... Read More

C++ Program to Find the Number of occurrences of a given Number using Binary Search approach

Ravi Ranjan

Ravi Ranjan

Updated on 20-Aug-2025 13:43:41

272 Views

In this article, our task is to find the number of occurrences of a given number using binary search. The binary search algorithm works on the divide-and-conquer principle as it keeps dividing the array in half before searching. To search for an element in an array using binary search, it ... Read More

Maximum Sum SubArray using Divide and Conquer in C++

Ravi Ranjan

Ravi Ranjan

Updated on 20-Aug-2025 13:41:56

1K+ Views

In this article, we have an array of integers. Our task is to find the maximum sum of a sub-array using divide and conquer algorithm. A sub-array is a continuous part of an array with consecutive array elements. For example: {2, 3, 4} is sub-array of {1, 2, 3, 4, ... Read More

Check if a given array can represent Preorder Traversal of Binary Search Tree in C++

Ravi Ranjan

Ravi Ranjan

Updated on 19-Aug-2025 17:22:30

544 Views

In this article, we have an array of preorder traversal of a binary search tree. Our task is to check if the given array can represent the preorder traversal of the binary search tree. In preorder traversal of tree, the root node is visited first, then the left subtree, and ... Read More

Balance a Binary Search Tree in c++

Ravi Ranjan

Ravi Ranjan

Updated on 19-Aug-2025 17:22:10

3K+ Views

In this article, we have a binary search tree and our task is to balance the given binary search tree. A binary search tree is a tree data structure and a special type of binary tree that follows the conditions given below: The left child ... Read More

Binary Tree to Binary Search Tree Conversion in C++

Ravi Ranjan

Ravi Ranjan

Updated on 19-Aug-2025 17:21:44

1K+ Views

To convert a binary tree to a binary search tree, use the inorder tree traversal of the tree. In inorder traversal, we first traverse the left subtree, then the root node, and then the right subtree. The nodes in inorder traversal of a binary search tree are in ascending order, ... Read More

Binary search in sorted vector of pairs in C++

Ravi Ranjan

Ravi Ranjan

Updated on 18-Aug-2025 16:08:48

595 Views

In this article, we have a sorted vector of pairs. Our task is to search for a target key using binary search in the given vector of pairs. Binary Search Algorithm The binary search algorithm works on the divide-and-conquer principle as it keeps dividing the array in half before searching. ... Read More

1 2 3 4 5 ... 15 Next
Advertisements