Programming Articles - Page 2182 of 3366

Binary Tree to Binary Search Tree Conversion in C++

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, so we find the inorder traversal of binary tree, sort it in ascending order, and place the sorted nodes in binary tree using inorder traversal to get the binary search tree. Understanding Binary Tree and Binary Search Tree A binary tree is a special type of tree in which ... Read More

Binary Tree with Array implementation in C++

sudhir sharma
Updated on 03-Jan-2020 06:40:01

5K+ Views

A binary tree is a special type of tree in which each node of the tree can have at most two child nodes. These child nodes are known as right child and left child.A simple binary tree is −For representing trees, there are two ways, dynamic node representation which uses linked listSequential representation which uses array.Here, we will discuss about array representation of binary tree. For this we need to number the nodes of the BT. This numbering can start from 0 to (n-1) or from 1 to n.Lets derive the positions of nodes and their parent and child nodes ... Read More

Binary Search Tree - Delete Operation in C++

sudhir sharma
Updated on 03-Jan-2020 06:37:30

4K+ Views

Binary search tree (BST) is a special type of tree which follows the following rules −left child node’s value is always less than the parent Noteright child node has a greater value than the parent node.all the nodes individually form a binary search tree.Example of a binary search tree (BST) −A binary search tree is created in order to reduce the complexity of operations like search, find minimum and maximum.Delete Operation binary search tree (BST)delete operation is dropping the specified node from the tree. in case deleting the nodes, there are three possibilities −Deleting a leaf node from the tree: ... Read More

Binary Search Tree - Search and Insertion Operations in C++

sudhir sharma
Updated on 03-Jan-2020 06:31:08

2K+ Views

Binary search tree (BST) is a special type of tree which follows the following rules −left child node’s value is always less than the parent Noteright child node has a greater value than the parent node.all the nodes individually form a binary search tree.Example of a binary search tree (BST) −A binary search tree is created in order to reduce the complexity of operations like search, find minimum and maximum.Search operation in BSTPerforming a search in a binary search tree, We need to search for a key in the tree. For this, We will compare the key with the root ... Read More

How to iterate the contents of a collection using forEach() in Java?

raja
Updated on 13-Jul-2020 08:06:06

338 Views

Lambda expression is the anonymous representation of a function descriptor of a functional interface. As we know that all collection interfaces like List, Set and Queue use an Iterable as their super interface. Since Java 8, an Iterable interface introduces a new method called forEach(). This method performs an action on the contents of Iterable in the order elements that occur when iterating until all elements have processed.Syntaxvoid forEach(Consumer

Binary Search on Singly Linked List in C++

Ravi Ranjan
Updated on 08-Aug-2025 14:40:31

2K+ Views

In this article, we are given a sorted singly linked list, and our task is to search for a given node using a binary search algorithm. The binary search algorithm works on the divide-and-conquer principle as it keeps dividing the list in half before searching. To search for an element in the linked list using binary search, it should be sorted. In the sorted linked list, we find the middle node using two pointers (slow and fast) and compare it with the target node, and based on the comparison, we either search in the left or right sub-list or return ... Read More

Binary Search in C++ Standard Template Library (STL)

sudhir sharma
Updated on 03-Jan-2020 06:21:12

265 Views

A binary search known as logarithmic search is a search algorithm that searches for an element in a sorted array. The algorithm recursively divides the array into two halves, if the element is found at the mid position then return otherwise call the divide and check again until the element is found.WorkingThe algorithm works by comparing the middle element of the sorted array with the element that is to be searched.If the search element is equal to the middle element, then return the index of the element.If the search element is greater than the middle element, search in the left ... Read More

Binary Search functions in C++ STL (binary_search, lower_bound and upper_bound)

sudhir sharma
Updated on 16-Jun-2025 18:18:23

4K+ Views

Binary search is the fastest algorithm for finding an item from a sorted list of items. C++ STL provides built-in functions to perform binary search operations on sorted ranges of elements. In this article, we will learn binary_search, lower_bound and upper_bound functions in C++ STL. First of all, let's understand what binary search is. What is Binary Search? Binary search is a fast search algorithm with run-time complexity of (log n). This search algorithm works on the principle of divide and conquer, since it divides the array into half before searching. This algorithm works only on sorted collection of ... Read More

How to use UnaryOperator interface in lambda expression in Java?

raja
Updated on 13-Jul-2020 08:00:30

1K+ Views

UnaryOperator is a functional interface that extends the Function interface. It represents an operation that accepts a parameter and returns a result of the same type as its input parameter. The apply() method from Function interface and default methods: andThen() and compose() are inherited from the UnaryOperator interface. A lambda expression and method reference can use UnaryOperator objects as their target.Syntax@FunctionalInterface public interface UnaryOperator extends FunctionExample-1import java.util.function.UnaryOperator; public class UnaryOperatorTest1 {    public static void main(String[] args) {       UnaryOperator operator = t -> t * 2;   // lambda expression       System.out.println(operator.apply(5));       System.out.println(operator.apply(7));       System.out.println(operator.apply(12));    } }Output10 ... Read More

How to use BinaryOperator interface in lambda expression in Java?

raja
Updated on 13-Jul-2020 07:29:22

1K+ Views

BinaryOperator is one of a functional interface from java.util.function package and having exactly one abstract method. A lambda expression or method reference uses BinaryOperator objects as their target. BinaryOperator interface represents a function that takes one argument of type T and returns a value of the same type.BinaryOperator Interface contains two static methods, minBy() and maxBy(). The minBy() method returns a BinaryOperator that returns the greater of two elements according to a specified Comparator while the maxBy() method returns a BinaryOperator that returns the lesser of two elements according to a specified Comparator.Syntax@FunctionalInterface public interface BinaryOperator extends BiFunctionExampleimport java.util.function.BinaryOperator; public class BinaryOperatorTest {    public static void main(String[] args) {       BinaryOperator ... Read More

Advertisements