Skip to content

Instantly share code, notes, and snippets.

@Heisenbergcodin
Heisenbergcodin / gist:45e6ac74ef7bfa913c10f9d718ca68da
Created December 4, 2023 14:36
Kth smallest number in n elements with qiuck SOrting
#include <stdio.h>
#include <stdlib.h>
// Function to partition the array and return the index of the pivot
int partition(int arr[], int low, int high)
{
int pivot = arr[high];
int i = low - 1;
for (int j = low; j < high; j++)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define a structure to represent a node in the Huffman tree
struct Node
{
char data;
int freq;
struct Node* left;
struct Node* right;
#include <stdio.h>
#include <stdlib.h>
// Structure to represent an edge in the graph
struct Edge
{
int src, dest, weight;
};
// Structure to represent a subset for union-find
#include <stdio.h>
int modexp(int a, int b, int N)
{
if (b == 0)
{
return 1;
}
int z = modexp(a, b / 2, N);
@Heisenbergcodin
Heisenbergcodin / gist:cc11760dcf5930d7b6ba077807bf013e
Created December 4, 2023 14:31
Starseens Multiplication for 2 by 2 Matrix
#include <stdio.h>
// Function to multiply two 2x2 matrices using Strassen's algorithm
void strassen_multiply(int A[2][2], int B[2][2], int C[2][2]) {
int M1, M2, M3, M4, M5, M6, M7;
M1 = (A[0][0] + A[1][1]) * (B[0][0] + B[1][1]);
M2 = (A[1][0] + A[1][1]) * B[0][0];
M3 = A[0][0] * (B[0][1] - B[1][1]);
M4 = A[1][1] * (B[1][0] - B[0][0]);
@Heisenbergcodin
Heisenbergcodin / gist:60c2d5a3bda4a4b6145f6c1defd5c5a3
Created December 4, 2023 14:30
Closest points and distance in 2d/x-y plane
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
struct Point
{
int x, y;
};
@Heisenbergcodin
Heisenbergcodin / gist:b2cd7f924c8832e7ef07e516e1bc3f23
Created December 4, 2023 14:29
Divide and Conquer multiplication of 2 NUmbers
#include <stdio.h>
#include <math.h>
// Function to multiply two numbers using divide and conquer
int multiply(int x, int y) {
// Base case: if either x or y is a single digit
if (x < 10 || y < 10) {
return x * y;
}
@Heisenbergcodin
Heisenbergcodin / gist:47522119783fa377d16e7f00f1935ef3
Created December 4, 2023 14:28
Extended Euclid Algo for GCD
#include <stdio.h>
int gcd(int x,int y)
{
if(y==0)
{
return x;
}
return gcd(y,x%y);
#include <stdio.h>
int modexp(int x,int y,int N)
{
if(y==0)
{
return 1;
}
int z=modexp(x,y/2,N);
@Heisenbergcodin
Heisenbergcodin / gist:2d893e201ff8f1b95850b5048cd90fc6
Created December 4, 2023 14:27
Multiplication algo using incremental tech return Modular
#include <stdio.h>
int multiply(int x, int y)
{
if (y == 0)
{
return 0;
}
int z = multiply(x, y / 2);