Found 7197 Articles for C++

C++ Program to Implement Sorted Circularly Singly Linked List

Nitya Raut
Updated on 30-Jul-2019 22:30:25

552 Views

In data structure, Linked List is a linear collection of data elements. Each element or node of a list is comprising of two items - the data and a reference to the next node. The last node has a reference to null. Into a linked list the entry point is called the head of the list.Each node in the list stores the contents and a pointer or reference to the next node in the list, in a singly linked list. Singly linked list does not store any pointer or reference to the previous node.As it is a sorted singly linked ... Read More

C++ Program to Implement Sorted Circularly Doubly Linked List

Aman Kumar
Updated on 21-May-2025 14:37:29

827 Views

Sorted Circular Doubly Linked ListA sorted circular doubly linked list is a type of circular doubly linked list in which elements are arranged in a specific order, typically ascending or descending based on the data values. The insertion operation makes sure that the new node is placed in its correct sorted position. In Circular Doubly Linked List two consecutive elements are linked or connected by previous and next pointer and the last node points to first node by next pointer and the first node also points to last node by previous pointer. Characteristics of Sorted Circular Doubly Linked List ... Read More

C++ Program to Implement Circular Doubly Linked List

Aman Kumar
Updated on 21-May-2025 14:43:08

7K+ Views

Circular Doubly Linked ListA circular linked list is called a circular doubly linked list in which each node has two links connecting it to the previous node and the next node. In Circular Doubly Linked List two consecutive elements are linked or connected by previous and next pointer and the last node points to first node by next pointer and the first node also points to last node by previous pointer. Characteristics of Circular Doubly Linked List The following are the characteristics of the circular doubly linked list: Circular: The main feature is that ... Read More

C++ Program to find the maximum subarray sum O(n^2) time (naive method)

Aman Kumar
Updated on 20-May-2025 18:47:14

363 Views

A subarray is a contiguous slice of an array, and maintains the order of elements naturally. (i.e., the elements of the subarray occupy consecutive positions). For example, the subarrays of an array {1, 2, 3} are {1}, {1, 2}, {1, 2, 3}, {2}, {2, 3}, and {3}. Input / Output Scenario Let's see the following input/output scenario: Input: arr[] = {1, 4, 5, 3, -1} Output: 13 Explanation: Subarray {1, 4, 5, 3} has the maximum sum 13. Input: arr[] = {1, 2, -3, 4, 5, -1} Output: 9 Explanation: Subarray {1, 2, -3, 4, 5} has the ... Read More

C++ Program to find the median of two sorted arrays using binary search approach

Aman Kumar
Updated on 20-May-2025 18:47:53

243 Views

The median is defined as the middle value of a sorted list of numbers, and the middle value is found by ordering the numbers in ascending order. Once the numbers are ordered, the middle value is called the median of the given data set. Here, in this article, we have two different sorted arrays and need to find the median of these two array using binary search. Median depends on the sorted combined array. So, the following cases may occur: If the length of the combined array is odd, then the median should be the ... Read More

C++ Program to find kth Smallest Element by the Method of Partitioning the Array

Aman Kumar
Updated on 20-May-2025 18:48:23

327 Views

In this articles we will find the kth Smallest Element by Partitioning the Array in C++, let's see input/output scenario: Input / Output Scenario Following is the input-output scenario: Input: arr[] = {7, 2, 1, 6, 8, 5, 3, 4} Output: 3 In the above scenario, after sorting the array, it becomes {1, 2, 3, 4, 5, 6, 7, 8}, so the kth smallest element is 3. An array is a linear data structure that is a collection of elements of the same type in a contiguous memory location. So, to partition a given array, we need to use ... Read More

C++ Program to Implement Double Order Traversal of a Binary Tree

Aman Kumar
Updated on 21-May-2025 14:47:09

224 Views

Double Order Traversal Double order traversal means each node in a tree is traversed twice in a particular order. A binary tree is a non-linear data structure where each node contains at most two children (i.e, left and right). Therefore, suppose we have a given binary tree, and the task is to find its double-order traversal. A double order traversal is a tree traversal technique in which every node traverses twice in the following order: Visit the node. Traverse the left subtree. Visit the node. ... Read More

C++ Program to Implement Cartesian Tree

Aman Kumar
Updated on 16-May-2025 16:54:51

437 Views

Cartesian Tree in C++A Cartesian tree is a binary tree derived from a sequence of distinct numbers. To construct a Cartesian tree, set its root to be the minimum number in the sequence, and then recursively construct its left and right subtrees from the subsequence before and after this number. A Cartesian tree is a tree data structure that obeys the following structural invariants: The tree follows the min (or max) heap property - each node is less than or greater than its children. An inorder traversal of the nodes causes the values in the same order in which they arise in the initial series. Let's construct a max-heap ... Read More

C++ Program to Implement B+ Tree

Aman Kumar
Updated on 16-May-2025 17:14:30

3K+ Views

A B+ tree is an m-tree that consists of a root, internal nodes, and leaves. The root may be a leaf or a node with two or more children. A B+ tree is an advanced data structure that extends the B-tree by adding a linked list of leaf nodes. A B+ tree can be a B-tree where each node contains only keys (not key-value pairs). What is B+ Tree? A B+ tree is a self-balancing tree data structure that maintains sorted data and allows for efficient insertion, deletion, and search operations. It differs from a B-tree in the following ways: ... Read More

C++ Program to find Median of Elements where Elements are stored in 2 different arrays

Aman Kumar
Updated on 15-May-2025 18:47:19

205 Views

The median is defined as the middle value of a sorted list of numbers, and the middle value is found by ordering the numbers in ascending order. Once the numbers are ordered, the middle value is called the median of the given data set. Here, in this article, we have two different sorted arrays and need to find the median of the array that is formed after merging of two given arrays. Median depends on the sorted merged array. So, the following cases may occur: If the length of the merged array is odd, then ... Read More

Advertisements