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
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to invert a binary search tree using recursion in C#?
To invert a binary search tree, we swap the left and right child nodes for every node in the tree recursively. This operation creates a mirror image of the original tree. The algorithm uses a recursive approach where we process each node by first inverting its left and right subtrees, then swapping their positions. The process involves calling a method InvertBinaryTree that takes a node as a parameter. If the node is null, we return null. Otherwise, we recursively call the method on both left and right children, then swap the left and right child references. ...
Read MoreGet a read-only copy of the OrderedDictionary in C#
The OrderedDictionary class in C# provides the AsReadOnly() method to create a read-only copy of the collection. This wrapper prevents any modifications to the dictionary while maintaining access to all elements in their insertion order. Syntax Following is the syntax for creating a read-only copy of an OrderedDictionary − OrderedDictionary readOnlyDict = originalDict.AsReadOnly(); Return Value The AsReadOnly() method returns an OrderedDictionary wrapper that is read-only. Any attempt to modify this wrapper will throw a NotSupportedException. Using AsReadOnly() Method The following example demonstrates how to create a read-only copy and verify its ...
Read MoreCopy the entire LinkedList to Array in C#
The LinkedList class in C# provides the CopyTo() method to copy all elements from a LinkedList to an array. This method is useful when you need to convert a dynamic LinkedList structure into a fixed-size array for processing or storage. Syntax Following is the syntax for copying a LinkedList to an array − linkedList.CopyTo(array, arrayIndex); Parameters array − The one-dimensional array that is the destination of elements copied from LinkedList. arrayIndex − The zero-based index in array at which copying begins. LinkedList ...
Read MoreHow to check whether a binary tree is a valid binary search tree using recursion in C#?
A Binary Search Tree (BST) is a tree structure where each node's left child contains values smaller than the node, and the right child contains values greater than the node. To validate whether a binary tree is a valid BST using recursion, we need to check that each node's value falls within its allowed range based on its position in the tree. The recursive approach uses upper and lower bounds that get updated as we traverse the tree. For each node, we verify that its value lies within the current bounds, then recursively check the left subtree with updated ...
Read MoreC# Program to Find Volume, Perimeter and Surface Area of Cuboid
A cuboid is a three-dimensional geometric shape with six rectangular faces, where opposite faces are equal in dimensions. It has three dimensions: length, breadth (width), and height. We can calculate the volume, perimeter, and surface area of a cuboid using specific mathematical formulas. Cuboid Structure Length Breadth Height Formulas The following formulas are ...
Read MoreRemove all elements from a HashSet in C#
To remove all elements from a HashSet in C#, you use the Clear() method. This method removes all elements from the HashSet and resets its count to zero. The Clear() method is the most efficient way to empty a HashSet completely. Syntax Following is the syntax for the Clear() method − hashSet.Clear(); Parameters The Clear() method takes no parameters. Return Value The Clear() method returns void (no return value). Using Clear() Method Example using System; using System.Collections.Generic; public class Demo { public static ...
Read MoreC# Program to Generate Marksheet of Student
A marksheet generation program is a practical application that calculates a student's total marks, percentage, and grade based on subject scores. This C# program demonstrates how to create a simple marksheet system using basic input/output operations, arithmetic calculations, and conditional logic. Algorithm The marksheet generation follows these steps − Step 1 − Declare variables for student roll number, name, subject marks, total marks, and percentage. Step 2 − Accept input for student details and marks in each subject. Step 3 − Calculate total marks by summing all subject marks. Step 4 − Calculate percentage ...
Read MoreHow to check whether a binary tree has the given path sum in C#?
A binary tree has a path sum when there exists a root-to-leaf path where the sum of all node values equals a given target sum. The HasPathSum method recursively traverses the tree, subtracting each node's value from the target sum until reaching a leaf node. Syntax Following is the syntax for checking path sum in a binary tree − public bool HasPathSum(Node node, int targetSum) { if (node == null) return false; if (node.LeftChild == null && node.RightChild == null) { ...
Read MoreRemove all elements from a SortedList in C#
To remove all elements from a SortedList in C#, you use the Clear() method. This method removes all key-value pairs from the SortedList and sets the Count property to zero. Syntax Following is the syntax for the Clear() method − sortedList.Clear(); Parameters The Clear() method does not take any parameters. Return Value The Clear() method does not return any value. It has a return type of void. SortedList.Clear() Operation Before Clear() {A:1, B:2, C:3} Count = 3 ...
Read MoreCopying BitArray elements to an Array in C#
The BitArray class in C# provides the CopyTo() method to copy its elements to a compatible one-dimensional array. This method is useful when you need to transfer bit values from a BitArray to a regular array for further processing or storage. Syntax Following is the syntax for copying BitArray elements to an array − bitArray.CopyTo(array, arrayIndex); Parameters array − The target one-dimensional array to copy elements to. Must be compatible with BitArray elements (bool[], int[], or byte[]). arrayIndex − The zero-based index in the target array at which copying begins. ...
Read More