Instantly share code, notes, and snippets.

# Vik Paruchuri VikParuchuri

Created October 13, 2023 16:19
Sample textbooks

# 1. Algorithm Design and Analysis

One important aspect of algorithm design is problem-solving strategies. This involves breaking down a complex problem into smaller, more manageable subproblems. By solving these subproblems, we can then combine their solutions to solve the original problem. This approach is known as the divide-and-conquer method.

Another important aspect of algorithm design is understanding the time and space complexity of an algorithm. Time complexity refers to the amount of time an algorithm takes to run, while space complexity refers to the amount of memory an algorithm requires. By analyzing the time and space complexity of an algorithm, we can determine its efficiency and scalability.

For example, let's consider the problem of finding the largest number in a list. One possible algorithm is to iterate through the list and keep track of the largest number encountered so far. This algorithm has a time complexity of O(n), where n is the size of the list. This means that the algorithm's

Created August 29, 2023 19:42
This file contains 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 code_filter(code): """ Filters out low quality training code, with an aim to improving benchmark performance. Works best with Python. """ # Python keywords keywords = ["assert", "async", "await", "break", "class", "continue", "def", "del", "elif", "else", "except", "finally", "for", "from", "global", "if", "import", "in", "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return", "try", "while", "with", "yield"] # This covers single line comments in python + other common languages comment_symbols = ["#", "//"]
Last active August 29, 2015 14:22
Sample ipython notebook to test rescaling
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Created February 23, 2015 14:52
Convert fields to markdown
This file contains 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
 import os import re import yaml import textwrap import html2text def write_to_yaml(k, v, yaml_data): if isinstance(v, str): v = v.strip() if v.count("\n") == 0 and k not in ["left_text", "initial_display", "hint", "answer", "check_val", "imports", "instructions"]:
Last active August 29, 2015 14:12
This file contains 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
 * Install brew packages (brew-packages.txt) * Setup all packages that need it so that they start at startup * Install pip (easy_install pip) * Install virtualenvwrapper (pip install virtualenvwrapper) * export WORKON_HOME=~/Envs * mkdir -p \$WORKON_HOME * source /usr/local/bin/virtualenvwrapper.sh * mkvirtualenv turfly * export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future"; psql -d postgres
Created December 13, 2013 17:17
This file contains 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
 from queue.models import Submission import queue subs = Submission.objects.filter(queue_name="open-ended", retired=False) queue_name="open-ended" for sub in subs: qitem=str(sub.id) qcount = queue.producer.push_to_queue(queue_name, qitem)
Created October 15, 2013 20:45
Implement the textrank algorithm in Python.
This file contains 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
 import networkx as nx from nltk.tokenize.punkt import PunktSentenceTokenizer from sklearn.feature_extraction.text import TfidfTransformer, CountVectorizer SENTENCES_IN_SUMMARY = 10 MIN_SENTENCE_LENGTH = 50 MAX_SENTENCE_LENGTH = 200 def f7(seq): seen = set()
Last active December 19, 2015 17:58
This file contains 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
 from copy import deepcopy def invert(X): """ Invert a matrix X according to gauss-jordan elimination In gauss-jordan elimination, we perform basic row operations to turn a matrix into row-echelon form. If we concatenate an identity matrix to our input matrix during this process, we will turn the identity matrix into our inverse. X - input list of lists where each list is a matrix row output - inverse of X """
Created October 2, 2012 16:21
New QuerySignatureV1AuthHandler
This file contains 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
 class QuerySignatureV1AuthHandler(QuerySignatureHelper, AuthHandler): """ Provides Query Signature V1 Authentication. """ SignatureVersion = 1 capability = ['sign-v1', 'mturk'] def _calc_signature(self, params, *args):
Created October 2, 2012 16:18
Old QuerySignatureV1Handler
This file contains 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
 class QuerySignatureV1AuthHandler(QuerySignatureHelper, AuthHandler): """ Provides Query Signature V1 Authentication. """ SignatureVersion = 1 capability = ['sign-v1', 'mturk'] def _calc_signature(self, params, *args): boto.log.debug('using _calc_signature_1')