Found 7347 Articles for C++

Binomial Random Variables in C++

sudhir sharma
Updated on 03-Jan-2020 07:01:33

352 Views

Random variables are those variables that are an outcome of the outcomes of a process that has the probability of giving rise to multiple outcomes. For example, The variable denoting head or tail as an outcome on tossing a coin is a random variable.A binomial random variable is a special type of random variable whose value is related to an event that has a fixed probability of an outcome in an event.There are certain properties that are possessed by a binomial random variable that makes it special. These are a must for a variable to become a binomial random variable ... Read More

Binary Tree to Binary Search Tree Conversion in C++

sudhir sharma
Updated on 13-Jul-2020 08:08:08

848 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 the right child and left child.A simple binary tree is −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 NoteThe right 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 ... Read More

Binary Tree with Array implementation in C++

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

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

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

Binary Search on Singly Linked List in C++

sudhir sharma
Updated on 03-Jan-2020 06:25:18

2K+ Views

A singly linked list is a linked list (a data structure that stores a node’s value and the memory location of the next node) which can go only one way.A binary search is a search algorithm based on divide and rule. That finds the middle element of the structure and compares and uses recursive calls to the same algorithm for inequality.Here, we are given a singly linked list and an element to be found using a binary search.Since the singly linked list is a data structure that uses only one pointer, it is not easy to find its middle element. ... Read More

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

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

152 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 03-Jan-2020 06:17:40

4K+ Views

Binary search is a search algorithm that searches for an element by comparing it with the middle value of the array and dividing it based on the value. The algorithm does this repeatedly until the element is found.The array should be sorted in order to apply a binary search to it.The time complexity of the binary search is of logarithmic order. That's why it is very important for programmers to know shorthands also related to binary search along with its implementations to reduce the time to code the algorithm. Functions related to the binary search algorithm included in the standard ... Read More

Convert a BST to a Binary Tree such that sum of all greater keys is added to every key in C++

Ayush Gupta
Updated on 02-Jan-2020 06:01:04

57 Views

In this tutorial, we will be discussing a program to convert a BST to a binary tree such that the sum of all greater keys is added to every key.For this, we will be provided with a Binary Search tree. Our task is to convert that tree into a binary tree with the sum of all greater keys added to the current key. This will be done by the reverse in order of the given BST along with having the sum of all the previous elements and finally adding it to the current element.Example Live Demo#include using namespace std; //node ... Read More

Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue) in C++

Ayush Gupta
Updated on 02-Jan-2020 05:54:48

301 Views

In this tutorial, we will be discussing a program to convert a binary tree to a threaded binary tree using a queue data structure.For this, we will be provided with a binary tree. Our task is to convert that particular binary tree into a threaded binary tree by adding additional routes for quicker inorder traversal with the help of a queue data structure.Example Live Demo#include #include using namespace std; //node structure for threaded tree struct Node {    int key;    Node *left, *right;    bool isThreaded; }; //putting the inorder pattern into a queue void convert_queue(Node* root, std::queue* ... Read More

Advertisements