Found 26504 Articles for Server Side Programming

C++ Program to Implement Splay Tree

Aman Kumar
Updated on 30-May-2025 18:39:36

3K+ Views

Splay Tree Splay tree is a self-balanced binary searched tree. The idea of implementing the splay tree is to bring the most recently inserted element to the root of the tree by performing a sequence of tree rotations, called splaying. Following are the basic operation on AVL: Insertion Searching Deletion Rotation: There are two types of rotation in splay tree (zig rotation and zag rotation). Let's see the code snippet of the above operation: Insertion Efficiently inserts a new key into the ... Read More

C++ Program to Implement self Balancing Binary Search Tree

Aman Kumar
Updated on 29-May-2025 15:44:52

2K+ Views

Self Balancing Binary Search tree A self-balancing binary search tree (BST) is a height-balanced binary search tree that automatically keeps its height (the maximum number of levels below the root) as small as possible when insertion and deletion operations are performed on the tree. In the self-balancing binary search tree, the height is maintained in the order of O(logn), so that all operations take O(logn) time on average. Common examples of self-balancing binary search trees are: AVL Tree RED Black Tree Splay Tree AVL Tree An ... Read More

C++ Program to Implement Randomized Binary Search Tree

Aman Kumar
Updated on 29-May-2025 15:45:27

721 Views

A Randomized Binary Search Tree (RBST) is a variation of a Binary Search Tree (BST) that contains randomization to maintain balance and improve efficiency. One common implementation of an RBST is a Treap, which combines BST properties with heap properties. Why We Use Random Binary Tree Random binary trees are used for analyzing the average-case complexity of data structure based on the binary trees. Features of RBST Following are the features of the randomized binary tree: BST Properties: The left subtree contains smaller value, right subtree contains larger value. Randomization: ... Read More

C++ Program to Implement Interval Tree

Aman Kumar
Updated on 28-May-2025 16:31:44

864 Views

What is an Interval Tree? An interval tree is a tree data structure that stores intervals. It helps us to efficiently find all intervals that overlap with a specific interval or point. The purpose is to enhance a self-balancing Binary Search Tree (BST) known as Interval Tree, which is similar to Red Black Tree, AVL Tree, and so on, with a set of intervals so that all operations can be performed in O(log n) time. Every node of interval trees stores the following details: i: An interval which is represented as a pair [start, end]. ... Read More

C++ Program to Implement Fusion Tree

Aman Kumar
Updated on 27-May-2025 16:33:56

669 Views

A fusion tree is a tree data structure that implements an associative array on w-bit integers. Here, W is the number of bits in the integer. A fusion tree is used to maintain the ordered set of elements. It uses a combination of a B-tree and a hash table that helps reduce the time complexity of the operations like insertion, deletion, and searching in the tree. How Fusion Tree Works? The following are the factors that should be considered while implementing the fusion tree: Bit manipulation: The tree extracts specific bits from stored integers and ... Read More

C++ Program to Implement Expression Tree Algorithm

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

461 Views

An expression tree is basically a binary which is used to represent expressions. In expression tree, internal nodes correspond to operators and each leaf node corresponds to an operand. Here is a C++ Program to implement the Expression Tree Algorithm which takes the postfix expression as an input and generates the corresponding expression tree traversed in inorder.AlgorithmBegin    function construct_expression_tree():       Flag = 1 when it is operand.       Flag = -1 when it is operator.       S = suffix[0] means read the first operand from the expression.    For i = 0 and ... Read More

Virtual Constructor in C++

Aman Kumar
Updated on 27-May-2025 16:31:50

23K+ Views

In C++, we cannot create a virtual constructor, this is because C++ is a statically typed language and the constructor is responsible for creating an object. So, the compiler needs to know the exact type of object at compile time. The virtual mechanism works only when we have a base class pointer to a derived class object. The constructor cannot be virtual, because when a constructor of a class is executed there is no virtual table in the memory, means no virtual pointer defined yet. So, the constructor should always be non-virtual. Implementation of Constructor & Destructor In the following ... Read More

Virtual Destructor in C++

Aman Kumar
Updated on 27-May-2025 16:32:51

2K+ Views

A virtual destructor is a destructor declared within the base class with a virtual keyword. In C++, destructors are special members of a class that frees memory occupied by an object when a memory leak occurs. Deleting a derived class object using a pointer to a base class, the base class should be defined with a virtual destructor. When to Use Virtual Destructor? Virtual destructorsare needed in scenarios where polymorphism and inheritance are involved, and instances of derived classes are managed by pointers to base classes. If our class has one or more virtual functions that are inherited from child ... Read More

Virtual functions in derived classes in C++

Aman Kumar
Updated on 26-May-2025 12:49:45

1K+ Views

Virtual Functions in Derived ClassesA virtual function is declared using the virtual keyword in the base class and becomes a member function of the base class overridden by the derived class. It becomes virtual in every class which is derived from the base class. So, the keyword virtual is not necessary in the derived class while declaring redefined versions of the virtual base class function. When we use a pointer or reference to the base class to refer to a derived class object, we can call its virtual function. Syntax Following is the syntax of the virtual function in ... Read More

Default arguments and virtual function in C++

Aman Kumar
Updated on 22-May-2025 18:28:36

331 Views

Default Argument A default argument is a value provided during the function declaration that can be automatically assigned if no argument is provided when the function is called. If a value is passed at the time of the function call, this default value is overridden, and the argument becomes a parametrized Argument. Syntax The syntax below shows how we can define a default argument function: int fun(int x = 0){ // function body } Example of Default Argument The following C++ example shows the working of the default argument: #include using namespace std; //function defined with ... Read More

Advertisements