Programming Articles

Page 975 of 2547

A Space Optimized Solution of LCS in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 299 Views

Here we will see one space optimized approach for LCS problem. The LCS is the longest common subsequence. If two strings are "BHHUBC" and "HYUYBZC", then the length of the subsequence is 4. One dynamic programming approach is already there, but using the dynamic programming approach, it will take more space. We need table of order m x n, where m is the number of characters in first string, and n is the number of characters in the second string. Here we will see how to implement this algorithm using O(n) amount of auxiliary space. If we observe the ...

Read More

A Peterson Graph Problem in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 395 Views

The Peterson Graph is a specific undirected graph with 10 vertices and 15 edges. In this problem, we need to find a walk through the Peterson Graph that realizes a given string pattern. Each vertex is labeled with a letter (A-E), and we must find a path where the sequence of vertex labels matches our target string. ...

Read More

A C/C++ Pointer Puzzle?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 470 Views

This C programming puzzle demonstrates how pointer arithmetic works with different types of pointers and multi-dimensional arrays. Understanding pointer sizes and type differences is crucial for mastering pointer arithmetic in C. Syntax sizeof(pointer_variable) (char*)(pointer + 1) - (char*)pointer Example: Pointer Arithmetic Puzzle Let's analyze this step-by-step with a complete C program that demonstrates pointer arithmetic with various pointer types − #include int main() { int a[4][5][6]; int x = 0; int* a1 = &x; ...

Read More

3-digit Osiris number C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 244 Views

An Osiris number is a special 3-digit number that equals the sum of all permutations of its 2-digit sub-samples. For example, 132 is an Osiris number because 12 + 21 + 13 + 31 + 23 + 32 = 132. Syntax bool isOsirisNumber(int n); Algorithm The approach is straightforward. For a 3-digit number, each digit appears exactly twice in the permutations − once in the tens position and once in the ones position. Therefore, we can check if the number equals 22 times the sum of its digits. Begin ...

Read More

Add all greater values to every node in a given BST?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 329 Views

In this problem, we need to modify each node in a Binary Search Tree (BST) by adding the sum of all greater node values to the current node's value. This transforms the BST while maintaining its structure but changing the node values. Syntax void addGreaterValues(struct Node* root, int* sum); Problem Statement Given a Binary Search Tree, we need to add to each node the sum of all node values that are greater than the current node value. Input BST 10 5 ...

Read More

Add 1 to a number represented as a linked list?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 725 Views

The linked list representation of a number stores each digit in a separate node, where the first node contains the most significant digit and the last node contains the least significant digit. For example, the number 202345 is represented as (2→0→2→3→4→5). To add 1 to this linked list represented number, we need to handle carry propagation from the least significant digit. If the last digit is less than 9, we simply increment it. Otherwise, we propagate the carry to the next digits. Syntax struct Node* addOne(struct Node* head); Algorithm The algorithm follows these ...

Read More

A Number Link Game?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 906 Views

Number Link is a logic puzzle where players must connect matching numbers on a grid using continuous paths. The paths cannot cross or branch, and each number must be at the endpoint of exactly one path. This implementation generates a random Number Link puzzle and its solution using a union-find data structure. Syntax struct _node { struct _node *parent; int rank; int path_number; int endpoint; }; Algorithm Overview The algorithm works by generating random paths first, then creating ...

Read More

C program to calculate the value of nPr?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 409 Views

Permutations, nPr can also be represented as P(n, r), is a mathematical formula to find the number of ways to arrange r objects from n objects where order matters. The formula of P(n, r) is n! / (n − r)!. The number of permutations on a set of n elements is given by n! where "!" represents factorial. Syntax nPr = n! / (n - r)! Where: n is the total number of objects r is the number of objects to be selected ! denotes factorial Example Let's calculate P(5, ...

Read More

C program to Find the Largest Number Among Three Numbers

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 926 Views

This program takes three numbers and finds the largest among them. We will use conditional statements to compare the numbers and determine which one has the maximum value. Syntax if (condition1) { if (condition2) { // statements } else { // statements } } else { if (condition3) { // statements } else ...

Read More

C Program for the compound interest?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 332 Views

Compound interest is the interest calculated on both the principal amount and the previously earned interest. Unlike simple interest, compound interest grows exponentially because the interest earned in each period is added to the principal for the next calculation period. Syntax Compound Interest = Principal * pow((1 + Rate/100), Time) - Principal Amount = Principal * pow((1 + Rate/100), Time) Example: Calculate Compound Interest Here's a complete C program to calculate compound interest using the mathematical formula − #include #include int main() { float principal, ...

Read More
Showing 9741–9750 of 25,466 articles
« Prev 1 973 974 975 976 977 2547 Next »
Advertisements