Server Side Programming Articles

Page 952 of 2109

Print leftmost and rightmost nodes of a Binary Tree in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 1K+ Views

In C, printing the leftmost and rightmost nodes of a binary tree involves traversing the tree level by level and capturing the first and last nodes at each level. This technique uses level-order traversal (BFS) to identify boundary nodes. Syntax struct node { int data; struct node* left; struct node* right; }; void printBoundaryNodes(struct node* root); Algorithm The approach uses a queue-based level-order traversal − Process each level completely before moving to the next For each level, store the ...

Read More

Print maximum sum square sub-matrix of given size in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 719 Views

Given a matrix of NxN, find a sub-matrix of MxM where M=1 such that the sum of all elements in the MxM matrix is maximum. The input matrix can contain zero, positive and negative integer values. Finding Maximum Sum Sub-matrix Original 5x5 Matrix 1 1 1 1 ...

Read More

Print left rotation of array in O(n) time and O(1) space in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 233 Views

We are given an array of some size n and multiple integer values, we need to rotate an array from a given index k. Left rotation means moving elements to the left by k positions, where elements that go beyond the beginning wrap around to the end. We want to rotate an array from an index k like − Array Left Rotation by k=2 Original Array: 1 2 3 ...

Read More

Print k different sorted permutations of a given array in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 263 Views

Given an array containing N integers, the challenge is to print k different permutations of indices such that the values at those indices form a non-decreasing sequence. Print -1 if it is not possible. Syntax void findSortedPermutations(int arr[], int n, int k); Algorithm The approach works by sorting the array while keeping track of original indices. If any two consecutive elements are equal, they can be swapped to generate different permutations − Create pairs of (value, original_index) for each array element Sort the pairs by value to get the first permutation Count ...

Read More

Print index of columns sorted by count of zeroes in the Given Matrix in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 197 Views

Given a matrix of size NxM where N is the number of rows and M is the number of columns, we need to print the column indices sorted by the count of zeros in each column. This means we first count zeros in each column, then sort the columns based on these counts, and finally print the column indices (1-based indexing). For example, if column 1 contains 1 zero, column 2 contains 0 zeros, and column 3 contains 2 zeros, the result should be − 2 1 3 (sorted by zero count: 0, 1, 2). Syntax ...

Read More

Print the corner elements and their sum in a 2-D matrix in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 3K+ Views

Given a 2D matrix, the challenge is to find and print the corner elements along with their sum. In a matrix, corner elements are located at the four corners: top-left, top-right, bottom-left, and bottom-right positions. For a matrix mat[r][c] with rows from 0 to r-1 and columns from 0 to c-1, the corner elements are: mat[0][0], mat[0][c-1], mat[r-1][0], and mat[r-1][c-1]. The task is to extract these corner elements and calculate their sum. Syntax // Corner elements of a matrix mat[r][c] mat[0][0] // Top-left corner mat[0][c-1] ...

Read More

Print the balanced bracket expression using given brackets in C Program

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 434 Views

Given four variables a, b, c, d with predefined values that represent different types of bracket pairs. The task is to use all the given brackets and print a balanced bracket expression using these bracket types. Where variables represent − a for (( b for () c for )( d for )) If we cannot form a balanced bracket expression then print "can't be formed". In case of multiple valid answers, we can print any of them. Syntax void print(int a, int b, int c, int d); Algorithm To ...

Read More

Print the last occurrence of elements in array in relative order in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 393 Views

Given an array with elements and the task is to print the last occurrences of the given elements in the list. Here we not only have to remove the duplicate elements but also we have to maintain the order of the occurrences of the elements in an array as per the last time they have occurred. For example, if we have an array of 6 elements containing some duplicate values i.e., {1, 3, 2, 3, 1, 2}, the result should be in the form of 3 1 2. Syntax void printLastOccurrence(int arr[], int n); ...

Read More

Print reverse of a Linked List without extra space and modification in C Program.

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 549 Views

The task is to print the nodes of a linked list in reverse order without using extra space and without modifying the original linked list. This approach maintains O(1) space complexity by counting nodes and accessing them by position rather than using recursion or additional data structures. 10 21 33 42 89 ...

Read More

Binary Search using pthread in C Program?

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

Binary search is one of the most efficient searching algorithms for sorted arrays. It works by repeatedly dividing the search space in half. In this article, we'll explore how to implement binary search using multiple threads (pthread) in C to potentially improve performance by parallelizing the search across different segments of the array. Syntax #include int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); int pthread_join(pthread_t thread, void **retval); Example: Multithreaded Binary ...

Read More
Showing 9511–9520 of 21,090 articles
« Prev 1 950 951 952 953 954 2109 Next »
Advertisements