This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Binary Search Tree GoLang | |
| Rupal barman | |
| [email protected] | |
| */ | |
| package main | |
| import ( | |
| "fmt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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}; |
NewerOlder