Skip to content

Instantly share code, notes, and snippets.

class Item:
def __init__(self, id, weight, profit):
self.id = id
self.weight = weight
self.profit = profit
def binaryKnapsack(knapsackMaxWeight, items):
"""
@jwickett
jwickett / LCS.py
Created January 2, 2010 10:12
Dynamic programming algorithm using memoization to solve for the Longest Common Subsequence (LCS) written in Python
def computeLCS(master, subseq):
"""
Wrapper method to compute the Longest Common Subsequence in an inputed master string given an inputed proposed subsequence string.
Note that the length of the 'subseq' string parameter must be less than or equal to the length of the 'master' string parameter.
This dynamic programming algorithm runs in O(n^2) time where n is the length of the 'master' string parameter.
The total space required is O(n^2) due to the memoization step.
"""
memoized = LCSLength(master, subseq)
@jwickett
jwickett / Multi-Threaded_Web_Crawler.py
Created December 22, 2009 06:32
A multi-threaded Web crawler implemented in Python
import threading, urllib, urlparse
from HTMLParser import HTMLParser
import sys
class LinkHTMLParser(HTMLParser):
A_TAG = "a"
HREF_ATTRIBUTE = "href"
def __init__(self):
self.links = []