Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Farhan Muhamed
101 articles
Array Manipulation and Sum using C/C++
In this problem, you are given an integer array arr of size n and an integer S. Your task is to find an element k in the array such that if all the elements greater than k in the array are replaced with k, then the sum of all the elements of the resultant array becomes equal to S. If such an element exists, print it; otherwise, print -1. Syntax int getElement(int arr[], int n, int S); Algorithm To solve this problem efficiently, we follow these steps − Sort the array in ...
Read More4 Dimensional Array in C/C++
A 4 dimensional array in C is an array of 3 dimensional arrays, where each 3D array contains multiple 2D arrays, and each 2D array contains multiple 1D arrays. This creates a hierarchical structure with four levels of indexing. Syntax datatype array_name[dimension1][dimension2][dimension3][dimension4]; For example: int arr[3][2][3][4]; /* 3 blocks, 2 tables, 3 rows, 4 columns */ Declaration and Initialization You can initialize a 4D array during declaration using nested braces − #include int main() { int arr[2][2][2][3] = { ...
Read MoreC/C++ Macro for string concatenation
In C programming, macros provide a powerful way to concatenate strings at compile-time using the preprocessor. This technique allows for efficient string manipulation without runtime overhead, making it particularly useful for creating constants, debug messages, and code generation. Syntax /* String literal concatenation */ #define STRING1 "First part" #define STRING2 "Second part" #define CONCATENATED STRING1 STRING2 /* Token concatenation using ## operator */ #define CONCAT_TOKENS(a, b) a##b Understanding Macros in C In C, macros are preprocessor directives defined using #define. They are expanded before compilation, replacing every occurrence with the defined value. Macros ...
Read MoreValidate Binary Search Tree in Python
A binary search tree is a special binary tree in which for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will discuss how to validate whether a given binary tree is a valid binary search tree (BST) in Python. Validate Binary Search Tree Algorithm to Validate Binary Search Tree Python Program to Validate Binary Search Tree Validate Binary Search Tree Given a root node of ...
Read MoreVerify Preorder Sequence in Binary Search Tree in C++
In this article will explain a popular coding problem that involves verifying whether a given preorder sequence can represent a valid binary search tree (BST). We will discuss the problem statement, provide examples, algorithm to solve, and a C++ implementation of the solution. Problem Statement Algorithm to Solve Problem C++ Program Time and Space Complexity Verify Preorder Sequence in Binary Search Tree Given an array containing the preorder traversal of a binary tree, we need to verify whether it ...
Read MoreSearching for minimum and maximum values in an Javascript Binary Search Tree
In this article, we will explain how to find the minimum and maximum values in a binary search tree (BST), with implementation in JavaScript. A binary search tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. So the leftmost node will have the minimum value, and the rightmost node will have the maximum value. Find Minimum and Maximum in a BST Given root node of a binary search tree, ...
Read MorePython Program To Find the Smallest and Largest Elements in the Binary Search Tree
In this article, we will explain how to find the minimum and maximum values in a binary search tree (BST), with implementation in Python. A binary search tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. So the leftmost node will have the minimum value, and the rightmost node will have the maximum value. Find Minimum and Maximum in a BST Given root node of a binary search tree, ...
Read MoreProgram to convert binary search tree to a singly linked list in C++?
A Binary Search Tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will discuss how to convert a Binary Search Tree (BST) into a singly linked list in C++. Flatten Binary Search Tree to Singly Linked List Given a Binary Search Tree, the goal is to convert it into a singly linked list where the linked list nodes are in the same order as the in-order ...
Read MorePrint Common Nodes in Two Binary Search Trees in C++
A Binary Search Tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will solve the problem of finding common nodes in two binary search trees (BSTs). Find Common Nodes in BSTs In this problem, you are given two binary search trees (BSTs) and your task is to develop a program that finds all the common nodes between these two trees. In the other words, the intersection ...
Read MorePrint all odd nodes of Binary Search Tree in C++
A Binary Search Tree is a data structure that stores data in a sorted order such that for every node, the left subtree contains values less than the node's value, and the right subtree contains values greater than the node's value. In this article, we will solve the problem of finding all odd nodes of a binary search tree in C++. Find Odd-Valued Nodes in BST You are given a binary search tree (BST) as input and your task is to write a program that finds all the nodes with odd values and returns them as output. To understand ...
Read More