sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 12 of 98

C / C++ Program for Subset Sum (Backtracking)

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 12K+ Views

Backtracking is a technique to solve dynamic programming problems. It works by going step by step and rejects those paths that do not lead to a solution and trackback (moves back) to the previous position. In the subset sum problem, we have to find the subset of a set such that the elements of this subset sum up to a given number K. All the elements of the set are positive and unique (no duplicate elements are present). Syntax void subset_sum(int s[], int t[], int s_size, int t_size, int sum, int index, int target_sum); ...

Read More

C Program for Naive algorithm for Pattern Searching

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 8K+ Views

Pattern matching in C is the process of finding if a string (pattern) is present within another string (text). For example, the string "algorithm" is present within the string "naive algorithm". If found, its location (starting position) is displayed. The Naive algorithm is a simple brute-force approach that checks every possible position in the text. Syntax void naivePatternSearch(char text[], char pattern[]); Algorithm The Naive Pattern Searching algorithm works as follows − naive_algorithm(pattern, text) Input − The text and the pattern Output − locations where the pattern is present in the text ...

Read More

C Program for Minimum number of jumps to reach the end

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

The minimum jumps problem involves finding the minimum number of jumps needed to reach the last index of an array from the first index. Each element in the array represents the maximum number of steps that can be taken forward from that position. Syntax int minJumps(int arr[], int n); Algorithm The naive approach starts from the first element and recursively calculates the minimum jumps needed − minJumps(start, end) = Min(minJumps(k, end)) for all k accessible from start We use dynamic programming with bottom-up approach. For each position, we check all ...

Read More

C Program for Minimum Cost Path

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

The minimum cost path problem involves finding the path from the top-left corner to the bottom-right corner of a 2D matrix with minimum total cost. You can only move right or down from any given cell. Dynamic programming provides an efficient solution to this problem. Syntax int minCostPath(int cost[][COLS], int m, int n); Problem Approach The solution uses dynamic programming to build a table where each cell contains the minimum cost to reach that position from the starting point (0, 0). The formula for any cell (i, j) is − dp[i][j] = ...

Read More

C Program Coin Change

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 4K+ Views

In this problem, we are given a value n, and we want to make change of n rupees using a given set of coin denominations. We need to return the total number of ways to make the sum using these coins. Syntax int coinChange(int coins[], int numCoins, int amount); Example Input/Output Input: N = 6, coins = {1, 2, 4} Output: 6 Explanation: The total combinations that make the sum of 6 are: {1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 2}, {1, 1, 2, 2}, {1, 1, 4}, {2, 2, ...

Read More

C / C++ Program for Dijkstra\'s shortest path algorithm

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 27K+ Views

Dijkstra's algorithm is a greedy algorithm used to find the shortest path from a source vertex to all other vertices in a weighted graph. It works by maintaining a set of vertices whose shortest distance from the source has been determined and gradually expanding this set until all vertices are included. Syntax void dijkstra(int graph[V][V], int source); Algorithm Steps Step 1: Create a set to store vertices included in shortest path tree Step 2: Initialize all distances as INFINITE and source distance as 0 Step 3: Loop until all vertices are processed: ...

Read More

Binary to Gray code using recursion in C program

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 2K+ Views

A Binary number is a number that has only two bits 0 and 1. Gray code is a special type of binary number that has a property that two successive numbers of the code cannot differ by more than one bit. This property of gray code makes it useful in K-maps, error correction, communication, etc. This makes the conversion of binary to gray code necessary. So, let's see an algorithm to convert binary to gray code using recursion. Syntax int binaryToGray(int binary); Algorithm Step 1: For input n: Step ...

Read More

Binary Search for Rational Numbers without using floating point arithmetic in C program

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

In this problem, we are given a sorted array of rational numbers and we have to search the given element using binary search algorithm without using floating point arithmetic. A Rational number is a number represented in the form p/q where both p and q are integers. For example, 2/3, 1/5. Binary search is a searching technique that works by finding the middle of the array and comparing elements to determine which half contains the target. For finding the element using binary search from a sorted array of rational numbers, where floating point arithmetic is not allowed, ...

Read More

C program to delete a file

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 3K+ Views

In programming, working with files is very important and every programming language has its own set of functions or library that help in manipulation of files. In C Programming Language, the remove() function can be used by the programmer to delete a file. Syntax int remove(const char *filename); Parameters The function accepts one parameter which is the name of the file that is to be deleted. File name can also be the path to the file but only if the system supports it. filename − A string containing the name of the ...

Read More

Bash program to check if the Number is a Prime or not

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 19K+ Views

A prime number is a natural number greater than 1 that has exactly two factors: 1 and itself. Examples include 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, etc. In this article, we'll write a C program to check if a given number is prime or not. Syntax for (i = 2; i

Read More
Showing 111–120 of 975 articles
« Prev 1 10 11 12 13 14 98 Next »
Advertisements