Found 7197 Articles for C++

C++ Program to Sort an Array of 10 Elements Using Heap Sort Algorithm

Arjun Thakur
Updated on 12-Feb-2020 07:17:15

3K+ Views

Heap Sort is based on the binary heap data structure. In the binary heap the child nodes of a parent node are smaller than or equal to it in the case of a max heap, and the child nodes of a parent node are greater than or equal to it in the case of a min heap.An example that explains all the steps in Heap Sort is as follows.The original array with 10 elements before sorting is −207154101590237725This array is built into a binary max heap using max-heapify. This max heap represented as an array is given as follows.907720542515123710The root ... Read More

C++ Program to Perform Postorder Recursive Traversal of a Given Binary Tree

Nishu Kumari
Updated on 16-May-2025 18:37:48

5K+ Views

A binary tree is a tree data structure where each node has zero, one, or two children. Even an empty tree is called a valid binary tree. Our goal is to write a C++ program to perform postorder recursive traversal on a given binary tree. Traversal means visiting all the nodes in a tree exactly once. In postorder traversal, we visit the left child (left subtree) first, then the right child (right subtree), and finally the root node. Let's take a small binary tree and look at an example. Here, we first ... Read More

C++ Program to Perform Inorder Recursive Traversal of a Given Binary Tree

Nishu Kumari
Updated on 16-May-2025 19:12:45

15K+ Views

Tree traversal is a form of graph traversal. It involves checking or printing each node in the tree exactly once. The inorder traversal of a binary tree involves visiting each of the nodes in the tree in the order (Left, Root, Right). An example of Inorder traversal of a binary tree is as follows. Here, we start at the leftmost node(5), move up to 6, then to 2, then to root 3, and continue to the right side with 9 then 4 and 8. Using Recursion for Inorder Traversal Recursion is a technique where a function ... Read More

C++ Program to Perform Preorder Recursive Traversal of a Given Binary Tree

Nishu Kumari
Updated on 16-May-2025 19:13:22

8K+ Views

In this article, we'll show you how to write a C++ program to perform a preorder recursive traversal of a binary tree. A binary tree is a tree where each node has zero, one, or two children. Even an empty tree is called a valid binary tree. Traversal means visiting all the nodes in a tree exactly once. In preorder traversal, we visit the root first, then the left child, and finally the right child. Let's take a small binary tree and see an example: Here, we start at the root(3), then go to the left child (6), ... Read More

C++ Program to Check Multiplicability of Two Matrices

Nishu Kumari
Updated on 20-May-2025 20:10:38

386 Views

Two matrices are said to be multiplicable if they can be multiplied. This is only possible when the number of columns of the first matrix is equal to the number of rows of the second matrix. Our goal is to check whether the given matrices are multiplicable or not using C++. Let's understand this with an example: Number of rows in Matrix 1 = 3 Number of columns in Matrix 1 = 2 Number of rows in Matrix 2 = 2 Number of columns in Matrix 2 = 5 Matrix 1 and Matrix 2 are multiplicable because ... Read More

C++ Program to Compute Determinant of a Matrix

Nishu Kumari
Updated on 20-May-2025 20:11:00

11K+ Views

The determinant of a square matrix can be computed using its element values. The determinant of a matrix A can be denoted as det(A) and it can be called the scaling factor of the linear transformation described by the matrix in geometry. An example of the determinant of a matrix is as follows. The matrix is: 3 1 2 7 The determinant of the above matrix: = 7*3 - 2*1 = 21 - 2 = 19 So, the determinant is 19. Steps to Compute Determinant of a Matrix We find the determinant using a method called recursive Laplace ... Read More

C++ Program to Check if a Matrix is Invertible

Nishu Kumari
Updated on 30-May-2025 18:04:19

402 Views

A matrix is invertible if it has an inverse. An inverse of a matrix exists only when its determinant is non-zero. If the determinant of a matrix is zero, the matrix is called singular and cannot be inverted. In this article, we'll write a C++ program to check if a matrix is invertible using its determinant. To better understand this, let's take the following 3x3 matrix as an example: Given 3*3 Matrix: 4 2 1 2 1 1 9 3 2 To check if this matrix is invertible, we ... Read More

C++ Program to Multiply two Matrices by Passing Matrix to Function

Ankith Reddy
Updated on 24-Jun-2020 09:55:04

2K+ Views

A matrix is a rectangular array of numbers that is arranged in the form of rows and columns.An example of a matrix is as follows.A 3*4 matrix has 3 rows and 4 columns as shown below.8 6 3 5 7 1 9 2 5 1 9 8A program that multiplies two matrices by passing the matrices to functions is as follows.Example Live Demo#include using namespace std; void MatrixMultiplication(int a[2][3],int b[3][3]) {    int product[10][10], r1=2, c1=3, r2=3, c2=3, i, j, k;    if (c1 != r2) {       cout

C++ Program to Store and Display Information Using Structure

Nishu Kumari
Updated on 16-May-2025 19:14:01

8K+ Views

A structure is a collection of items of different data types. It is very useful in creating complex data structures with different data type records. A structure is defined with the struct keyword. In this article, we will store and display information of an employee using a structure. An example of a structure is as follows: struct employee { int empID; char name[50]; int salary; char department[50]; }; Store Information in Structure and Display It In this program, we store and display employee information using a ... Read More

C++ Program to Calculate Standard Deviation

Nishu Kumari
Updated on 21-May-2025 09:46:51

8K+ Views

Standard deviation is a measure of how spread out the numbers in a dataset are. It is the square root of the variance, where variance is the average of the squared differences from the mean. In this article, we will show you how to calculate the standard deviation in C++. Let's understand this with an example: Input: Numbers are 4, 8, 6, 5, 8 Calculating: Find the mean = (4 + 8 + 6 + 5 + 8) / 5 = 31 / 5 = 6.2 Subtract the mean and square the result: (4 - 6.2)^2 = ... Read More

Advertisements