Skip to content

Instantly share code, notes, and snippets.

View rupalbarman's full-sized avatar

Rupal Barman rupalbarman

View GitHub Profile
@rupalbarman
rupalbarman / bin_packing_nextfit_simple.py
Created March 27, 2017 14:03
Simple Bin Packing Algorithm code which uses Next-fit technique
# bin packing algo (estimation)
# since it is Np- Hard
# for better methods (first fit and best fit) use self balancing trees
# this one is Next fit
def bins_needed(item_weights, bin_capacity):
remain= bin_capacity
bins=0
for i in item_weights:
if i> bin_capacity:
@rupalbarman
rupalbarman / subset_having_sum.py
Created March 26, 2017 15:05
get subsets of two elements from a list/ array whose sum is given
def get_pair_with_sum(a, need):
s= set()
for i in a:
if (need- i) in s:
print(need-i, i)
else:
s.add(i)
a=[4,2,4,2]
b=[3,6,2,5]
@rupalbarman
rupalbarman / adjacencyMat_to_List.py
Created March 19, 2017 03:19
Utility to convert adjacency matrix into adjacency list in python, for efficient BFS and DFS maybe
# get adjancy matrix
n= int(input()) #number of vertices
am=[]
for i in range(n):
am.append([int(x) for x in input().split()])
print(am) #show matrix
print()
#conver to adjancy list
@rupalbarman
rupalbarman / bst.go
Last active February 25, 2017 13:51
Binary Search Tree golang
/*
Binary Search Tree GoLang
Rupal barman
[email protected]
*/
package main
import (
"fmt"
@rupalbarman
rupalbarman / bst.py
Last active February 25, 2017 13:28
Binary Search Tree in Python
'''
Binary Searc Tree Simple
Rupal Barman
[email protected]
This is a demonstration of implementing BST in python.
Since, it's basic. Feel free to add in more features.
'''
class Node(object):
@rupalbarman
rupalbarman / InterCodeGen.cpp
Created December 9, 2016 03:13
Intermediate code generator ( Three address code) simple
//SIMPLE INTERMEDIATE CODE GENERATOR (3 ADDRESS CODE)
//Author: Rupal Barman
//Modified: 5/11/16
// Does not consider the operator precedence, ie. generates the 3 address code from left to right directly.
// INPUT example: t = q * p + g ; (don't forget to end the statement with a ';' or any character, even a space would work)
// OUTPUT example: v=r*j; w=v+h
#include <iostream>
#include <stdio.h>
#include <string.h>
@rupalbarman
rupalbarman / rotateArrXor.c
Last active April 9, 2021 17:19
Rotate an Array using XOR operations
/* The code allows rotation of an 1D array (right and left)
using XOR operator
ie. Shifts elements of an Array to left or right directions,
wraps the elements circularly.
*/
#include <stdio.h>
int arr[]={1,2,3,4,5,6,7,8,9,10};