Server Side Programming Articles

Page 956 of 2109

A Puzzle using C Program

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

Here we will see one C puzzle question. Suppose we have two numbers 48 and 96. We have to add the first number after the second one. So final result will be like 9648. But we cannot use any logical, arithmetic, string related operations, also cannot use any pre-defined functions. So how can we do that? This is easy. We can do by using Token Pasting operator (##) in C. The Token Pasting operator is a preprocessor operator. It sends commands to compiler to add or concatenate two tokens into one string. We use this operator at the macro ...

Read More

3-Way QuickSort (Dutch National Flag)

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 2K+ Views

The 3-Way QuickSort, also known as the Dutch National Flag algorithm, is an optimized version of the standard QuickSort algorithm. While traditional QuickSort partitions the array into two parts (less than and greater than pivot), 3-Way QuickSort creates three partitions: elements less than pivot, equal to pivot, and greater than pivot. Syntax void partition(int arr[], int left, int right, int *i, int *j); void quicksort3Way(int arr[], int left, int right); Algorithm The partition function divides the array into three sections − partition(arr, left, right, i, j): if right - left

Read More

A Space Optimized Solution of LCS in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 297 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 392 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 467 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 235 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 321 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 718 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 895 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 399 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
Showing 9551–9560 of 21,090 articles
« Prev 1 954 955 956 957 958 2109 Next »
Advertisements