Skip to content

Instantly share code, notes, and snippets.

View jitsceait's full-sized avatar

Sangar Jitendra jitsceait

View GitHub Profile
@jitsceait
jitsceait / poss_path_dynamic.c
Created May 4, 2014 03:51
This program implements dynamic approach to find all possible paths.
#include<stdlib.h>
#include<stdio.h>
int PossiblePaths(int m,int n){
int Table[m][n];
int i,j;
for(i=0;i<=m; i++){
Table[i][0] =1;
@jitsceait
jitsceait / poss_path_optimized.c
Created May 4, 2014 03:53
This program implements optimized version of dynamic programming approach for all possible path problem
int PossiblePaths(int m,int n){
int Table[n];
int diagonal_sum =0;
int i,j;
for(i=0;i<=n; i++){
Table[i] =1;
}
@jitsceait
jitsceait / zero_sum.c
Created May 4, 2014 03:59
This post provides implementation for zero sum sub array problem.
#include<stdio.h>
#include<stdlib.h>
#include <math.h>
void zero_subarray(int a[], int n){
int i, j;
int T[n];
T[0] = a[0];
for(i= 1; i<n; i++){
@jitsceait
jitsceait / sliding_window.c
Last active August 29, 2015 14:00
This code provides implementation of sliding window problem
#include<stdio.h>
#include<stdlib.h>
#include <math.h>
/* This function heapifies heap after removal of root
or at time of building heap from an array */
void max_heapify_ptr(heap_node * a[], int i, int len){
int largest =i;
int left, right;
Current window : 1 4 5 6 3
4 Minimum elements in current window : 5 4 3 1
Current window : 4 5 6 3 2
4 Minimum elements in current window : 5 3 4 2
Current window : 5 6 3 2 4
@jitsceait
jitsceait / balanced_partition.c
Last active August 29, 2015 14:00
This code implementation of dynamic programming concept for balance partitioning problem.
#include <stdio.h>
#include <stdlib.h>
int balancePartition(int set[], int n)
{
/*The value of subset[i][j] will be true if there is a subset
of set[0..j-1] with sum equal to i */
int i,j;
int sum =0;
@jitsceait
jitsceait / zigzagRec.c
Last active August 29, 2015 14:00
This program prints tree in zig zag fashion
void printTreeLevel_iter1(Node *root){
int h = height(root);
int i;
int ltr = 1;
for(i =1; i<=h; i++){
printf("\n Level %d :", i);
/* initially passing it to left to right */
zigzagRec(root, i, ltr);
/* For next iteration (level), it will be reversed */
ltr = !ltr;
@jitsceait
jitsceait / zigzag_iter.c
Created May 4, 2014 05:32
This program prints tree in zig zag fashion
void zigzag(Node * root){
stack s1, s2;
s1.top = -1;
s2.top = -1;
if(root == NULL ) return;
push(&s1, root);
while(!is_empty(s1) || !is_empty(s2)){
printf("\n");
@jitsceait
jitsceait / driver.c
Last active August 29, 2015 14:00
This is driver program for tree related questions
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct node{
int value;
struct node *left;
struct node *right;
};
typedef struct node Node;
@jitsceait
jitsceait / trie_init.c
Created May 4, 2014 05:54
Trie initialization
#define MAX_SIZE 26
#define GET_CHAR_INDEX(ch)\
((int) ch - (int)'a' )
#define LEAF_NODE 1
#define true 1
#define false 0
typedef struct trie_node_t {