├── .gitignore ├── .nojekyll ├── Code ├── Procfile ├── Simplified_Starter_Code │ ├── dictogram.py │ ├── listogram.py │ ├── markov.py │ ├── test_dictogram.py │ └── test_listogram.py ├── dictogram.py ├── dictogram_test.py ├── hashtable.py ├── hashtable_class_example.py ├── hashtable_test.py ├── linkedlist.py ├── linkedlist_test.py ├── listogram.py ├── listogram_test.py ├── requirements.txt └── runtime.txt ├── Lessons ├── AlgorithmAnalysis.md ├── Architecture.md ├── ArraysLinkedLists.md ├── FlaskWebApp.md ├── HW1.md ├── HW2.md ├── HW3.md ├── HashTables.md ├── Histograms.md ├── Images │ ├── buckets.png │ ├── chaining.png │ ├── flower.png │ ├── functionrecipe.png │ ├── hashfunction.png │ ├── hashtable.png │ ├── houseblueprint.jpeg │ ├── linearprobing.png │ ├── str_array.png │ └── suburbia.jpg ├── Lesson1.md ├── Lesson2.md ├── Lesson3.md ├── Lesson4.md ├── Lesson5.md ├── Lesson6.md ├── Lesson7.md ├── MarkovChains.md ├── Probability.md ├── Quiz1.md ├── Quiz2.md ├── RandomStrings.md ├── RegularExpressions.md ├── Sentences.md ├── graphproject.md ├── playlist.md └── word_freq.md ├── ReadMe.md ├── Reveal ├── README.md ├── favicon.ico └── makeschool.css ├── Setup.md ├── Slides ├── AlgorithmAnalysis.pdf ├── ArraysLinkedLists.pdf ├── HashTables.pdf ├── Images │ ├── buckets.png │ ├── chaining.png │ ├── flower.png │ ├── functionrecipe.png │ ├── hashfunction.png │ ├── hashtable.png │ ├── houseblueprint.jpeg │ ├── linearprobing.png │ ├── str_array.png │ └── suburbia.jpg ├── Lesson1.html ├── Lesson2.html ├── Lesson3.html ├── Lesson4.html ├── Lesson5.html ├── Lesson6.html ├── Lesson7.html ├── MarkovChains.pdf ├── Probability.pdf ├── RegularExpressions.pdf ├── TweetGenerator.pdf ├── assets │ └── Reveal │ │ └── makeschool.css ├── css │ ├── highlight │ │ └── zenburn.css │ ├── print │ │ ├── paper.css │ │ └── pdf.css │ ├── reset.css │ ├── reveal.css │ ├── reveal.scss │ └── theme │ │ ├── README.md │ │ ├── beige.css │ │ ├── black.css │ │ ├── blood.css │ │ ├── league.css │ │ ├── moon.css │ │ ├── night.css │ │ ├── serif.css │ │ ├── simple.css │ │ ├── sky.css │ │ ├── solarized.css │ │ ├── source │ │ ├── beige.scss │ │ ├── black.scss │ │ ├── blood.scss │ │ ├── league.scss │ │ ├── moon.scss │ │ ├── night.scss │ │ ├── serif.scss │ │ ├── simple.scss │ │ ├── sky.scss │ │ ├── solarized.scss │ │ └── white.scss │ │ ├── template │ │ ├── mixins.scss │ │ ├── settings.scss │ │ └── theme.scss │ │ └── white.css ├── index.html ├── js │ └── reveal.js └── plugin │ ├── highlight │ └── highlight.js │ ├── markdown │ ├── example.html │ ├── example.md │ ├── markdown.js │ └── marked.js │ ├── math │ └── math.js │ ├── multiplex │ ├── client.js │ ├── index.js │ ├── master.js │ └── package.json │ ├── notes-server │ ├── client.js │ ├── index.js │ └── notes.html │ ├── notes │ ├── notes.html │ └── notes.js │ ├── print-pdf │ └── print-pdf.js │ ├── search │ └── search.js │ └── zoom-js │ └── zoom.js ├── Web ├── .nojekyll ├── logo-icononly.svg ├── style.css └── sw.js ├── _navbar.md ├── _sidebar.md ├── index.html ├── reveal-md.json ├── reveal.json └── src ├── PlaylistLinkedList-StarterCode ├── Playlist.py ├── Song.py └── main.py ├── Queue.py ├── SearchAlgorithms.py ├── SortingAlgorithms.py ├── Stack.py └── linked-list ├── LinkedList.py ├── Node.py ├── main.py └── whole_linked_list.py /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/macos,python 3 | 4 | ### macOS ### 5 | *.DS_Store 6 | .AppleDouble 7 | .LSOverride 8 | 9 | # Icon must end with two \r 10 | Icon 11 | 12 | # Thumbnails 13 | ._* 14 | 15 | # Files that might appear in the root of a volume 16 | .DocumentRevisions-V100 17 | .fseventsd 18 | .Spotlight-V100 19 | .TemporaryItems 20 | .Trashes 21 | .VolumeIcon.icns 22 | .com.apple.timemachine.donotpresent 23 | 24 | # Directories potentially created on remote AFP share 25 | .AppleDB 26 | .AppleDesktop 27 | Network Trash Folder 28 | Temporary Items 29 | .apdisk 30 | 31 | ### Python ### 32 | # Byte-compiled / optimized / DLL files 33 | __pycache__/ 34 | *.py[cod] 35 | *$py.class 36 | 37 | # C extensions 38 | *.so 39 | 40 | # Distribution / packaging 41 | .Python 42 | build/ 43 | develop-eggs/ 44 | dist/ 45 | downloads/ 46 | eggs/ 47 | .eggs/ 48 | lib/ 49 | lib64/ 50 | parts/ 51 | sdist/ 52 | var/ 53 | wheels/ 54 | *.egg-info/ 55 | .installed.cfg 56 | *.egg 57 | 58 | # PyInstaller 59 | # Usually these files are written by a python script from a template 60 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 61 | *.manifest 62 | *.spec 63 | 64 | # Installer logs 65 | pip-log.txt 66 | pip-delete-this-directory.txt 67 | 68 | # Unit test / coverage reports 69 | htmlcov/ 70 | .tox/ 71 | .coverage 72 | .coverage.* 73 | .cache 74 | nosetests.xml 75 | coverage.xml 76 | *.cover 77 | .hypothesis/ 78 | 79 | # Translations 80 | *.mo 81 | *.pot 82 | 83 | # Django stuff: 84 | *.log 85 | local_settings.py 86 | 87 | # Flask stuff: 88 | instance/ 89 | .webassets-cache 90 | 91 | # Scrapy stuff: 92 | .scrapy 93 | 94 | # Sphinx documentation 95 | docs/_build/ 96 | 97 | # PyBuilder 98 | target/ 99 | 100 | # Jupyter Notebook 101 | .ipynb_checkpoints 102 | 103 | # pyenv 104 | .python-version 105 | 106 | # celery beat schedule file 107 | celerybeat-schedule 108 | 109 | # SageMath parsed files 110 | *.sage.py 111 | 112 | # Environments 113 | .env 114 | .venv 115 | env/ 116 | venv/ 117 | ENV/ 118 | env.bak/ 119 | venv.bak/ 120 | 121 | # Spyder project settings 122 | .spyderproject 123 | .spyproject 124 | 125 | # Rope project settings 126 | .ropeproject 127 | 128 | # mkdocs documentation 129 | /site 130 | 131 | # mypy 132 | .mypy_cache/ 133 | 134 | # End of https://www.gitignore.io/api/macos,python 135 | -------------------------------------------------------------------------------- /.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/.nojekyll -------------------------------------------------------------------------------- /Code/Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn app:app -------------------------------------------------------------------------------- /Code/Simplified_Starter_Code/dictogram.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | class Dictogram: 4 | 5 | def __init__(self, word_list): 6 | '''Initializes the dictogram properties''' 7 | 8 | self.word_list = word_list 9 | 10 | self.dictionary_histogram = self.build_dictogram() 11 | 12 | self.tokens = sum(self.dictionary_histogram.values()) 13 | self.types = self.unique_words() 14 | 15 | def build_dictogram(self): 16 | '''Creates a histogram dictionary using the word_list property and returns it''' 17 | 18 | #TODO: use your histogram function as a starting point to complete this method 19 | pass 20 | 21 | def frequency(self, word): 22 | '''returns the frequency or count of the given word in the dictionary histogram''' 23 | #TODO: use your frequency function as a starting point to complete this method 24 | pass 25 | 26 | def unique_words(self): 27 | '''returns the number of unique words in the dictionary histogram''' 28 | #TODO: use your unique words function as a starting point to complete this method 29 | pass 30 | 31 | def sample(self): 32 | '''Randomly samples from the dictionary histogram based on the frequency, returns a word''' 33 | 34 | #TODO: use your sample function as a starting point to complete this method 35 | pass 36 | 37 | def print_dictogram(word_list): 38 | '''Creates a dictionary based histogram (dictogram) and then prints out its properties and samples from it''' 39 | 40 | print() 41 | print('Dictionary Histogram:') 42 | print('word list: {}'.format(word_list)) 43 | # Create a dictogram and display its contents 44 | dictogram = Dictogram(word_list) 45 | print('dictogram: {}'.format(dictogram.dictionary_histogram)) 46 | print('{} tokens, {} types'.format(dictogram.tokens, dictogram.types)) 47 | for word in word_list[-2:]: 48 | freq = dictogram.frequency(word) 49 | print('{!r} occurs {} times'.format(word, freq)) 50 | print() 51 | print_dictogram_samples(dictogram) 52 | 53 | def print_dictogram_samples(dictogram): 54 | '''Compares sampled frequency to observed frequency''' 55 | 56 | print('Dictionary Histogram samples:') 57 | # Sample the histogram 10,000 times and count frequency of results 58 | samples_list = [dictogram.sample() for _ in range(10000)] 59 | samples_hist = Dictogram(samples_list) 60 | print('samples: {}'.format(samples_hist.dictionary_histogram)) 61 | print() 62 | print('Sampled frequency and error from observed frequency:') 63 | header = '| word type | observed freq | sampled freq | error |' 64 | divider = '-' * len(header) 65 | print(divider) 66 | print(header) 67 | print(divider) 68 | # Colors for error 69 | green = '\033[32m' 70 | yellow = '\033[33m' 71 | red = '\033[31m' 72 | reset = '\033[m' 73 | # Check each word in original histogram 74 | for word, count in dictogram.dictionary_histogram.items(): 75 | # Calculate word's observed frequency 76 | observed_freq = count / dictogram.tokens 77 | # Calculate word's sampled frequency 78 | samples = samples_hist.frequency(word) 79 | sampled_freq = samples / samples_hist.tokens 80 | # Calculate error between word's sampled and observed frequency 81 | error = (sampled_freq - observed_freq) / observed_freq 82 | color = green if abs(error) < 0.05 else yellow if abs(error) < 0.1 else red 83 | print('| {!r:<9} '.format(word) 84 | + '| {:>4} = {:>6.2%} '.format(count, observed_freq) 85 | + '| {:>4} = {:>6.2%} '.format(samples, sampled_freq) 86 | + '| {}{:>+7.2%}{} |'.format(color, error, reset)) 87 | print(divider) 88 | print() 89 | 90 | print_dictogram(['one', 'fish', 'two', 'fish', 'red', 'fish', 'blue', 'fish']) 91 | 92 | -------------------------------------------------------------------------------- /Code/Simplified_Starter_Code/listogram.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | class Listogram: 4 | 5 | def __init__(self, word_list): 6 | '''Initializes the listogram properties''' 7 | 8 | self.word_list = word_list 9 | 10 | self.list_histogram = self.build_listogram() 11 | 12 | self.tokens = self.get_num_tokens() 13 | self.types = self.unique_words() 14 | 15 | def build_listogram(self): 16 | '''Creates a histogram list of lists using the word_list property and returns it''' 17 | 18 | #TODO: use your listogram function as a starting point to complete this method 19 | pass 20 | 21 | def get_num_tokens(self): 22 | '''gets the number of tokens in the listogram''' 23 | 24 | tokens = 0 25 | for item in self.list_histogram: 26 | tokens += item[1] 27 | return tokens 28 | 29 | def get_index(self, word, list_histogram): 30 | '''searches in the list histogram parameter and returns the index of the inner list that contains the word if present''' 31 | #TODO: use your get_index function as a starting point to complete this method 32 | pass 33 | 34 | def frequency(self, word): 35 | '''returns the frequency or count of the given word in the list of lists histogram''' 36 | #TODO: use your frequency and get_index function as a starting point to complete this method 37 | #You will need to adapt it a little bit to work with listogram 38 | pass 39 | 40 | def unique_words(self): 41 | '''returns the number of unique words in the list of lists histogram''' 42 | #TODO: use your unique words function as a starting point to complete this method 43 | #You will need to adapt it a little bit to work with listogram 44 | pass 45 | 46 | 47 | def sample(self): 48 | '''Randomly samples from the list of list histogram based on the frequency, returns a word''' 49 | 50 | #TODO: use your sample function as a starting point to complete this method 51 | #You will need to adapt it a little bit to work with listogram 52 | 53 | def print_listogram(word_list): 54 | '''Creates a list based histogram (listogram) and then prints out its properties and samples from it''' 55 | 56 | print() 57 | print('List of Lists Histogram:') 58 | print('word list: {}'.format(word_list)) 59 | # Create a dictogram and display its contents 60 | listogram = Listogram(word_list) 61 | print('listogram: {}'.format(listogram.list_histogram)) 62 | print('{} tokens, {} types'.format(listogram.tokens, listogram.types)) 63 | for word in word_list[-2:]: 64 | freq = listogram.frequency(word) 65 | print('{!r} occurs {} times'.format(word, freq)) 66 | print() 67 | print_dictogram_samples(listogram) 68 | 69 | def print_dictogram_samples(listogram): 70 | '''Compares sampled frequency to observed frequency''' 71 | 72 | print('List of Lists Histogram samples:') 73 | # Sample the histogram 10,000 times and count frequency of results 74 | samples_list = [listogram.sample() for _ in range(10000)] 75 | samples_hist = Listogram(samples_list) 76 | print('samples: {}'.format(samples_hist.list_histogram)) 77 | print() 78 | print('Sampled frequency and error from observed frequency:') 79 | header = '| word type | observed freq | sampled freq | error |' 80 | divider = '-' * len(header) 81 | print(divider) 82 | print(header) 83 | print(divider) 84 | # Colors for error 85 | green = '\033[32m' 86 | yellow = '\033[33m' 87 | red = '\033[31m' 88 | reset = '\033[m' 89 | # Check each word in original histogram 90 | for item in listogram.list_histogram: 91 | word = item[0] 92 | count = item[1] 93 | # Calculate word's observed frequency 94 | observed_freq = count / listogram.tokens 95 | # Calculate word's sampled frequency 96 | samples = samples_hist.frequency(word) 97 | sampled_freq = samples / samples_hist.tokens 98 | # Calculate error between word's sampled and observed frequency 99 | error = (sampled_freq - observed_freq) / observed_freq 100 | color = green if abs(error) < 0.05 else yellow if abs(error) < 0.1 else red 101 | print('| {!r:<9} '.format(word) 102 | + '| {:>4} = {:>6.2%} '.format(count, observed_freq) 103 | + '| {:>4} = {:>6.2%} '.format(samples, sampled_freq) 104 | + '| {}{:>+7.2%}{} |'.format(color, error, reset)) 105 | print(divider) 106 | print() 107 | 108 | print_listogram(['one', 'fish', 'two', 'fish', 'red', 'fish', 'blue', 'fish']) 109 | 110 | -------------------------------------------------------------------------------- /Code/Simplified_Starter_Code/markov.py: -------------------------------------------------------------------------------- 1 | from dictogram import Dictogram 2 | 3 | class MarkovChain: 4 | 5 | def __init__(self, word_list): 6 | 7 | 8 | #The Markov chain will be a dictionary of dictionaries 9 | #Example: for "one fish two fish red fish blue fish" 10 | #{"one": {fish:1}, "fish": {"two":1, "red":1, "blue":1}, "two": {"fish":1}, "red": {"fish":1}, "blue": {"fish:1"}} 11 | self.markov_chain = self.build_markov(word_list) 12 | self.first_word = list(self.markov_chain.keys())[0] 13 | 14 | def build_markov(self, word_list): 15 | markov_chain = {} 16 | 17 | for i in range(len(word_list) - 1): 18 | #get the current word and the word after 19 | current_word = word_list[i] 20 | next_word = word_list[i+1] 21 | 22 | if current_word in markov_chain.keys(): #already there 23 | #get the histogram for that word in the chain 24 | histogram = markov_chain[current_word] 25 | #add to count 26 | histogram.dictionary_histogram[next_word] = histogram.dictionary_histogram.get(next_word, 0) + 1 27 | else: #first entry 28 | markov_chain[current_word] = Dictogram([next_word]) 29 | 30 | return markov_chain 31 | 32 | def walk(self, num_words): 33 | #TODO: generate a sentence num_words long using the markov chain 34 | pass 35 | 36 | def print_chain(self): 37 | for word, histogram in self.markov_chain.items(): 38 | print(word, histogram.dictionary_histogram) 39 | 40 | 41 | 42 | markov_chain = MarkovChain(["one", "fish", "two", "fish", "red", "fish", "blue", "fish"]) 43 | markov_chain.print_chain() 44 | print(markov_chain.walk(10)) -------------------------------------------------------------------------------- /Code/Simplified_Starter_Code/test_dictogram.py: -------------------------------------------------------------------------------- 1 | #to run type: pytest test_dictogram.py 2 | from dictogram import Dictogram 3 | 4 | # known inputs and their expected results 5 | fish_words = ['one', 'fish', 'two', 'fish', 'red', 'fish', 'blue', 'fish'] 6 | fish_dict = {'one': 1, 'fish': 4, 'two': 1, 'red': 1, 'blue': 1} 7 | 8 | def test_entries(): 9 | dictogram = Dictogram(fish_words).dictionary_histogram 10 | # Verify histogram as dictionary of entries like {word: count} 11 | assert len(dictogram) == 5 12 | assert len(dictogram) == len(fish_dict) 13 | 14 | def test_contains(): 15 | dictogram = Dictogram(fish_words).dictionary_histogram 16 | # All of these words should be found 17 | for word in fish_words: 18 | assert word in dictogram 19 | # None of these words should be found 20 | for word in ('fishy', 'food'): 21 | assert word not in dictogram 22 | 23 | def test_frequency(): 24 | dictogram = Dictogram(fish_words) 25 | # Verify frequency count of all words 26 | assert dictogram.frequency('one') == 1 27 | assert dictogram.frequency('two') == 1 28 | assert dictogram.frequency('red') == 1 29 | assert dictogram.frequency('blue') == 1 30 | assert dictogram.frequency('fish') == 4 31 | 32 | 33 | def test_tokens(): 34 | dictogram = Dictogram(fish_words) 35 | # Verify total count of all word tokens 36 | assert len(fish_words) == 8 37 | assert dictogram.tokens == 8 38 | 39 | def test_types(): 40 | dictogram = Dictogram(fish_words) 41 | # Verify count of distinct word types 42 | assert len(set(fish_words)) == 5 43 | assert dictogram.types == 5 44 | 45 | def test_sample(): 46 | dictogram = Dictogram(fish_words) 47 | # Create a list of 10,000 word samples from histogram 48 | samples_list = [dictogram.sample() for _ in range(10000)] 49 | # Create a histogram to count frequency of each word 50 | samples_hist = Dictogram(samples_list) 51 | # Check each word in original histogram 52 | for word, count in dictogram.dictionary_histogram.items(): 53 | # Calculate word's observed frequency 54 | observed_freq = count / dictogram.tokens 55 | # Calculate word's sampled frequency 56 | samples = samples_hist.frequency(word) 57 | sampled_freq = samples / samples_hist.tokens 58 | # Verify word's sampled frequency is close to observed frequency 59 | lower_bound = observed_freq * 0.9 # 10% below = 90% = 0.9 60 | upper_bound = observed_freq * 1.1 # 10% above = 110% = 1.1 61 | assert lower_bound <= sampled_freq <= upper_bound -------------------------------------------------------------------------------- /Code/Simplified_Starter_Code/test_listogram.py: -------------------------------------------------------------------------------- 1 | 2 | from listogram import Listogram 3 | 4 | # known inputs and their expected results 5 | fish_words = ['one', 'fish', 'two', 'fish', 'red', 'fish', 'blue', 'fish'] 6 | fish_list = [('one', 1), ('fish', 4), ('two', 1), ('red', 1), ('blue', 1)] 7 | 8 | def test_entries(): 9 | # NOTE: This test assumes Listogram is implemented as a list of tuples, 10 | # but if you implement it as a list of lists (or a list of count-lists) 11 | # you should modify the fish_list fixture above and/or this test (only) 12 | listogram = Listogram(fish_words) 13 | # Verify histogram as list of entries like [(word, count)] 14 | assert len(listogram.list_histogram) == 5 15 | assert len(listogram.list_histogram) == len(fish_list) # Ignore item order 16 | 17 | def test_frequency(): 18 | histogram = Listogram(fish_words) 19 | # Verify frequency count of all words 20 | assert histogram.frequency('one') == 1 21 | assert histogram.frequency('two') == 1 22 | assert histogram.frequency('red') == 1 23 | assert histogram.frequency('blue') == 1 24 | assert histogram.frequency('fish') == 4 25 | 26 | 27 | def test_tokens(): 28 | listogram = Listogram(fish_words) 29 | # Verify total count of all word tokens 30 | assert len(fish_words) == 8 31 | assert listogram.tokens == 8 32 | 33 | def test_types(): 34 | listogram = Listogram(fish_words) 35 | # Verify count of distinct word types 36 | assert len(set(fish_words)) == 5 37 | assert listogram.types == 5 38 | 39 | def test_sample(): 40 | listogram = Listogram(fish_words) 41 | # Create a list of 10,000 word samples from histogram 42 | samples_list = [listogram.sample() for _ in range(10000)] 43 | # Create a histogram to count frequency of each word 44 | samples_hist = Listogram(samples_list) 45 | # Check each word in original histogram 46 | for item in listogram.list_histogram: 47 | word = item[0] 48 | count = item[1] 49 | # Calculate word's observed frequency 50 | observed_freq = count / listogram.tokens 51 | # Calculate word's sampled frequency 52 | samples = samples_hist.frequency(word) 53 | sampled_freq = samples / samples_hist.tokens 54 | # Verify word's sampled frequency is close to observed frequency 55 | lower_bound = observed_freq * 0.9 # 10% below = 90% = 0.9 56 | upper_bound = observed_freq * 1.1 # 10% above = 110% = 1.1 57 | assert lower_bound <= sampled_freq <= upper_bound 58 | -------------------------------------------------------------------------------- /Code/dictogram.py: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | from __future__ import division, print_function # Python 2 and 3 compatibility 4 | import random 5 | 6 | 7 | class Dictogram(dict): 8 | """Dictogram is a histogram implemented as a subclass of the dict type.""" 9 | 10 | def __init__(self, word_list=None): 11 | """Initialize this histogram as a new dict and count given words.""" 12 | super(Dictogram, self).__init__() # Initialize this as a new dict 13 | # Add properties to track useful word counts for this histogram 14 | self.types = 0 # Count of distinct word types in this histogram 15 | self.tokens = 0 # Total count of all word tokens in this histogram 16 | # Count words in given list, if any 17 | if word_list is not None: 18 | for word in word_list: 19 | self.add_count(word) 20 | 21 | def add_count(self, word, count=1): 22 | """Increase frequency count of given word by given count amount.""" 23 | # TODO: Increase word frequency by count 24 | 25 | def frequency(self, word): 26 | """Return frequency count of given word, or 0 if word is not found.""" 27 | # TODO: Retrieve word frequency count 28 | 29 | def sample(self): 30 | """Return a word from this histogram, randomly sampled by weighting 31 | each word's probability of being chosen by its observed frequency.""" 32 | # TODO: Randomly choose a word based on its frequency in this histogram 33 | 34 | 35 | def print_histogram(word_list): 36 | print() 37 | print('Histogram:') 38 | print('word list: {}'.format(word_list)) 39 | # Create a dictogram and display its contents 40 | histogram = Dictogram(word_list) 41 | print('dictogram: {}'.format(histogram)) 42 | print('{} tokens, {} types'.format(histogram.tokens, histogram.types)) 43 | for word in word_list[-2:]: 44 | freq = histogram.frequency(word) 45 | print('{!r} occurs {} times'.format(word, freq)) 46 | print() 47 | print_histogram_samples(histogram) 48 | 49 | 50 | def print_histogram_samples(histogram): 51 | print('Histogram samples:') 52 | # Sample the histogram 10,000 times and count frequency of results 53 | samples_list = [histogram.sample() for _ in range(10000)] 54 | samples_hist = Dictogram(samples_list) 55 | print('samples: {}'.format(samples_hist)) 56 | print() 57 | print('Sampled frequency and error from observed frequency:') 58 | header = '| word type | observed freq | sampled freq | error |' 59 | divider = '-' * len(header) 60 | print(divider) 61 | print(header) 62 | print(divider) 63 | # Colors for error 64 | green = '\033[32m' 65 | yellow = '\033[33m' 66 | red = '\033[31m' 67 | reset = '\033[m' 68 | # Check each word in original histogram 69 | for word, count in histogram.items(): 70 | # Calculate word's observed frequency 71 | observed_freq = count / histogram.tokens 72 | # Calculate word's sampled frequency 73 | samples = samples_hist.frequency(word) 74 | sampled_freq = samples / samples_hist.tokens 75 | # Calculate error between word's sampled and observed frequency 76 | error = (sampled_freq - observed_freq) / observed_freq 77 | color = green if abs(error) < 0.05 else yellow if abs(error) < 0.1 else red 78 | print('| {!r:<9} '.format(word) 79 | + '| {:>4} = {:>6.2%} '.format(count, observed_freq) 80 | + '| {:>4} = {:>6.2%} '.format(samples, sampled_freq) 81 | + '| {}{:>+7.2%}{} |'.format(color, error, reset)) 82 | print(divider) 83 | print() 84 | 85 | 86 | def main(): 87 | import sys 88 | arguments = sys.argv[1:] # Exclude script name in first argument 89 | if len(arguments) >= 1: 90 | # Test histogram on given arguments 91 | print_histogram(arguments) 92 | else: 93 | # Test histogram on letters in a word 94 | word = 'abracadabra' 95 | print_histogram(list(word)) 96 | # Test histogram on words in a classic book title 97 | fish_text = 'one fish two fish red fish blue fish' 98 | print_histogram(fish_text.split()) 99 | # Test histogram on words in a long repetitive sentence 100 | woodchuck_text = ('how much wood would a wood chuck chuck' 101 | ' if a wood chuck could chuck wood') 102 | print_histogram(woodchuck_text.split()) 103 | 104 | 105 | if __name__ == '__main__': 106 | main() 107 | -------------------------------------------------------------------------------- /Code/dictogram_test.py: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | from dictogram import Dictogram 4 | import unittest 5 | # Python 2 and 3 compatibility: unittest module renamed this assertion method 6 | if not hasattr(unittest.TestCase, 'assertCountEqual'): 7 | unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual 8 | 9 | 10 | class DictogramTest(unittest.TestCase): 11 | 12 | # Test fixtures: known inputs and their expected results 13 | fish_words = ['one', 'fish', 'two', 'fish', 'red', 'fish', 'blue', 'fish'] 14 | fish_list = [('one', 1), ('fish', 4), ('two', 1), ('red', 1), ('blue', 1)] 15 | fish_dict = {'one': 1, 'fish': 4, 'two': 1, 'red': 1, 'blue': 1} 16 | 17 | def test_entries(self): 18 | dictogram = Dictogram(self.fish_words) 19 | # Verify histogram as dictionary of entries like {word: count} 20 | assert len(dictogram) == 5 21 | self.assertCountEqual(dictogram, self.fish_dict) # Ignore item order 22 | # Verify histogram as list of entries like [(word, count)] 23 | listogram = dictogram.items() 24 | assert len(listogram) == 5 25 | self.assertCountEqual(listogram, self.fish_list) # Ignore item order 26 | 27 | def test_contains(self): 28 | histogram = Dictogram(self.fish_words) 29 | # All of these words should be found 30 | for word in self.fish_words: 31 | assert word in histogram 32 | # None of these words should be found 33 | for word in ('fishy', 'food'): 34 | assert word not in histogram 35 | 36 | def test_frequency(self): 37 | histogram = Dictogram(self.fish_words) 38 | # Verify frequency count of all words 39 | assert histogram.frequency('one') == 1 40 | assert histogram.frequency('two') == 1 41 | assert histogram.frequency('red') == 1 42 | assert histogram.frequency('blue') == 1 43 | assert histogram.frequency('fish') == 4 44 | # Verify frequency count of unseen words 45 | assert histogram.frequency('food') == 0 46 | 47 | def test_add_count(self): 48 | histogram = Dictogram(self.fish_words) 49 | # Add more words to update frequency counts 50 | histogram.add_count('two', 2) 51 | histogram.add_count('blue', 3) 52 | histogram.add_count('fish', 4) 53 | histogram.add_count('food', 5) 54 | # Verify updated frequency count of all words 55 | assert histogram.frequency('one') == 1 56 | assert histogram.frequency('two') == 3 57 | assert histogram.frequency('red') == 1 58 | assert histogram.frequency('blue') == 4 59 | assert histogram.frequency('fish') == 8 60 | assert histogram.frequency('food') == 5 61 | # Verify count of distinct word types 62 | assert histogram.types == 6 63 | # Verify total count of all word tokens 64 | assert histogram.tokens == 8 + 14 65 | 66 | def test_tokens(self): 67 | histogram = Dictogram(self.fish_words) 68 | # Verify total count of all word tokens 69 | assert len(self.fish_words) == 8 70 | assert histogram.tokens == 8 71 | # Adding words again should double total count of all word tokens 72 | for word in self.fish_words: 73 | histogram.add_count(word) 74 | assert histogram.tokens == 8 * 2 75 | 76 | def test_types(self): 77 | histogram = Dictogram(self.fish_words) 78 | # Verify count of distinct word types 79 | assert len(set(self.fish_words)) == 5 80 | assert histogram.types == 5 81 | # Adding words again should not change count of distinct word types 82 | for word in self.fish_words: 83 | histogram.add_count(word) 84 | assert histogram.types == 5 85 | 86 | def test_sample(self): 87 | histogram = Dictogram(self.fish_words) 88 | # Create a list of 10,000 word samples from histogram 89 | samples_list = [histogram.sample() for _ in range(10000)] 90 | # Create a histogram to count frequency of each word 91 | samples_hist = Dictogram(samples_list) 92 | # Check each word in original histogram 93 | for word, count in histogram.items(): 94 | # Calculate word's observed frequency 95 | observed_freq = count / histogram.tokens 96 | # Calculate word's sampled frequency 97 | samples = samples_hist.frequency(word) 98 | sampled_freq = samples / samples_hist.tokens 99 | # Verify word's sampled frequency is close to observed frequency 100 | lower_bound = observed_freq * 0.9 # 10% below = 90% = 0.9 101 | upper_bound = observed_freq * 1.1 # 10% above = 110% = 1.1 102 | assert lower_bound <= sampled_freq <= upper_bound 103 | 104 | 105 | if __name__ == '__main__': 106 | unittest.main() 107 | -------------------------------------------------------------------------------- /Code/hashtable.py: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | from linkedlist import LinkedList 4 | 5 | 6 | class HashTable(object): 7 | 8 | def __init__(self, init_size=8): 9 | """Initialize this hash table with the given initial size.""" 10 | # Create a new list (used as fixed-size array) of empty linked lists 11 | self.buckets = [] 12 | for i in range(init_size): 13 | self.buckets.append(LinkedList()) 14 | 15 | def __str__(self): 16 | """Return a formatted string representation of this hash table.""" 17 | items = [] 18 | for key, val in self.items(): 19 | items.append('{!r}: {!r}'.format(key, val)) 20 | return '{' + ', '.join(items) + '}' 21 | 22 | def __repr__(self): 23 | """Return a string representation of this hash table.""" 24 | return 'HashTable({!r})'.format(self.items()) 25 | 26 | def _bucket_index(self, key): 27 | """Return the bucket index where the given key would be stored.""" 28 | # Calculate the given key's hash code and transform into bucket index 29 | return hash(key) % len(self.buckets) 30 | 31 | def keys(self): 32 | """Return a list of all keys in this hash table. 33 | TODO: Running time: O(???) Why and under what conditions?""" 34 | # Collect all keys in each bucket 35 | all_keys = [] 36 | for bucket in self.buckets: 37 | for key, value in bucket.items(): 38 | all_keys.append(key) 39 | return all_keys 40 | 41 | def values(self): 42 | """Return a list of all values in this hash table. 43 | TODO: Running time: O(???) Why and under what conditions?""" 44 | # TODO: Loop through all buckets 45 | # TODO: Collect all values in each bucket 46 | 47 | def items(self): 48 | """Return a list of all items (key-value pairs) in this hash table. 49 | TODO: Running time: O(???) Why and under what conditions?""" 50 | # Collect all pairs of key-value entries in each bucket 51 | all_items = [] 52 | for bucket in self.buckets: 53 | all_items.extend(bucket.items()) 54 | return all_items 55 | 56 | def length(self): 57 | """Return the number of key-value entries by traversing its buckets. 58 | TODO: Running time: O(???) Why and under what conditions?""" 59 | # TODO: Loop through all buckets 60 | # TODO: Count number of key-value entries in each bucket 61 | 62 | def contains(self, key): 63 | """Return True if this hash table contains the given key, or False. 64 | TODO: Running time: O(???) Why and under what conditions?""" 65 | # TODO: Find bucket where given key belongs 66 | # TODO: Check if key-value entry exists in bucket 67 | 68 | def get(self, key): 69 | """Return the value associated with the given key, or raise KeyError. 70 | TODO: Running time: O(???) Why and under what conditions?""" 71 | # TODO: Find bucket where given key belongs 72 | # TODO: Check if key-value entry exists in bucket 73 | # TODO: If found, return value associated with given key 74 | # TODO: Otherwise, raise error to tell user get failed 75 | # Hint: raise KeyError('Key not found: {}'.format(key)) 76 | 77 | def set(self, key, value): 78 | """Insert or update the given key with its associated value. 79 | TODO: Running time: O(???) Why and under what conditions?""" 80 | # TODO: Find bucket where given key belongs 81 | # TODO: Check if key-value entry exists in bucket 82 | # TODO: If found, update value associated with given key 83 | # TODO: Otherwise, insert given key-value entry into bucket 84 | 85 | def delete(self, key): 86 | """Delete the given key from this hash table, or raise KeyError. 87 | TODO: Running time: O(???) Why and under what conditions?""" 88 | # TODO: Find bucket where given key belongs 89 | # TODO: Check if key-value entry exists in bucket 90 | # TODO: If found, delete entry associated with given key 91 | # TODO: Otherwise, raise error to tell user delete failed 92 | # Hint: raise KeyError('Key not found: {}'.format(key)) 93 | 94 | if __name__ == '__main__': 95 | ht = HashTable() 96 | print('hash table: {}'.format(ht)) 97 | -------------------------------------------------------------------------------- /Code/hashtable_class_example.py: -------------------------------------------------------------------------------- 1 | from linkedlist import LinkedList 2 | 3 | keyvalues = [("rose", 10), ("mums", 12), ("daisy", 5)] 4 | 5 | #hash table 6 | #array of linked lists 7 | my_hashtable = [LinkedList(), LinkedList(), LinkedList()] 8 | 9 | #hash function 10 | def my_hash(key): 11 | return len(key) 12 | 13 | #figure out bucket ids 14 | #rose #3 15 | bucket_id = my_hash(keyvalues[0][0]) % len(my_hashtable) 16 | print(bucket_id) 17 | 18 | #add the key value pair to the hash table? 19 | ll_at_bucket = my_hashtable[bucket_id] 20 | ll_at_bucket.append(keyvalues[0]) 21 | print(ll_at_bucket) 22 | 23 | #mums #3 24 | bucket_id = my_hash(keyvalues[1][0]) % len(my_hashtable) 25 | print(bucket_id) 26 | ll_at_bucket = my_hashtable[bucket_id] 27 | ll_at_bucket.append(keyvalues[1]) 28 | print(ll_at_bucket) 29 | #daisy #3 30 | bucket_id = my_hash(keyvalues[2][0]) % len(my_hashtable) 31 | print(bucket_id) 32 | ll_at_bucket = my_hashtable[bucket_id] 33 | ll_at_bucket.append(keyvalues[2]) 34 | print(ll_at_bucket) 35 | -------------------------------------------------------------------------------- /Code/hashtable_test.py: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | from hashtable import HashTable 4 | import unittest 5 | # Python 2 and 3 compatibility: unittest module renamed this assertion method 6 | if not hasattr(unittest.TestCase, 'assertCountEqual'): 7 | unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual 8 | 9 | 10 | class HashTableTest(unittest.TestCase): 11 | 12 | def test_init(self): 13 | ht = HashTable(4) 14 | assert len(ht.buckets) == 4 15 | assert ht.length() == 0 16 | 17 | def test_keys(self): 18 | ht = HashTable() 19 | assert ht.keys() == [] 20 | ht.set('I', 1) 21 | assert ht.keys() == ['I'] 22 | ht.set('V', 5) 23 | self.assertCountEqual(ht.keys(), ['I', 'V']) # Ignore item order 24 | ht.set('X', 10) 25 | self.assertCountEqual(ht.keys(), ['I', 'V', 'X']) # Ignore item order 26 | 27 | def test_values(self): 28 | ht = HashTable() 29 | assert ht.values() == [] 30 | ht.set('I', 1) 31 | assert ht.values() == [1] 32 | ht.set('V', 5) 33 | self.assertCountEqual(ht.values(), [1, 5]) # Ignore item order 34 | ht.set('X', 10) 35 | self.assertCountEqual(ht.values(), [1, 5, 10]) # Ignore item order 36 | 37 | def test_items(self): 38 | ht = HashTable() 39 | assert ht.items() == [] 40 | ht.set('I', 1) 41 | assert ht.items() == [('I', 1)] 42 | ht.set('V', 5) 43 | self.assertCountEqual(ht.items(), [('I', 1), ('V', 5)]) 44 | ht.set('X', 10) 45 | self.assertCountEqual(ht.items(), [('I', 1), ('V', 5), ('X', 10)]) 46 | 47 | def test_length(self): 48 | ht = HashTable() 49 | assert ht.length() == 0 50 | ht.set('I', 1) 51 | assert ht.length() == 1 52 | ht.set('V', 5) 53 | assert ht.length() == 2 54 | ht.set('X', 10) 55 | assert ht.length() == 3 56 | 57 | def test_contains(self): 58 | ht = HashTable() 59 | ht.set('I', 1) 60 | ht.set('V', 5) 61 | ht.set('X', 10) 62 | assert ht.contains('I') is True 63 | assert ht.contains('V') is True 64 | assert ht.contains('X') is True 65 | assert ht.contains('A') is False 66 | 67 | def test_set_and_get(self): 68 | ht = HashTable() 69 | ht.set('I', 1) 70 | ht.set('V', 5) 71 | ht.set('X', 10) 72 | assert ht.get('I') == 1 73 | assert ht.get('V') == 5 74 | assert ht.get('X') == 10 75 | assert ht.length() == 3 76 | with self.assertRaises(KeyError): 77 | ht.get('A') # Key does not exist 78 | 79 | def test_set_twice_and_get(self): 80 | ht = HashTable() 81 | ht.set('I', 1) 82 | ht.set('V', 4) 83 | ht.set('X', 9) 84 | assert ht.length() == 3 85 | ht.set('V', 5) # Update value 86 | ht.set('X', 10) # Update value 87 | assert ht.get('I') == 1 88 | assert ht.get('V') == 5 89 | assert ht.get('X') == 10 90 | assert ht.length() == 3 # Check length is not overcounting 91 | 92 | def test_delete(self): 93 | ht = HashTable() 94 | ht.set('I', 1) 95 | ht.set('V', 5) 96 | ht.set('X', 10) 97 | assert ht.length() == 3 98 | ht.delete('I') 99 | ht.delete('X') 100 | assert ht.length() == 1 101 | with self.assertRaises(KeyError): 102 | ht.delete('X') # Key no longer exists 103 | with self.assertRaises(KeyError): 104 | ht.delete('A') # Key does not exist 105 | 106 | 107 | if __name__ == '__main__': 108 | unittest.main() 109 | -------------------------------------------------------------------------------- /Code/linkedlist.py: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | 4 | class Node(object): 5 | 6 | def __init__(self, data): 7 | """Initialize this node with the given data.""" 8 | self.data = data 9 | self.next = None 10 | 11 | def __repr__(self): 12 | """Return a string representation of this node.""" 13 | return f'Node({self.data})' 14 | 15 | 16 | class LinkedList: 17 | 18 | def __init__(self, items=None): 19 | """Initialize this linked list and append the given items, if any.""" 20 | self.head = None # First node 21 | self.tail = None # Last node 22 | # Append given items 23 | if items is not None: 24 | for item in items: 25 | self.append(item) 26 | 27 | def __repr__(self): 28 | """Return a string representation of this linked list.""" 29 | ll_str = "" 30 | for item in self.items(): 31 | ll_str += f'({item}) -> ' 32 | return ll_str 33 | 34 | def items(self): 35 | """Return a list (dynamic array) of all items in this linked list. 36 | Best and worst case running time: O(n) for n items in the list (length) 37 | because we always need to loop through all n nodes to get each item.""" 38 | items = [] # O(1) time to create empty list 39 | # Start at head node 40 | node = self.head # O(1) time to assign new variable 41 | # Loop until node is None, which is one node too far past tail 42 | while node is not None: # Always n iterations because no early return 43 | items.append(node.data) # O(1) time (on average) to append to list 44 | # Skip to next node to advance forward in linked list 45 | node = node.next # O(1) time to reassign variable 46 | # Now list contains items from all nodes 47 | return items # O(1) time to return list 48 | 49 | def is_empty(self): 50 | """Return a boolean indicating whether this linked list is empty.""" 51 | return self.head is None 52 | 53 | def length(self): 54 | """Return the length of this linked list by traversing its nodes. 55 | TODO: Running time: O(n) Why and under what conditions?""" 56 | # TODO: Loop through all nodes and count one for each 57 | 58 | 59 | def append(self, item): 60 | """Insert the given item at the tail of this linked list. 61 | TODO: Running time: O(???) Why and under what conditions?""" 62 | # TODO: Create new node to hold given item 63 | # TODO: If self.is_empty() == True set the head and the tail to the new node 64 | # TODO: Else append node after tail 65 | 66 | 67 | def prepend(self, item): 68 | """Insert the given item at the head of this linked list. 69 | TODO: Running time: O(???) Why and under what conditions?""" 70 | # TODO: Create new node to hold given item 71 | # TODO: Prepend node before head, if it exists 72 | 73 | def find(self, item): 74 | """Return an item from this linked list if it is present. 75 | TODO: Best case running time: O(???) Why and under what conditions? 76 | TODO: Worst case running time: O(???) Why and under what conditions?""" 77 | # TODO: Loop through all nodes to find item, if present return True otherwise False 78 | 79 | def delete(self, item): 80 | """Delete the given item from this linked list, or raise ValueError. 81 | TODO: Best case running time: O(???) Why and under what conditions? 82 | TODO: Worst case running time: O(???) Why and under what conditions?""" 83 | # TODO: Loop through all nodes to find one whose data matches given item 84 | # TODO: Update previous node to skip around node with matching data 85 | # TODO: Otherwise raise error to tell user that delete has failed 86 | # Hint: raise ValueError('Item not found: {}'.format(item)) 87 | 88 | if __name__ == "__main__": 89 | my_ll = LinkedList(["A", "B", "C"]) 90 | print(my_ll) 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /Code/listogram.py: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | from __future__ import division, print_function # Python 2 and 3 compatibility 4 | import random 5 | 6 | 7 | class Listogram(list): 8 | """Listogram is a histogram implemented as a subclass of the list type.""" 9 | 10 | def __init__(self, word_list=None): 11 | """Initialize this histogram as a new list and count given words.""" 12 | super(Listogram, self).__init__() # Initialize this as a new list 13 | # Add properties to track useful word counts for this histogram 14 | self.types = 0 # Count of distinct word types in this histogram 15 | self.tokens = 0 # Total count of all word tokens in this histogram 16 | # Count words in given list, if any 17 | if word_list is not None: 18 | for word in word_list: 19 | self.add_count(word) 20 | 21 | def add_count(self, word, count=1): 22 | """Increase frequency count of given word by given count amount.""" 23 | # TODO: Increase word frequency by count 24 | 25 | def frequency(self, word): 26 | """Return frequency count of given word, or 0 if word is not found.""" 27 | # TODO: Retrieve word frequency count 28 | 29 | def __contains__(self, word): 30 | """Return boolean indicating if given word is in this histogram.""" 31 | # TODO: Check if word is in this histogram 32 | 33 | def index_of(self, target): 34 | """Return the index of entry containing given target word if found in 35 | this histogram, or None if target word is not found.""" 36 | # TODO: Implement linear search to find index of entry with target word 37 | 38 | def sample(self): 39 | """Return a word from this histogram, randomly sampled by weighting 40 | each word's probability of being chosen by its observed frequency.""" 41 | # TODO: Randomly choose a word based on its frequency in this histogram 42 | 43 | 44 | def print_histogram(word_list): 45 | print() 46 | print('Histogram:') 47 | print('word list: {}'.format(word_list)) 48 | # Create a listogram and display its contents 49 | histogram = Listogram(word_list) 50 | print('listogram: {}'.format(histogram)) 51 | print('{} tokens, {} types'.format(histogram.tokens, histogram.types)) 52 | for word in word_list[-2:]: 53 | freq = histogram.frequency(word) 54 | print('{!r} occurs {} times'.format(word, freq)) 55 | print() 56 | print_histogram_samples(histogram) 57 | 58 | 59 | def print_histogram_samples(histogram): 60 | print('Histogram samples:') 61 | # Sample the histogram 10,000 times and count frequency of results 62 | samples_list = [histogram.sample() for _ in range(10000)] 63 | samples_hist = Listogram(samples_list) 64 | print('samples: {}'.format(samples_hist)) 65 | print() 66 | print('Sampled frequency and error from observed frequency:') 67 | header = '| word type | observed freq | sampled freq | error |' 68 | divider = '-' * len(header) 69 | print(divider) 70 | print(header) 71 | print(divider) 72 | # Colors for error 73 | green = '\033[32m' 74 | yellow = '\033[33m' 75 | red = '\033[31m' 76 | reset = '\033[m' 77 | # Check each word in original histogram 78 | for word, count in histogram: 79 | # Calculate word's observed frequency 80 | observed_freq = count / histogram.tokens 81 | # Calculate word's sampled frequency 82 | samples = samples_hist.frequency(word) 83 | sampled_freq = samples / samples_hist.tokens 84 | # Calculate error between word's sampled and observed frequency 85 | error = (sampled_freq - observed_freq) / observed_freq 86 | color = green if abs(error) < 0.05 else yellow if abs(error) < 0.1 else red 87 | print('| {!r:<9} '.format(word) 88 | + '| {:>4} = {:>6.2%} '.format(count, observed_freq) 89 | + '| {:>4} = {:>6.2%} '.format(samples, sampled_freq) 90 | + '| {}{:>+7.2%}{} |'.format(color, error, reset)) 91 | print(divider) 92 | print() 93 | 94 | 95 | def main(): 96 | import sys 97 | arguments = sys.argv[1:] # Exclude script name in first argument 98 | if len(arguments) >= 1: 99 | # Test histogram on given arguments 100 | print_histogram(arguments) 101 | else: 102 | # Test histogram on letters in a word 103 | word = 'abracadabra' 104 | print_histogram(list(word)) 105 | # Test histogram on words in a classic book title 106 | fish_text = 'one fish two fish red fish blue fish' 107 | print_histogram(fish_text.split()) 108 | # Test histogram on words in a long repetitive sentence 109 | woodchuck_text = ('how much wood would a wood chuck chuck' 110 | ' if a wood chuck could chuck wood') 111 | print_histogram(woodchuck_text.split()) 112 | 113 | 114 | if __name__ == '__main__': 115 | main() 116 | -------------------------------------------------------------------------------- /Code/listogram_test.py: -------------------------------------------------------------------------------- 1 | #!python 2 | 3 | from listogram import Listogram 4 | import unittest 5 | # Python 2 and 3 compatibility: unittest module renamed this assertion method 6 | if not hasattr(unittest.TestCase, 'assertCountEqual'): 7 | unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual 8 | 9 | 10 | class ListogramTest(unittest.TestCase): 11 | 12 | # Test fixtures: known inputs and their expected results 13 | fish_words = ['one', 'fish', 'two', 'fish', 'red', 'fish', 'blue', 'fish'] 14 | fish_list = [('one', 1), ('fish', 4), ('two', 1), ('red', 1), ('blue', 1)] 15 | fish_dict = {'one': 1, 'fish': 4, 'two': 1, 'red': 1, 'blue': 1} 16 | 17 | def test_entries(self): 18 | # NOTE: This test assumes Listogram is implemented as a list of tuples, 19 | # but if you implement it as a list of lists (or a list of count-lists) 20 | # you should modify the fish_list fixture above and/or this test (only) 21 | listogram = Listogram(self.fish_words) 22 | # Verify histogram as list of entries like [(word, count)] 23 | assert len(listogram) == 5 24 | self.assertCountEqual(listogram, self.fish_list) # Ignore item order 25 | # Verify histogram as dictionary of entries like {word: count} 26 | dictogram = dict(listogram) 27 | assert len(dictogram) == 5 28 | self.assertCountEqual(dictogram, self.fish_dict) # Ignore item order 29 | 30 | def test_contains(self): 31 | histogram = Listogram(self.fish_words) 32 | # All of these words should be found 33 | for word in self.fish_words: 34 | assert word in histogram 35 | # None of these words should be found 36 | for word in ('fishy', 'food'): 37 | assert word not in histogram 38 | 39 | def test_frequency(self): 40 | histogram = Listogram(self.fish_words) 41 | # Verify frequency count of all words 42 | assert histogram.frequency('one') == 1 43 | assert histogram.frequency('two') == 1 44 | assert histogram.frequency('red') == 1 45 | assert histogram.frequency('blue') == 1 46 | assert histogram.frequency('fish') == 4 47 | # Verify frequency count of unseen words 48 | assert histogram.frequency('food') == 0 49 | 50 | def test_add_count(self): 51 | histogram = Listogram(self.fish_words) 52 | # Add more words to update frequency counts 53 | histogram.add_count('two', 2) 54 | histogram.add_count('blue', 3) 55 | histogram.add_count('fish', 4) 56 | histogram.add_count('food', 5) 57 | # Verify updated frequency count of all words 58 | assert histogram.frequency('one') == 1 59 | assert histogram.frequency('two') == 3 60 | assert histogram.frequency('red') == 1 61 | assert histogram.frequency('blue') == 4 62 | assert histogram.frequency('fish') == 8 63 | assert histogram.frequency('food') == 5 64 | # Verify count of distinct word types 65 | assert histogram.types == 6 66 | # Verify total count of all word tokens 67 | assert histogram.tokens == 8 + 14 68 | 69 | def test_tokens(self): 70 | histogram = Listogram(self.fish_words) 71 | # Verify total count of all word tokens 72 | assert len(self.fish_words) == 8 73 | assert histogram.tokens == 8 74 | # Adding words again should double total count of all word tokens 75 | for word in self.fish_words: 76 | histogram.add_count(word) 77 | assert histogram.tokens == 8 * 2 78 | 79 | def test_types(self): 80 | histogram = Listogram(self.fish_words) 81 | # Verify count of distinct word types 82 | assert len(set(self.fish_words)) == 5 83 | assert histogram.types == 5 84 | # Adding words again should not change count of distinct word types 85 | for word in self.fish_words: 86 | histogram.add_count(word) 87 | assert histogram.types == 5 88 | 89 | def test_sample(self): 90 | histogram = Listogram(self.fish_words) 91 | # Create a list of 10,000 word samples from histogram 92 | samples_list = [histogram.sample() for _ in range(10000)] 93 | # Create a histogram to count frequency of each word 94 | samples_hist = Listogram(samples_list) 95 | # Check each word in original histogram 96 | for word, count in histogram: 97 | # Calculate word's observed frequency 98 | observed_freq = count / histogram.tokens 99 | # Calculate word's sampled frequency 100 | samples = samples_hist.frequency(word) 101 | sampled_freq = samples / samples_hist.tokens 102 | # Verify word's sampled frequency is close to observed frequency 103 | lower_bound = observed_freq * 0.9 # 10% below = 90% = 0.9 104 | upper_bound = observed_freq * 1.1 # 10% above = 110% = 1.1 105 | assert lower_bound <= sampled_freq <= upper_bound 106 | 107 | 108 | if __name__ == '__main__': 109 | unittest.main() 110 | -------------------------------------------------------------------------------- /Code/requirements.txt: -------------------------------------------------------------------------------- 1 | atomicwrites==1.3.0 2 | attrs==19.1.0 3 | autopep8==1.4.4 4 | certifi==2019.6.16 5 | chardet==3.0.4 6 | Click==7.0 7 | entrypoints==0.3 8 | flake8==3.7.8 9 | flake8-docstrings==1.3.1 10 | flake8-polyfill==1.0.2 11 | Flask==1.1.1 12 | Flask-PyMongo==2.3.0 13 | gunicorn==19.9.0 14 | idna==2.8 15 | importlib-metadata==0.23 16 | itsdangerous==1.1.0 17 | Jinja2==2.10.1 18 | MarkupSafe==1.1.1 19 | mccabe==0.6.1 20 | more-itertools==7.2.0 21 | packaging==19.1 22 | pluggy==0.13.0 23 | py==1.8.0 24 | pycodestyle==2.5.0 25 | pydocstyle==4.0.1 26 | pyflakes==2.1.1 27 | pymongo==3.9.0 28 | pyparsing==2.4.2 29 | pytest==5.1.2 30 | python-dotenv==0.10.3 31 | requests==2.22.0 32 | six==1.12.0 33 | snowballstemmer==1.9.0 34 | urllib3==1.25.3 35 | virtualenv==16.7.3 36 | wcwidth==0.1.7 37 | Werkzeug==0.15.6 38 | zipp==0.6.0 -------------------------------------------------------------------------------- /Code/runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.7.4 -------------------------------------------------------------------------------- /Lessons/AlgorithmAnalysis.md: -------------------------------------------------------------------------------- 1 | # [Algorithm Analysis](https://docs.google.com/presentation/d/1bZ1jGmCobX7qia3qRGe4wIq7aLx6F9lOQsAxnE63Nv4/edit#slide=id.p) 2 | 3 | ## Linked List Activities 4 | - Complete [linked list worksheet] 5 | - When finished, compare your answers to [linked list worksheet solutions] 6 | - Draw diagram of how a linked list data structure is stored in memory 7 | - Compare and contrast diagram representations with partners 8 | - Code review implementations of linked list class instance methods 9 | - Read and discuss [article on algorithm analysis and big O notation][IC big O] 10 | 11 | ## Hash Table Activities 12 | - Complete [hash table worksheet] 13 | - When finished, compare your answers to [hash table worksheet solutions] 14 | - Draw diagram of how a hash table data structure is stored in memory 15 | - Compare and contrast diagram representations with partners 16 | - Complete [hash table time complexity worksheet] 17 | - Watch [video of hash table time complexity worksheet review] 18 | - Form teams and collaboratively draw more complete hash table diagrams 19 | - Review merits of each diagram's faithfulness to actual memory organization 20 | - Code review implementations of hash table class instance methods 21 | 22 | ## Objectives 23 | After completing this class session and the associated tutorial challenges, students will be able to ... 24 | - Describe and diagram in detail how a hash table uses arrays and linked lists to store key-value entries 25 | - Explain how to add a new key-value entry to a hash table and how to get the value associated with a given key 26 | - Identify key ingredients used to build a hash table: hash function, indexed array of buckets, and linked lists to store multiple key-value entries per bucket 27 | - Perform basic analysis of algorithm time complexity with big O notation 28 | 29 | ## Resources 30 | - Review Make School's [algorithm analysis slides] 31 | - Read Interview Cake's [article on the idea behind big O notation][IC big O] 32 | - Read Stack Overflow's [plain English explanations of big O notation][SO big O] 33 | - Read Justin Abrams's [article on big O notation explained by a self-taught programmer][JA big O] 34 | - Watch HackerRank's [big O notation video] 35 | - Watch Harvard's [asymptotic notation video] and [computational complexity video] 36 | - Play with VisuAlgo's [interactive linked list][VisuAlgo list] and [hash table visualizations][VisuAlgo hash table] 37 | 38 | ## Challenges 39 | These challenges are the baseline required to complete the project and course. 40 | Be sure to complete these before next class session and before starting on the stretch challenges below. 41 | 42 | ### Linked List Challenges 43 | - Annotate these `LinkedList` class instance methods with time complexity analysis: 44 | - `length()` 45 | - `append(item)` 46 | - `prepend(item)` 47 | - `find(quality)` 48 | - `delete(item)` 49 | - See the `items()` instance method for an example annotation 50 | 51 | ### Hash Table Challenges 52 | - Annotate these `HashTable` class instance methods with time complexity analysis: 53 | - `length()` 54 | - `items()` 55 | - `contains(key)` 56 | - `get(key)` 57 | - `set(key, value)` 58 | - `delete(key)` 59 | 60 | ## Stretch Challenges 61 | These challenges are more difficult and help you push your skills and understanding to the next level. 62 | - [Page 10: Performance Analysis] 63 | - Benchmark the running time performance of your `LinkedList` and `HashTable` data structures with varying size using the [`timeit` module] 64 | - Benchmark the built-in `list` and `dict` types and compare to your `LinkedList` and `HashTable` classes 65 | 66 | 67 | [linked list worksheet]: https://make.sc/linked-list-worksheet 68 | [linked list worksheet solutions]: https://make.sc/linked-list-worksheet-solutions 69 | [hash table worksheet]: https://make.sc/hash-table-worksheet 70 | [hash table worksheet solutions]: https://make.sc/hash-table-worksheet-solutions 71 | [hash table time complexity worksheet]: https://make.sc/hash-table-time-complexity-worksheet 72 | [video of hash table time complexity worksheet review]: https://www.youtube.com/watch?v=Ka3hvRoUxnY 73 | [algorithm analysis slides]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Slides/AlgorithmAnalysis.pdf 74 | [big O notation video]: https://www.youtube.com/watch?v=v4cd1O4zkGw 75 | [asymptotic notation video]: https://www.youtube.com/watch?v=iOq5kSKqeR4 76 | [computational complexity video]: https://www.youtube.com/watch?v=IM9sHGlYV5A 77 | [IC big O]: https://www.interviewcake.com/article/python/big-o-notation-time-and-space-complexity 78 | [SO big O]: https://stackoverflow.com/questions/487258/what-is-a-plain-english-explanation-of-big-o-notation 79 | [JA big O]: https://justin.abrah.ms/computer-science/big-o-notation-explained.html 80 | [VisuAlgo list]: https://visualgo.net/list 81 | [VisuAlgo hash table]: https://visualgo.net/hashtable 82 | 83 | [`time` module]: https://docs.python.org/3/library/time.html 84 | [`timeit` module]: https://docs.python.org/3/library/timeit.html 85 | 86 | [Page 10: Performance Analysis]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/performance-analysis 87 | 88 | [linked list source code]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/linkedlist.py 89 | [hash table source code]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/hashtable.py 90 | -------------------------------------------------------------------------------- /Lessons/ArraysLinkedLists.md: -------------------------------------------------------------------------------- 1 | # [Arrays & Linked Lists](https://docs.google.com/presentation/d/108BfIVUqSgx6lOntEjZiJIuLlQ1yMfcUhiQJkJn87lM/edit#slide=id.p) 2 | 3 | ## Activities 4 | - Complete [histogram, Markov chain and sampling worksheet] 5 | - Watch [video of histogram, Markov chain, and sampling worksheet review] 6 | - Draw diagram of your Markov chain mental model and related data structures 7 | - Compare and contrast diagram representations and code organization with partners 8 | - Review how to build a Markov chain from text and generate sentences from it 9 | - Lecture and discussion following [array and linked list slides] 10 | - Watch [video of array and linked list lecture] 11 | - Act out how dynamic array and linked list data structures and algorithms work 12 | 13 | ## Objectives 14 | After completing this class session and the associated tutorial challenges, students will be able to ... 15 | - Diagram abstract concepts implemented with nested data structures 16 | - Describe and diagram how arrays and linked lists are stored in memory 17 | - Describe how dynamic arrays automatically resize when more space is needed 18 | - Compare advantages and disadvantages of dynamic arrays with linked lists 19 | - Implement essential linked list class instance methods using node objects 20 | 21 | ## Resources 22 | - Review Make School's [array and linked list slides] 23 | - Watch Make School's [array and linked list video lecture] 24 | - Watch HackerRank's [linked list video] 25 | - Watch Harvard's [array video], [singly linked list video], and [doubly linked list video] 26 | - Play with VisuAlgo's [interactive linked list visualization][VisuAlgo list] 27 | - Read Wikipedia's [dynamic array article] and [linked list article] 28 | 29 | ## Challenges 30 | These challenges are the baseline required to complete the project and course. 31 | Be sure to complete these before next class session and before starting on the stretch challenges below. 32 | - [Page 8: Linked List] 33 | - Implement `LinkedList` class using [linked list starter code] with these instance methods: 34 | - `length()` - return the length of the linked list by traversing its nodes 35 | - `append(item)` - insert `item` at the tail of the linked list 36 | - `prepend(item)` - insert `item` at the head of the linked list 37 | - `find(quality)` - return an item from the linked list satisfying the `quality` function 38 | - `delete(item)` - remove `item` from the linked list, or raise `ValueError` if not found 39 | - Run `python linkedlist.py` to test `LinkedList` class instance methods on a small example 40 | - Run `pytest linkedlist_test.py` to run the [linked list unit tests] and fix any failures 41 | 42 | ## Stretch Challenges 43 | These challenges are more difficult and help you push your skills and understanding to the next level. 44 | - [Page 8: Linked List] 45 | - Implement `replace(old_item, new_item)` - replaces `old_item` in the list with `new_item` without creating a new node 46 | - Want to make the `LinkedList` class more convenient to use? Add methods so that it can be used as an [iterable container], such as in a `for` loop 47 | - Consider an alternative approach to calculate the `length` of the linked list that doesn't require node traversal and implement it, then benchmark its running time against the first approach on short lists and long lists 48 | - Read about the [doubly linked list] structure and implement it in your own `DoublyLinkedList` class. What advantages and disadvantages does this structure have over a [singly linked list][linked list article]? 49 | 50 | 51 | [histogram, Markov chain and sampling worksheet]: https://make.sc/histogram-worksheet 52 | [video of histogram, Markov chain, and sampling worksheet review]: https://www.youtube.com/watch?v=ZnfqxrXrXKQ 53 | [video of array and linked list lecture]: https://www.youtube.com/watch?v=3RQ3ueNSb3k 54 | [array and linked list slides]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Slides/ArraysLinkedLists.pdf 55 | [array and linked list video lecture]: https://www.youtube.com/watch?v=3WWuf4H61Nk 56 | [linked list video]: https://www.youtube.com/watch?v=njTh_OwMljA 57 | [array video]: https://www.youtube.com/watch?v=7EdaoE46BTI 58 | [singly linked list video]: https://www.youtube.com/watch?v=ZoG2hOIoTnA 59 | [doubly linked list video]: https://www.youtube.com/watch?v=HmAEzp1taIE 60 | [dynamic array article]: https://en.wikipedia.org/wiki/Dynamic_array 61 | [linked list article]: https://en.wikipedia.org/wiki/Linked_list 62 | [doubly linked list]: https://en.wikipedia.org/wiki/Doubly_linked_list 63 | [VisuAlgo list]: https://visualgo.net/list 64 | 65 | [Page 8: Linked List]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/linked-list 66 | [iterable container]: https://docs.python.org/3/library/stdtypes.html#typeiter 67 | 68 | [linked list starter code]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/linkedlist.py 69 | [linked list unit tests]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/linkedlist_test.py 70 | -------------------------------------------------------------------------------- /Lessons/FlaskWebApp.md: -------------------------------------------------------------------------------- 1 | # [Flask Web App Development](https://docs.google.com/presentation/d/1IYRiJYRSD9w3a5pY9_tBC1iDVgfAvdjuZFxbJ3nLvCo/edit#slide=id.g7dd52372eb_0_67) 2 | 3 | ## Activities 4 | - Compare implementations for sampling words based on observed frequency 5 | - Visualize how sampling algorithms work by drawing pictures with a number line 6 | - Watch [video of sampling algorithms whiteboard activity] 7 | - Discuss tradeoffs of different sampling techniques based on histogram implementations 8 | 9 | ## Objectives 10 | After completing this class session and the associated tutorial challenges, students will be able to ... 11 | - Set up Python virtual environments for package isolation 12 | - Build and test simple Flask web apps on local computers 13 | - Deploy Flask web apps to Heroku cloud hosted servers 14 | 15 | ## Challenges 16 | These challenges are the baseline required to complete the project and course. 17 | Be sure to complete these before next class session and before starting on the stretch challenges below. 18 | - [Page 5: Flask Web App] 19 | - Set up an isolated virtual environment with `virtualenv` 20 | - Develop a Flask web app locally (access via `localhost`) 21 | - Push your Flask web app to Heroku servers (on the Web) 22 | 23 | ## Stretch Challenges 24 | These challenges are more difficult and help you push your skills and understanding to the next level. 25 | - [Page 5: Flask Web App] 26 | - Improve the style of your page with CSS 27 | - Display more than one generated word 28 | - Generate a specific number of words given in a URL query string parameter (like `/?num=10`) 29 | - Add a button to display a new word (i.e. refresh the page) when clicked 30 | - Add a button and route to store favorites (chosen by users) with a database 31 | 32 | ## Resources 33 | - Read The Hitchhiker's Guide to Python's tutorial on [virtual environments] 34 | - Consult documentation for Python's [`virtualenv` tool] 35 | - Read the [Flask quickstart] to jump right in and follow the [Flask tutorial] 36 | - Consult the [Flask documentation] to learn more and solve specific problems 37 | - Read [Explore Flask], a book about best practices and patterns for developing web apps with Flask 38 | - Install the [Heroku command line interface][Heroku CLI] to manage Heroku apps from your terminal 39 | 40 | 41 | [video of sampling algorithms whiteboard activity]: https://www.youtube.com/watch?v=C0jk6HLj6Tk 42 | [Page 5: Flask Web App]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/flask-web-app-ea916e69-cf94-4a51-8fa6-9d4ac013da65 43 | [virtual environments]: http://docs.python-guide.org/en/latest/dev/virtualenvs/ 44 | [`virtualenv` tool]: https://virtualenv.pypa.io/en/stable/ 45 | [Flask]: http://flask.pocoo.org/ 46 | [Flask documentation]: http://flask.pocoo.org/docs/0.11/ 47 | [Flask quickstart]: http://flask.pocoo.org/docs/0.11/quickstart/ 48 | [Flask tutorial]: http://flask.pocoo.org/docs/0.11/tutorial/ 49 | [Explore Flask]: https://exploreflask.com/en/latest/ 50 | [Heroku CLI]: https://devcenter.heroku.com/articles/heroku-cli 51 | -------------------------------------------------------------------------------- /Lessons/HW2.md: -------------------------------------------------------------------------------- 1 | # Linked Lists 2 | 3 | The goal of this assignment is to complete the [linked list starter code](https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/linkedlist.py) so that it is passing all tests in the [linked list test file](https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/linkedlist_test.py). 4 | 5 | In this assignment you will complete the following methods inside the linked list class: 6 | - length(): the number of nodes in the linked list 7 | - append(): inserts a new node at the tail of the linked list 8 | - prepend(): inserts a new node at the head of the linked list 9 | - find(): checks if data is present in the linked list 10 | - delete(): deletes a given item from the linked list -------------------------------------------------------------------------------- /Lessons/HW3.md: -------------------------------------------------------------------------------- 1 | # Hash Tables 2 | 3 | The goal of this assignment is to complete the [hash table starter code](https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/hashtable.py) so that it is passing all tests in the [hash table test file](https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/hashtable_test.py). 4 | 5 | In this assignment you will complete the following methods inside the hash table class: 6 | - values(): returns all the values present in the hash table as a list 7 | - length(): returns the number of key, values present in the hash table 8 | - contains(): returns true if key is in the hash table, false if not 9 | - get(): returns the value for the given key if present, key error if not 10 | - set(): adds a new key,value to the hash table if not already present, if key is already present updates the value 11 | - delete(): removes the given key value from the hash table -------------------------------------------------------------------------------- /Lessons/HashTables.md: -------------------------------------------------------------------------------- 1 | # [Hash Tables](https://docs.google.com/presentation/d/1pQDkjQfe5aEohm0N1uU_Ntg8QNsOpVs3Q5UTNuyb0Ys/edit#slide=id.p) 2 | 3 | ## Activities 4 | - Complete [linked list time complexity worksheet] 5 | - Watch [video of linked list time complexity worksheet review] 6 | - Lecture and discussion following [hash table slides] 7 | - Watch [video of hash table lecture] 8 | - Act out how hash table data structure and algorithms work 9 | 10 | ## Objectives 11 | After completing this class session and the associated tutorial challenges, students will be able to ... 12 | - Describe what a hash function does to enable mapping arbitrary keys to integers 13 | - Describe and diagram how a hash table uses arrays and linked lists to store key-value entries 14 | - Explain what a hash collision is, why it happens, and at least one resolution technique 15 | - Compare advantages and disadvantages of using hash tables versus arrays or linked lists 16 | - Implement essential hash table class instance methods 17 | 18 | ## Resources 19 | - Review Make School's [hash table slides] 20 | - Watch Make School's [hash table video lecture] 21 | - Watch HackerRank's [hash table video] 22 | - Watch Harvard's [old hash table video] and [new hash table video] 23 | - Play with VisuAlgo's [interactive hash table visualization][VisuAlgo hash table] 24 | - Read Wikipedia's [hash table article] 25 | 26 | ## Challenges 27 | These challenges are the baseline required to complete the project and course. 28 | Be sure to complete these before next class session and before starting on the stretch challenges below. 29 | - [Page 9: Hash Table] 30 | - Implement `HashTable` class using [hash table starter code] with these instance methods: 31 | - `length()` - return the number of entries (key-value pairs) in the hash table by traversing its buckets 32 | - `items()` - return a list of all entries (key-value pairs) in the hash table 33 | - `keys()` - return a list of all keys in the hash table 34 | - `values()` - return a list of all values in the hash table 35 | - `contains(key)` - return a boolean indicating whether `key` is in the hash table 36 | - `get(key)` - return the value associated with `key` in the hash table, or raise `KeyError` if not found 37 | - `set(key, value)` - insert `key` (or update, if already present) with associated `value` in the hash table 38 | - `delete(key)` - delete `key` and associated value from the hash table, or raise `KeyError` if not found 39 | - Run `python hashtable.py` to test `HashTable` class instance methods on a small example 40 | - Run `pytest hashtable_test.py` to run the [hash table unit tests] and fix any failures 41 | 42 | ## Stretch Challenges 43 | These challenges are more difficult and help you push your skills and understanding to the next level. 44 | - [Page 9: Hash Table] 45 | - Add several magic methods to allow subscripting syntax like the [Python `dict` type] 46 | - Want to make the `HashTable` class more convenient to use? Add methods so that it can be used as an [iterable container], such as in a `for` loop 47 | - Consider an alternative approach to calculate the `length` of the hash table that doesn't require bucket traversal and implement it, then benchmark its running time against the first approach on small and large hash tables 48 | - Implement an alternative hash table [collision resolution] strategy instead of [separate chaining] (like [linear probing]) and consider what advantages and disadvantages this approach has over chaining with linked lists 49 | - Write additional test cases to expand the [hash table unit tests] to ensure your collision resolution strategy is robust 50 | 51 | 52 | [linked list time complexity worksheet]: https://make.sc/linked-list-time-complexity-worksheet 53 | [video of linked list time complexity worksheet review]: https://www.youtube.com/watch?v=ZGtkVO6XlmQ 54 | [video of hash table lecture]: https://www.youtube.com/watch?v=drQ_FfCVxFU 55 | [hash table slides]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Slides/HashTables.pdf 56 | [hash table video lecture]: https://www.youtube.com/watch?v=nLWXJ6IDKmQ 57 | [hash table video]: https://www.youtube.com/watch?v=shs0KM3wKv8 58 | [old hash table video]: https://www.youtube.com/watch?v=h2d9b_nEzoA 59 | [new hash table video]: https://www.youtube.com/watch?v=tjtFkT97Xmc 60 | [VisuAlgo hash table]: https://visualgo.net/hashtable 61 | 62 | [hash table article]: https://en.wikipedia.org/wiki/Hash_table 63 | [collision resolution]: https://en.wikipedia.org/wiki/Hash_table#Collision_resolution 64 | [separate chaining]: https://en.wikipedia.org/wiki/Hash_table#Separate_chaining 65 | [linear probing]: https://en.wikipedia.org/wiki/Linear_probing 66 | 67 | [iterable container]: https://docs.python.org/3/library/stdtypes.html#typeiter 68 | [Python `dict` type]: https://docs.python.org/3/library/stdtypes.html#dict 69 | 70 | [Page 9: Hash Table]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/hash-table 71 | 72 | [hash table starter code]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/hashtable.py 73 | [hash table unit tests]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/hashtable_test.py 74 | -------------------------------------------------------------------------------- /Lessons/Histograms.md: -------------------------------------------------------------------------------- 1 | # [Histogram Data Structures](https://docs.google.com/presentation/d/1hFArsihiDByjiNm42kpAXHFIbRLXCIXw6SLLzInWI08/edit#slide=id.p) 2 | 3 | # [Histograms Part 2](https://docs.google.com/presentation/d/1V7-gTKR1flCrPTTIjMSDaMubevSrCu5i8tODLbgz890/edit#slide=id.g6e22aad45f_0_98) 4 | 5 | ## Activities 6 | - Compare code quality and techniques for rearranging words 7 | - Compare code quality for getting random dictionary words 8 | - Refactor code to improve readability, modularity, and performance 9 | 10 | ## Objectives 11 | After completing this class session and the associated tutorial challenges, students will be able to ... 12 | - Split strings into components to find words 13 | - Build a histogram to count word occurrences 14 | - Create and use dictionary, list, and tuple data types 15 | 16 | ## Challenges 17 | These challenges are the baseline required to complete the project and course. 18 | Be sure to complete these before next class session and before starting on the stretch challenges below. 19 | - [Page 3: Analyze Word Frequency in Text] 20 | - Histogram (dictionary) 21 | - Histogram (list of lists) 22 | - Histogram (list of tuples) 23 | - Histogram (list of counts) 24 | 25 | ## Stretch Challenges 26 | These challenges are more difficult and help you push your skills and understanding to the next level. 27 | - [Page 3: Analyze Word Frequency in Text] 28 | - Benchmark and optimize 29 | - Sort histogram entries by word or by count 30 | - Store the data in a histogram text file 31 | 32 | ## Resources 33 | - HackerRank's [Python challenges](https://www.hackerrank.com/domains/python/py-basic-data-types) – try the basic data types and strings sections 34 | 35 | 36 | [Page 3: Analyze Word Frequency in Text]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/analyze-word-frequency-in-text-372496dc-c68b-4752-b656-e32b69a3d45b 37 | -------------------------------------------------------------------------------- /Lessons/Images/buckets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Lessons/Images/buckets.png -------------------------------------------------------------------------------- /Lessons/Images/chaining.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Lessons/Images/chaining.png -------------------------------------------------------------------------------- /Lessons/Images/flower.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Lessons/Images/flower.png -------------------------------------------------------------------------------- /Lessons/Images/functionrecipe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Lessons/Images/functionrecipe.png -------------------------------------------------------------------------------- /Lessons/Images/hashfunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Lessons/Images/hashfunction.png -------------------------------------------------------------------------------- /Lessons/Images/hashtable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Lessons/Images/hashtable.png -------------------------------------------------------------------------------- /Lessons/Images/houseblueprint.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Lessons/Images/houseblueprint.jpeg -------------------------------------------------------------------------------- /Lessons/Images/linearprobing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Lessons/Images/linearprobing.png -------------------------------------------------------------------------------- /Lessons/Images/str_array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Lessons/Images/str_array.png -------------------------------------------------------------------------------- /Lessons/Images/suburbia.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Lessons/Images/suburbia.jpg -------------------------------------------------------------------------------- /Lessons/Lesson1.md: -------------------------------------------------------------------------------- 1 | 2 | # Fundamentals and OOP Review Part I 3 | 4 | [Slides](https://make-school-courses.github.io/CS-1.2-Intro-Data-Structures/Slides/Lesson1.html) 5 | 6 | 7 | 8 | ## Agenda 9 | 10 | - Check In 11 | - Review Functions & Scope 12 | - Review OOP Fundamentals 13 | - Encapsulation 14 | - Classes 15 | - Objects 16 | - Methods 17 | - Properties 18 | - Converting Functions to a Class 19 | 20 | 21 | 22 | ## Check In 23 | 24 | What are you most interested in learning in this class? 25 | 26 | 27 | 28 | ## Learning Goals 29 | 30 | - Be able to write and apply functions 31 | - Be able to write and apply OOP concepts 32 | - Understand how to convert a set of related functionality into a class 33 | 34 | 35 | 36 | ## Functions Review 37 | 38 | We can think of functions like a recipe, the inputs or parameters are the ingredients and the output is the complete sandwich 39 | 40 | ![Functions as Sandwich Recipe](Images/functionrecipe.png) 41 | 42 | 43 | 44 | ## Types of Functions 45 | 46 | We can think of dividing functions into two broad categories 47 | - Functions that take in input, process it, and return output 48 | - Functions that take in input, process it, and return None 49 | 50 | 51 | 52 | ## Types of Functions 53 | 54 | Let's do a code trace this function that returns the average of a list 55 | 56 | 57 | 58 | 59 | 60 | ## Types of Functions 61 | 62 | Let's do a code trace of this function that prints something but returns None 63 | 64 | 65 | 66 | 67 | 68 | ## Scope 69 | 70 | All variables have a scope associated with them. Think of the scope as when a given name can refer to a given variable. Scope can be passed down the chain from global (everything) to function (within a function definition) to block (within a for or if statement) 71 | 72 | 73 | 74 | ## Scope Example 75 | 76 | Think of a function as a small community 77 | 78 | 79 | 80 | 81 | 82 | ## Functions Practice 83 | 84 | Complete this exercise 85 | 86 | 87 | 88 | 89 | 90 | ## Object Oriented Programming 91 | 92 | 93 | 94 | ## Encapsulation 95 | 96 | Bundling related data and functionality together 97 | Providing an interface to access this information while hiding the details 98 | 99 | 100 | 101 | ## Classes 102 | 103 | A class is like a blueprint 104 | 105 | ![Functions as Sandwich Recipe](Images/houseblueprint.jpeg) 106 | 107 | 108 | 109 | ## Objects 110 | 111 | An object is a thing built from the blueprint 112 | 113 | ![Functions as Sandwich Recipe](Images/suburbia.jpg) 114 | 115 | 116 | 117 | ## Methods 118 | 119 | Methods are behaviors or functions defined within a class 120 | 121 | 122 | 123 | ## Properties 124 | 125 | Properties are data or variables defined within a class 126 | 127 | 128 | 129 | ## Instantiation 130 | 131 | To create a thing (object) using the blueprint (class) we use instantiation 132 | 133 | 134 | 135 | ## An Example in Python 136 | 137 | 138 | 139 | 140 | 141 | ## OOP Practice 142 | 143 | 144 | 145 | 146 | 147 | ## Shout Outs 148 | 149 | 150 | 151 | ## Learning Goals 152 | 153 | - Be able to write and apply functions 154 | - Be able to write and apply OOP concepts 155 | - Understand how to convert a set of related functionality into a class 156 | 157 | 158 | 159 | ## Lab Time 160 | 161 | -------------------------------------------------------------------------------- /Lessons/Lesson2.md: -------------------------------------------------------------------------------- 1 | 2 | # Fundamentals and OOP Review Part II 3 | 4 | [Slides](https://make-school-courses.github.io/CS-1.2-Intro-Data-Structures/Slides/Lesson2.html) 5 | 6 | 7 | 8 | ## Agenda 9 | 10 | - Check In 11 | - Intro to turtle graphics 12 | - Creating Functions 13 | - Converting Functions to a Class 14 | - Inheritance and Polymorphism 15 | 16 | 17 | 18 | ## Check In 19 | 20 | What are the biggest challenges you anticipate this term? How can Jess help you overcome them? 21 | 22 | 23 | 24 | ## Learning Goals 25 | 26 | - Be able to use turtle graphics to draw in Python 27 | - Be able to make decisions about defining functions 28 | - Be able to convert functions to classes 29 | - Understand and apply inheritance and polymorphism 30 | 31 | 32 | 33 | ## Interview Question Warmup 34 | 35 | Write a function called find_max that takes in a list of numbers and returns the max (largest) number in the list. 36 | 37 | 38 | 39 | 40 | 41 | ## Intro to Turtle Graphics 42 | 43 | Let's Draw Stuff! 44 | 45 | 46 | 47 | ## Turtle Commands 48 | 49 | - forward() 50 | - backward() 51 | - left() 52 | - right() 53 | - pencolor() 54 | - pensize() 55 | - speed() 56 | 57 | 58 | 59 | ## Turtle Graphics Code Along 60 | 61 | 62 | 63 | 64 | 65 | ## Use what we have learned so far to draw a square! 66 | 67 | 68 | 69 | 70 | 71 | ## What if we wanted to draw many squares? 72 | 73 | How can we make our code more efficient and reusable? 74 | 75 | 76 | 77 | 78 | 79 | ## How can we convert this code to a class? 80 | 81 | How can we make our code more efficient and reusable? 82 | 83 | 84 | 85 | 86 | 87 | ## OOP Inheritance 88 | 89 | Let's think about if we wanted to draw more than just squares but many shapes. What are things all shapes would have in common? 90 | 91 | 92 | 93 | ## Refactoring, creating a shapes super class 94 | 95 | 96 | 97 | 98 | 99 | ## Shout Outs 100 | 101 | 102 | 103 | ## Learning Goals 104 | 105 | - Be able to use turtle graphics to draw in Python 106 | - Be able to make decisions about defining functions 107 | - Be able to convert functions to classes 108 | - Understand and apply inheritance and polymorphism 109 | 110 | 111 | 112 | ## Lab Time 113 | 114 | Use what you have learned to create a superclass and subclass of your own -------------------------------------------------------------------------------- /Lessons/Lesson3.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Strings and File I/O Review 4 | 5 | [Slides](https://make-school-courses.github.io/CS-1.2-Intro-Data-Structures/Slides/Lesson3.html) 6 | 7 | 8 | 9 | ## Agenda 10 | - Check In 11 | - Interview Question Warmup 12 | - String Manipulation 13 | - File Input 14 | - File Output 15 | 16 | 17 | 18 | ## Check In 19 | 20 | What is one of your favorite shows you are watching right now? 21 | 22 | 23 | 24 | ## Interview Question Warm Up 25 | 26 | Create a class called Monster that takes two parameters to its __init__() method, name and color. Set up name and color as properties and then create a method called say_name() and a method called say_color() that will print out the name and color properties. Instantiate two Monster objects and call their methods. 27 | 28 | 29 | 30 | ## Learning Goals 31 | 32 | - Be able to manipulate strings 33 | - Be able to read files and handle file data 34 | - Be able to write output to files 35 | 36 | 37 | 38 | ## Strings 39 | 40 | Strings and Python lists have some things in common, and can both be thought of as a sequence of items 41 | 42 | 43 | 44 | ## Strings 45 | 46 | - You can access each character in a string using an index 47 | - Each character is itself a string 48 | - You can use the len() function to get the number of characters in a string 49 | - You can stick two strings together using the + operator 50 | 51 | 52 | 53 | 54 | ![String in Array format](Images/str_array.png) 55 | 56 | 57 | 58 | ## String Exercise 59 | 60 | Write code to print out each character in the given string, one character per line 61 | 62 | 63 | 64 | 65 | 66 | ## Common String Methods 67 | 68 | - .split() 69 | - .rstrip() 70 | - .find() 71 | - .join() 72 | 73 | Research what these methods do and then be prepared to explain in your own words 74 | 75 | 76 | 77 | ## Common String Methods 78 | 79 | 80 | 81 | 82 | 83 | ## File Input/Output (File I/O) 84 | 85 | 86 | 87 | ## Opening a file 88 | 89 | 90 | 91 | 92 | 93 | ## Reading from a file 94 | 95 | 96 | 97 | 98 | 99 | ## Using file data 100 | 101 | 102 | 103 | 104 | 105 | ## Writing to a file 106 | 107 | 108 | 109 | 110 | 111 | ## File I/O and Strings Exercise 112 | 113 | 114 | 115 | 116 | 117 | ## Shout Outs 118 | 119 | 120 | 121 | ## Lab Time 122 | 123 | -------------------------------------------------------------------------------- /Lessons/Lesson4.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Arrays 4 | 5 | [Slides](https://make-school-courses.github.io/CS-1.2-Intro-Data-Structures/Slides/Lesson4.html) 6 | 7 | 8 | 9 | ## Agenda 10 | 11 | - Check In 12 | - Interview Question Warm Up 13 | - Python Lists 14 | - Arrays in Memory 15 | - Static Arrays 16 | - Dynamic Arrays 17 | 18 | 19 | 20 | ## Check In 21 | 22 | 23 | 24 | ## Interview Question Warm Up 25 | 26 | print all the words in the words.txt file in all uppercase letters 27 | 28 | 29 | 30 | 31 | 32 | ## Lists in Python 33 | 34 | my_list = [1,"candy",4.5] 35 | - mutable 36 | - heterogeneous 37 | 38 | 39 | 40 | ## Accessing items 41 | 42 | - Index or position 43 | - Negative indexing 44 | - Slicing 45 | 46 | 47 | 48 | 49 | 50 | ## Memory Behavior 51 | 52 | - Contiguous block of memory 53 | - Think of an array as a row of mailboxes with each having a unique integer address 54 | - Same item storage size at each index 55 | 56 | 57 | 58 | 59 | ## Let's Draw It! 60 | 61 | 62 | 63 | ## The Idea of a List 64 | 65 | - Lists are used to represent an ordered collection of objects. 66 | - There are many ways to build a list 67 | - In Python lists are actually built using dynamic arrays 68 | 69 | 70 | 71 | ## Static Arrays 72 | 73 | - Static arrays are a direct representation of how memory is organized in physical RAM 74 | - Can’t change size because their memory is allocated once as a single contiguous block 75 | - However, we often do not know or cannot predict how many items we need to store... 76 | 77 | 78 | 79 | 80 | ## Let's Draw It! 81 | 82 | 83 | 84 | ## Dynamic Arrays 85 | 86 | - Dynamic arrays can change size but still have to store their items in a static array of fixed size – indexes are marked as occupied or available 87 | - When the static array is out of space we need to allocate a larger one and copy all existing items into it before we can append a new item 88 | 89 | 90 | 91 | 92 | ## Let's Draw It! 93 | 94 | 95 | 96 | ## Shout Outs 97 | 98 | 99 | 100 | ## Lab Time 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /Lessons/Lesson5.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Linked Lists 4 | 5 | [Slides](https://make-school-courses.github.io/CS-1.2-Intro-Data-Structures/Slides/Lesson5.html) 6 | 7 | 8 | 9 | ## Annoucements 10 | 11 | - Quiz 1 next Monday 12 | - Midterms next week 13 | 14 | ## Check In 15 | 16 | 17 | 18 | ## Agenda 19 | 20 | 21 | 22 | ## Interview Question Warmup 23 | 24 | What are the key differences between a static and a dynamic array? 25 | 26 | 27 | 28 | ## Lists 29 | 30 | So far we have talked about the idea of a list and two different ways to implement one 31 | 32 | - static array 33 | - dynamic array 34 | 35 | 36 | 37 | ## Linked List 38 | 39 | A Linked List is another way to implement the idea of a list. Its key different is that it is non-contiguous in memory. 40 | 41 | 42 | 43 | ## Linked List 44 | 45 | A linked list is a lot like a scavenger hunt! 46 | 47 | 48 | 49 | ## Linked List Components 50 | 51 | - Node 52 | - data 53 | - next 54 | We can think of the data as the treasure and the next as a clue to the next Node (treasure location) 55 | 56 | 57 | 58 | ## Linked List Drawing 59 | 60 | 61 | 62 | ## Linked List Starter Code 63 | 64 | Find the starter code [here](https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Code/linkedlist.py) 65 | 66 | 67 | 68 | ## Linked List vs. Arrays 69 | 70 | What are some advantages of the non-contiguous property? Some disadvantages? 71 | 72 | 73 | 74 | ## Assignment 75 | 76 | Finish the linked list starter code so that it will pass all tests in linkedlist_test.py 77 | 78 | Assignment can be found [here](Lessons/HW2.md) 79 | 80 | 81 | 82 | ## Shout Outs 83 | 84 | 85 | 86 | ## Lab Time -------------------------------------------------------------------------------- /Lessons/Lesson6.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Algorithm Analysis 4 | 5 | ➡️ [**Slides**](https://make-school-courses.github.io/CS-1.2-Intro-Data-Structures/Slides/Lesson6.html ':ignore') 6 | 7 | 8 | 9 | # Interview Question Warmup 10 | 11 | Draw the steps for an algorithm to print out all the items in a linked list 12 | 13 | 14 | 15 | # Big O Notation 16 | 17 | - O(1): constant time 18 | - O(n): linear time, increases with the input n 19 | - O(n^2): Quadratic time, increases exponentially with input n 20 | 21 | 22 | 23 | 24 | # Let's Look At Some Examples 25 | 26 | 27 | 28 | 29 | 30 | # Big O Notation 31 | 32 | We shorten Big O notation to the most significant one 33 | 34 | O(n^2) + O(n) + O(1) ---> O(n^2) 35 | 36 | 37 | 38 | # Linked List Methods 39 | 40 | - Length: get the length of the list 41 | - Append: add a node to the end of the list 42 | - Prepend: add a node to the beginning of the list 43 | - Find: find a piece of data in the list 44 | - Insert: add an item in the middle 45 | - Delete: an item from the end of the list 46 | 47 | 48 | 49 | # Let's Analyze These Methods in Terms of Big O! 50 | 51 | 52 | 53 | # Shout Outs 54 | 55 | 56 | 57 | # Lab Time 58 | 59 | 60 | -------------------------------------------------------------------------------- /Lessons/Lesson7.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Hash Tables 4 | 5 | ➡️ [**Slides**](https://make-school-courses.github.io/CS-1.2-Intro-Data-Structures/Slides/Lesson7.html ':ignore') 6 | 7 | 8 | 9 | ## Interview Question Warmup 10 | 11 | 1. Draw a linked list with 3 items: "mango", "peach", "pineapple" 12 | 2. Write pseudocode for the append method from memory 13 | 14 | 15 | 16 | ## Hash Tables 17 | 18 | - Maps keys → values (any objects) 19 | - Python’s dict() / {} type is a hash table 20 | - Used because of strong average case performance (time complexity) 21 | 22 | 23 | 24 | ## Hash Table 25 | 26 | ![Picture of a Hash Table](Images/hashtable.png) 27 | 28 | 29 | 30 | ## Hash Table Analogy 31 | 32 | Think of coat checks... 33 | 34 | 35 | 36 | ## Hash Function 37 | 38 | - Converts a variable-size input (key) to a fixed-size integer output (hash code) 39 | - Same input → same output 40 | - Input can be many types: number (int or float), string, or immutable collection 41 | 42 | 43 | 44 | ## Hash Function 45 | 46 | ![Picture of a Hash Function Mapping](Images/hashfunction.png) 47 | 48 | 49 | 50 | ## Which Bucket? 51 | 52 | - Hash function outputs are very large integers, but we want the index of a bucket 53 | - We can use the modulus operator % 54 | 55 | index = hash(key) % buckets 56 | 57 | index ranges from 0 to buckets-1 58 | 59 | 60 | 61 | ## Hash Collisions 62 | 63 | - It is impossible to map all possible inputs to a fixed output space without some inputs generating the same output (hash code) 64 | - Different inputs (keys) generating the same output (hash code) is called a hash collision 65 | 66 | 67 | 68 | ## Linear Probing 69 | 70 | - Each bucket contains at most one entry 71 | - On collision - find next open bucket, add entry there 72 | - To retrieve - find bucket, if that’s not entry, try next bucket until you find entry or empty bucket 73 | - Python’s dict uses probing 74 | 75 | 76 | 77 | ## Linear Probing 78 | 79 | ![Linear probing collision handling method](Images/linearprobing.png) 80 | 81 | 82 | 83 | ## Chaining 84 | 85 | - Each bucket contains a linked list of entries 86 | - On collision - add to the bucket’s linked list 87 | - To retrieve - find bucket, find entry in linked list 88 | - We will use chaining to implement our hash table 89 | 90 | 91 | 92 | ## Chaining 93 | 94 | ![Chaining collision handling method](Images/chaining.png) 95 | 96 | 97 | 98 | ## Challenge: Draw a Hash Table Using Chaining 99 | 100 | - Our hash table will have 4 buckets 101 | - We have 3 key value pairs to add: "red": 5, "pink": 5, "blue": 4 102 | - The hash function will be len(color) % num_buckets 103 | 104 | 105 | 106 | ## Shout Outs 107 | 108 | 109 | 110 | ## Lab Time 111 | 112 | [Hash Table Worksheet](https://docs.google.com/document/d/1O8nQjC7bbKF4M5wxoelVilJo5QYC6R0a/copy) 113 | 114 | -------------------------------------------------------------------------------- /Lessons/MarkovChains.md: -------------------------------------------------------------------------------- 1 | # Higher Order Markov Chains 2 | 3 | ## Activities 4 | - Code review implementations of hash table class instance methods 5 | - Lecture and discussion on building higher order Markov chains with larger window sizes 6 | 7 | ## Objectives 8 | After completing this class session and the associated tutorial challenges, students will be able to ... 9 | - Build higher order Markov chains based on observed frequency of *n*-grams (tuples of *n* words) in text 10 | - Generate sentences by sampling words by performing random walks on higher order Markov chain 11 | - Utilize a linked list as a queue to track words in a Markov chain's *n*-gram window 12 | 13 | ## Resources 14 | - Read Victor Powell's [visual explanation of Markov chains] and play with the interactive animated diagrams 15 | - Read Alex Dejeu's [article on how Markov chains work][Dejeu Markov article], with great examples specific to this project (especially section B, "Further Markov Model Topics" and its subsection 3, "Bigger Windows" on creating higher order Markov chains) 16 | - Read Dataiku's [article on using Markov chains with backoff][Dataiku Markov article] to generate Donald Trump and Hillary Clinton quotes 17 | - Watch Make School's [Markov chains lecture] 18 | - Review Make School's [Markov chains slides] 19 | 20 | ## Challenges 21 | These challenges are the baseline required to complete the project and course. 22 | Be sure to complete these before next class session and before starting on the stretch challenges below. 23 | - [Page 11: Markov Chains Revisited] 24 | - Build a second order Markov chain by analyzing frequency of adjacent words in text 25 | - Sample a random word from a state histogram in second order Markov chain 26 | - Generate a sentence by performing a random walk on second order Markov chain 27 | - [Page 12: Creating a Corpus] 28 | - Choose a source with at least 20,000 words (ideally, well over 100,000 words) 29 | - Collect your corpus (use Diffbot corpus collection script if needed) 30 | 31 | ## Stretch Challenges 32 | These challenges are more difficult and help you push your skills and understanding to the next level. 33 | - [Page 11: Markov Chains Revisited] 34 | - Extend code used to build second order Markov chain to build *n*-th order Markov chain for varying values of *n* (from 1 up to ~5) 35 | - Implement `MarkovChain` class to store states of word frequency histograms 36 | - Add methods for constructing state histograms and sampling words 37 | - Handle beginning and end of sentences with special start and stop tokens 38 | - Use a linked list as a queue to track words in Markov chain's *n*-gram window 39 | - Create a deque (double-ended queue) with a doubly-linked list 40 | - Implement a circular buffer (fixed-size queue) with a fixed-size array 41 | 42 | 43 | [Markov chains lecture]: https://www.youtube.com/watch?v=dNaJg-mLobQ 44 | [Markov chains slides]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Slides/MarkovChains.pdf 45 | [visual explanation of Markov chains]: http://setosa.io/blog/2014/07/26/markov-chains/ 46 | [Dejeu Markov article]: https://hackernoon.com/from-what-is-a-markov-model-to-here-is-how-markov-models-work-1ac5f4629b71 47 | [Dataiku Markov article]: https://blog.dataiku.com/2016/10/08/machine-learning-markov-chains-generate-clinton-trump-quotes 48 | [Page 11: Markov Chains Revisited]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/markov-chains-revisited 49 | [Page 12: Creating a Corpus]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/creating-a-corpus 50 | -------------------------------------------------------------------------------- /Lessons/Probability.md: -------------------------------------------------------------------------------- 1 | # [Probability & Sampling](https://docs.google.com/presentation/d/1rX0fkg-PdG_ypu4EL_cN_dDZ96UCrZkmEXeRRdT99lI/edit#slide=id.g6e846b49fc_2_76) 2 | 3 | ## Activities 4 | - Compare code quality for histogram implementations 5 | - Refactor code to improve readability, modularity, and performance 6 | - Compare tradeoffs of different histogram implementations 7 | - Watch [video of histogram comparison whiteboard activity] 8 | - Lecture and discussion following [probability and sampling slides] 9 | - Watch [video of probability and sampling lecture] 10 | 11 | ## Objectives 12 | After completing this class session and the associated tutorial challenges, students will be able to ... 13 | - Sample words according to their observed frequencies 14 | - Compare tradeoffs with different sampling techniques 15 | - Validate sampling techniques based on relative probabilities 16 | 17 | ## Challenges 18 | These challenges are the baseline required to complete the project and course. 19 | Be sure to complete these before next class session and before starting on the stretch challenges below. 20 | - [Page 4: Stochastic Sampling] 21 | - Sample words by observed frequency weighting 22 | - Test relative probabilities to validate sampling technique 23 | 24 | ## Stretch Challenges 25 | These challenges are more difficult and help you push your skills and understanding to the next level. 26 | - [Page 4: Stochastic Sampling] 27 | - Optimize for speed of sampling (read time) 28 | - Optimize for memory (use the least amount of space) 29 | - Solve with only lists and tuples 30 | - Combine other weighting techniques 31 | 32 | ## Resources 33 | - Review Make School's [probability and sampling slides] 34 | - Consult Python's [random module] documentation, but *do not* use the `random.choices` function (the challenge is to implement this yourself) 35 | - If you're *really* stuck, read the Python Cookbook's [Randomly Picking Items with Given Probabilities], but *don't read this until you've tried to solve it yourself* 36 | 37 | 38 | [video of histogram comparison whiteboard activity]: https://www.youtube.com/watch?v=w0F7gZbSoHg 39 | [video of probability and sampling lecture]: https://www.youtube.com/watch?v=-fq36v2KjR8 40 | [probability and sampling slides]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Slides/Probability.pdf 41 | [Page 4: Stochastic Sampling]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/stochastic-sampling-506e62a9-e8be-486f-8c72-486baa8c3454 42 | [random module]: https://docs.python.org/3/library/random.html 43 | [Randomly Picking Items with Given Probabilities]: https://www.safaribooksonline.com/library/view/python-cookbook-2nd/0596007973/ch04s22.html 44 | -------------------------------------------------------------------------------- /Lessons/Quiz1.md: -------------------------------------------------------------------------------- 1 | # Quiz 1 Study Guide 2 | 3 | All quizzes will be taken on [gradescope](https://www.gradescope.com/courses/131138). You will have several days in which to complete the quiz and it will be open notes. Please read the instructions carefully and show all work on your quiz. If you do not pass a quiz you will have an opportunity to retake. 4 | 5 | ## Topics 6 | - Functions 7 | - Know how to write a function from a description 8 | - Know how to call and use functions 9 | - OOP 10 | - Know how to write a class from a description 11 | - Know how to instantiate objects from a class 12 | - Know fundamental OOP vocabulary such as methods and properties 13 | - Strings 14 | - Understand how to print all the characters in a string 15 | - Understand how to use basic string methods such as split() -------------------------------------------------------------------------------- /Lessons/Quiz2.md: -------------------------------------------------------------------------------- 1 | # Quiz 2 Study Guide 2 | 3 | All quizzes will be taken on [gradescope](https://www.gradescope.com/courses/131138). You will have several days in which to complete the quiz and it will be open notes. Please read the instructions carefully and show all work on your quiz. If you do not pass a quiz you will have an opportunity to retake. 4 | 5 | ## Topics 6 | - Algorithm Analysis 7 | - Be able to analyze a code snippet in terms of time complexity (O(1), O(N), O(N^2)) and justify your answer 8 | - Linked Lists 9 | - Be able to draw how a linked list is organized in memory (refer to the [linked list worksheet](https://docs.google.com/document/d/1hdhCZtQMwFuXs6x_X5lZYjHj47cTkRnqZiFn846J-pE/copy)) 10 | - Be able to explain what each linked list method does and how it works with drawings and diagrams 11 | - append 12 | - find 13 | - prepend 14 | - length 15 | - delete 16 | - Be able to explain the time complexity of each of the above methods (refer to the [linked list time complexity worksheet](https://docs.google.com/document/d/1rkQRoTs-jbn7jqo-fPgjrpXE3Rl0hqFFHUBW7QtvCBk/copy)) and justify your answer with drawings 17 | - Hash Tables 18 | - Be able to draw a hash table (refer to the [hash table worksheet](https://docs.google.com/document/d/10W1e0Ws03bMphekNKk5XN60h4GqBdcLBnhtpIHIprlM/copy)) 19 | - Be able to explain what each hash table method does and how it works with drawings and diagrams 20 | - get 21 | - set 22 | - delete 23 | - keys 24 | - Be able to explain the time complexity of each of the above methods (refer to the [hash table time complexity worksheet](https://docs.google.com/document/d/1XuklcBhC5_hF1Kt8s25O4PmYdkuHxutkN_PIhe82Cx0/copy)) -------------------------------------------------------------------------------- /Lessons/RandomStrings.md: -------------------------------------------------------------------------------- 1 | # [Strings & Random Numbers](https://docs.google.com/presentation/d/137XVqxjeV0wYyxjPZwW3UKtaOR6R2uVYArw2-_5Qt7Q/edit#slide=id.p) 2 | 3 | ## Activity 4 | - Review prerequisite skills and knowledge 5 | - Watch [video of course and project kickoff] 6 | - Show examples of completed projects and similar websites 7 | 8 | ## Objectives 9 | After completing this class session and the associated tutorial challenges, students will be able to ... 10 | - Create Python scripts and modules 11 | - Access command-line arguments 12 | - Read files and extract lines of text 13 | - Remove whitespace from strings 14 | - Store and access elements in a list 15 | - Generate random integers in a range 16 | 17 | ## Challenges 18 | Visit Make School's [Online Academy] to find the [Tweet Generator tutorial]. 19 | 20 | These challenges are the baseline required to complete the project and course. 21 | Be sure to complete these before next class session and before starting on the stretch challenges below. 22 | - [Page 1: Let’s Get Started] 23 | - Python scripts and modules 24 | - Rearrange words script 25 | - [Page 2: Random Dictionary Words] 26 | - Generate random dictionary words 27 | - Benchmark and optimize for speed 28 | 29 | ## Stretch Challenges 30 | These challenges are more difficult and help you push your skills and understanding to the next level. They are often found in the "Where to Go From Here" section at the bottom of most tutorial pages, although a few bonus challenges are only included here. 31 | - [Page 1: Let’s Get Started] 32 | - Reverse words/sentences 33 | - Interactive mad libs game 34 | - Simple anagram generator 35 | - [Page 2: Random Dictionary Words] 36 | - Vocabulary study game 37 | - Autocomplete program 38 | - Real word anagram generator 39 | - Bonus challenges 40 | - Write a script that imitates [`cowsay`](https://en.wikipedia.org/wiki/Cowsay) – install with `brew install cowsay` 41 | - Write your own shuffle function or implement the [Fisher–Yates shuffle](https://bost.ocks.org/mike/shuffle/) 42 | 43 | ## Resources 44 | - Make School's [OOP coding challenge](http://hr.gs/ooptest) – covers classes, inheritance, and polymorphism 45 | - Code School's [Python tutorial](https://www.codeschool.com/courses/try-python) – gentle introduction with strings and conditionals 46 | - HackerRank's [Python challenges](https://www.hackerrank.com/domains/python/py-introduction) – try the basic data types and strings sections 47 | - Interview Cake's [in-place shuffle interview problem](https://www.interviewcake.com/question/python/shuffle) – with helpful detailed hints 48 | - Google's [Python class](https://developers.google.com/edu/python/) – includes lecture videos and lots of practice exercises 49 | 50 | 51 | [video of course and project kickoff]: https://www.youtube.com/watch?v=Ka4QT1OxzdI 52 | [Tweet Generator intro slides]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Slides/TweetGenerator.pdf 53 | [Online Academy]: https://www.makeschool.com/academy 54 | [Tweet Generator tutorial]: http://make.sc/oa-tweet-generator 55 | 56 | [Page 1: Let’s Get Started]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/let-s-get-started 57 | [Page 2: Random Dictionary Words]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/random-dictionary-words-0f05439f-f238-4cb7-9be4-535aefaf0f2f 58 | -------------------------------------------------------------------------------- /Lessons/RegularExpressions.md: -------------------------------------------------------------------------------- 1 | # Regular Expressions 2 | 3 | ## Activities 4 | - Code review implementations of higher order Markov chains 5 | - Review structures used to build Markov chain and discuss scalability 6 | - Lecture and discussion following [regular expressions slides] 7 | - Build and test regular expressions with [RegExr] and visualize them with [RegExper] 8 | 9 | ## Objectives 10 | After completing this class session and the associated tutorial challenges, students will be able to ... 11 | - Use regular expressions to clean up and remove junk text from corpus 12 | - Use regular expressions to create a more intelligent word tokenizer 13 | 14 | ## Resources 15 | - Watch Make School's [regular expressions lecture] 16 | - Review Make School's [regular expressions slides] 17 | - Use Cheatography's [regular expressions cheat sheet] as a reference guide 18 | - Solve interactive challenges in UBC's [regular expressions lab webpage][UBC regex lab] 19 | - Use [RegExr] or [RegEx Pal] to build and test regular expression patterns on text samples 20 | - Use [RegExper] to visualize railroad diagrams of regular expression patterns 21 | - Read StackOverflow answers to questions about using regular expressions to parse HTML: first [some comedic relief][SO match HTML tags] and then [an explanation of why you shouldn't][SO why not HTML] 22 | 23 | ## Challenges 24 | These challenges are the baseline required to complete the project and course. 25 | Be sure to complete these before next class session and before starting on the stretch challenges below. 26 | - [Page 13: Parsing Text and Clean Up] 27 | - Remove unwanted junk text (e.g., chapter titles in books, character names in scripts) 28 | - Remove unwanted punctuation (e.g., `_` or `*` characters around words) 29 | - Convert HTML character codes to ASCII equivalents (e.g., `—` to `—`) 30 | - Normalize punctuation characters (e.g., convert both types of quotes – `‘’` and `“”` – to regular quotes – `''` and `""`) 31 | - [Page 14: Tokenization] 32 | - Handle special characters (e.g., underscores, dashes, brackets, `$`, `%`, `•`, etc.) 33 | - Handle punctuation and hyphens (e.g., `Dr.`, `U.S.`, `can't`, `on-demand`, etc.) 34 | - Handle letter casing and capitalization (e.g., `turkey` and `Turkey`) 35 | 36 | ## Stretch Challenges 37 | These challenges are more difficult and help you push your skills and understanding to the next level. 38 | - [Page 13: Parsing Text and Clean Up] 39 | - Make your parser code readable, then improve its organization and modularity so that it's easy to modify in the future 40 | - Modify your parser so that it can be used as both a module (imported by another script) and as a stand-alone, executable script that, when invoked from the command line with a file argument, will print out the cleaned-up version, which can be redirected into a file 41 | - [Page 14: Tokenization] 42 | - Make your tokenizer code readable, then improve its organization and modularity so that it's easy to modify in the future 43 | - Write tests to ensure that you're getting the results you've designed for, then run your tests with controlled input data 44 | - Come up with at least one other tokenization strategy and compare performance against your original strategy, then find ways to make your tokenizer more efficient 45 | 46 | 47 | [regular expressions lecture]: https://www.youtube.com/watch?v=roUtBDH3Obc 48 | [regular expressions slides]: https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/blob/master/Slides/RegularExpressions.pdf 49 | [regular expressions cheat sheet]: https://www.cheatography.com/davechild/cheat-sheets/regular-expressions/ 50 | [UBC regex lab]: http://www.ugrad.cs.ubc.ca/~cs121/2015W1/Labs/Lab8/lab8.html 51 | [RegExr]: https://regexr.com/ 52 | [RegEx Pal]: https://www.regexpal.com/ 53 | [RegExper]: https://regexper.com/ 54 | [SO match HTML tags]: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags 55 | [SO why not HTML]: http://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-not 56 | 57 | [Page 13: Parsing Text and Clean Up]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/parsing-text-and-clean-up-969fe44d-6090-45d0-be85-c12e75cbade6 58 | [Page 14: Tokenization]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/tokenization-551b78bf-22a5-4c32-8a33-0b5f9e93a0e1 59 | -------------------------------------------------------------------------------- /Lessons/Sentences.md: -------------------------------------------------------------------------------- 1 | # [Generating Sentences](https://docs.google.com/presentation/d/1B0cYEcEK0TIcRVZB8Gy8WcxMEUL53yl5emjJTi2_KbU/edit) 2 | 3 | ## Activities 4 | - Compare histogram functions to `Dictogram` and `Listogram` class instance methods 5 | - Discuss advantages of classes and object-oriented programming (OOP) 6 | - Lecture and discussion on building Markov chains and performing random walks 7 | - Watch [video of lecture on generating sentences with Markov chains] 8 | 9 | ## Objectives 10 | After completing this class session and the associated tutorial challenges, students will be able to ... 11 | - Build Markov chains based on observed frequency of adjacent words in text 12 | - Generate sentences by sampling words by performing random walks on Markov chain 13 | 14 | ## Challenges 15 | These challenges are the baseline required to complete the project and course. 16 | Be sure to complete these before next class session and before starting on the stretch challenges below. 17 | - [Page 7: Generating Sentences] 18 | - Build a Markov chain by analyzing frequency of adjacent words in text 19 | - Sample a random word from a state histogram in a Markov chain 20 | - Generate a sentence by performing a random walk on Markov chain 21 | 22 | ## Stretch Challenges 23 | These challenges are more difficult and help you push your skills and understanding to the next level. 24 | - [Page 7: Generating Sentences] 25 | - Implement `MarkovChain` class to store states of word frequency histograms 26 | - Add methods for constructing state histograms and sampling words 27 | - Handle beginning and end of sentences with special start and stop tokens 28 | 29 | ## Resources 30 | - Read Victor Powell's [visual explanation of Markov chains] and play with the interactive animated diagrams 31 | - Read Alex Dejeu's [article on how Markov chains work][Dejeu Markov article], with great examples specific to this project (only the "Intro To Markov Models" section; we'll cover the topics in the "Further Markov Model Topics" section later in the course) 32 | 33 | [video of lecture on generating sentences with Markov chains]: https://www.youtube.com/watch?v=NcmSugXmB-g 34 | [Page 7: Generating Sentences]: https://www.makeschool.com/academy/tutorial/tweet-generator-data-structures-probability-with-python/generating-sentences-with-markov-chains 35 | [visual explanation of Markov chains]: http://setosa.io/blog/2014/07/26/markov-chains/ 36 | [Dejeu Markov article]: https://hackernoon.com/from-what-is-a-markov-model-to-here-is-how-markov-models-work-1ac5f4629b71 37 | -------------------------------------------------------------------------------- /Lessons/graphproject.md: -------------------------------------------------------------------------------- 1 | To complete the final graph project refer to these [project specs](https://docs.google.com/document/d/1KIi-KBvGkLo6epwZ36A_37yIv7QSU7u9gKbDYgXFPyw/edit?usp=sharing) and the activities we will do in class. -------------------------------------------------------------------------------- /Lessons/playlist.md: -------------------------------------------------------------------------------- 1 | # Music Playlist 🎶 2 | 3 | 4 | ## Description 5 | 6 | In this project, you will be building a music playlist builder using a linked list as the underlying data structure. Your playlist builder allows users to add new songs, remove songs, search for songs, and get the length of the playlist. 7 | 8 | ## Learning Outcomes 9 | By completing this project, you should be able to… 10 | 11 | - Create a linked list using an OOP approach 12 | - Identify the main components of a linked list 13 | - Read items in a linked list 14 | - Update items in a linked list 15 | - Search for items in a linked list 16 | 17 | 18 | ## Requirements 19 | 20 | ### Submission Requirements: 21 | 1. Your submitted code should be in a new (public) repo on Github. 22 | 1. Your repository should have a minimum of **5 commits**. 23 | 1. Your repo should include a README with the name of your project and a description. 24 | 1. Create a demo video. The demo should include a walkthrough of your code and demonstration of your project working. 25 | 1. [Optional] Upload your video to Google Drive and share a link if Gradescope upload speeds are too slow. 26 | 1. Submit the link to your repo and demo on [Gradescope](https://www.gradescope.com/courses/202248/assignments/803584). 27 | 28 | ### Assignment Requirements: 29 | 30 | Download the [starter code from here](https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/tree/master/src/PlaylistLinkedList-StarterCode), which includes: 31 | 32 | 1. `main.py` 33 | 1. `Playlist.py` 34 | 1. `Song.py` 35 | 36 | 37 | Your goals are: 38 | 39 | 1. Complete the `TODO`s in `Song.py`: 40 | - Create a getter method for the `title` attribute, called `get_title()` 41 | - Create a setter method for the `title` attribute, called `set_title()`. Make sure titles are type cased to strings and are **Title Cased**. 42 | - Create a getter method for the `next_song` attribute, called `get_next_song()` 43 | - Create a setter method for the `next_song` attribute, called `set_next_song()`. Make sure titles are type cased to strings and are Title Cased. 44 | - Using the `__str___()` dunder method, return a string of the song title. 45 | - Using the `__repr__()` dunder method, return a string formatted as the following:`'Song Title -> Next Song Title'` 46 | 47 | 2. Complete the `TODO`s in `Playlist.py`: 48 | - Create a method called `add_song()` that creates a `Song` object and adds it to the playlist. This method has one parameter called `title`. 49 | - Create a method called `find_song()` that searches for whether a song exists in the playlist and returns its index. The method has one parameter, `title`, which is the title of the song to be searched for. If the song is found, return its index. If not found, return `-1`. 50 | - Create a method called `remove_song()` that removes a song from the playlist. This method takes one parameter, `title`, which is the song that should be removed. 51 | - Create a method called `length()`, which returns the number of songs in the playlist. 52 | - Create a method called `print_songs()` that prints a numbered list of the songs in the playlist. 53 | - Test your solution by running the code in `main.py` and test all of the 5 options. 54 | 55 | 56 | 57 | ### Stretch Challenges (Optional) 58 | 1. Add a `insert_song(title, index)` method to the Playlist class that creates a new song and adds it a specified index of the linked list. 59 | 1. Add a `shuffle()` method to the Playlist class that shuffles the order of the Songs in the playlist. After, add it to the options menu in main.py 60 | 1. Add a `reverse()` method that will reverse the linked list in place. 61 | 62 | 63 | ## Rubric 64 | 65 | You can find the rubric for the Playlist project [here](https://docs.google.com/document/d/18EX0UCNB2AjkeLQ4JIh2JRq7vGynZpqk4EsJyAdgX9w/edit?usp=sharing) 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Lessons/word_freq.md: -------------------------------------------------------------------------------- 1 | # Frequency Counting with a Hash Table 📊 2 | 3 | 4 | ## Description 5 | 6 | One standard use of a hash table is counting the frequency of words in a file. For this assignment, you will use a hash table to implement a word-frequency counting program. 7 | 8 | 9 | ## Setup 10 | 11 | 🚨 Before starting the assignment, watch [How to: Setup for a New Assignment](https://youtu.be/MCbDO8IpqZM). 12 | 13 | This tutorial walks you through how to set up a new repository, make commits, and push code to Github. 14 | 15 | 16 | 17 | ## Requirements 18 | 19 | ### Submission Requirements: 20 | 1. Your submitted code should be in a new (public) repo on Github. 21 | 1. Your repository should have a minimum of **5 commits**. 22 | 1. Your repo should include a README with the name of your project and a description. 23 | 1. Create a demo video. The demo should include a walkthrough of your code and demonstration of your project working. 24 | 1. [Optional] Upload your video to Google Drive and share a link if Gradescope upload speeds are too slow. 25 | 1. Submit the link to your repo and demo on [Gradescope](https://www.gradescope.com/courses/202248/assignments/803584). 26 | 27 | ### Assignment Overview: 28 | 29 | Your program will do the following: 30 | * Count the number of occurrences of each word in the file. 31 | * Print all of the words and their frequencies. 32 | 33 | For example, a text file that contains these lines: 34 | 35 | ``` 36 | I write, erase, rewrite 37 | Erase again, and then 38 | A poppy blooms. 39 | ``` 40 | 41 | would generate this output: 42 | ``` 43 | a: 1 44 | again: 1 45 | and: 1 46 | blooms: 1 47 | erase: 2 48 | i: 1 49 | poppy: 1 50 | rewrite: 1 51 | then: 1 52 | write: 1 53 | ``` 54 | 55 | Assumptions: 56 | * The starter code handles all of the file I/O and string tokenization discussed below: 57 | * Words will be counted in a case-insensitive manner (For example, in the above example, `Erase` and `erase` are counted as the same word.) 58 | * Punctuation is ignored. You can use a delimiter to ignore the following characters: `, . ; : - ? !` 59 | * Assume that the input file consists of letter-only words (That is, the file will not have words that contain apostrophes such as `isn’t` and `‘tis`). 60 | 61 | 62 | ### Assignment Requirements: 63 | 64 | Download the [starter code from here](https://repl.it/@JoiAnderson2/Frequency-Counter-Starter-Code), which includes: 65 | 66 | [Click here to download zip file](https://repl.it/@JoiAnderson2/Frequency-Counter-Starter-Code.zip) 67 | 68 | * `main.py` 69 | * `HashTable.py` 70 | * `LinkedList.py` 71 | * `Node.py` 72 | * `example.txt` 73 | 74 | Your goals are: 75 | 76 | Complete the `TODOs` in `HashTable.py`: 77 | 78 | 1. `create_arr` - Complete the `create_arr` method in `HashTable.py`. Each element of the hash table (arr) is a linked list. This method creates an array (list) of a given size and populates each of its elements with a LinkedList object. Note: Doing `[LinkedList()] * size` does not work. 79 | 80 | 1. `hash_func` - Complete the `hash_func` method in `HashTable.py`. Create your own hash function. Hash functions are a function that turns each of these keys into an index value that we can use to decide where in our list each key:value pair should be stored. 81 | 82 | 1. `insert` - Complete the `insert` method in `HashTable.py`. Should insert a key value pair into the hash table, where the key is the word and the value is a counter for the number of times the word appeared. When inserting a new word in the hash table, be sure to check if there is a Node with the same key in the table already. 83 | 84 | 1. `print_key_values` - Complete the `print_key_values` method in `HashTable.py`. Traverse through the every Linked List in the table and print the key value pairs (formatted like the above example) 85 | 86 | 87 | 88 | ### Stretch Challenges (Optional) 89 | 1. Print the total number of distinct words at the beginning of your program. 90 | 1. Offer the user a prompt to query the exact count of a particular word. 91 | 92 | 93 | 94 | ## Rubric 95 | 96 | Coming soon. 97 | -------------------------------------------------------------------------------- /Reveal/README.md: -------------------------------------------------------------------------------- 1 | # reveal-md 2 | 3 | ## Installation: 4 | 5 | ```bash 6 | npm install -g reveal-md 7 | ``` 8 | 9 | ## Usage: 10 | 11 | ### Syntax 12 | 13 | **Slide styling:** 14 | 15 | ``` 16 | 17 | ``` 18 | 19 | **Change background color:** 20 | 21 | ``` 22 | 23 | ``` 24 | 25 | **Signal a horizontal slide transition** 26 | 27 | ``` 28 | 29 | ``` 30 | 31 | **Signal a vertical slide transition** 32 | 33 | ``` 34 | 35 | ``` 36 | 37 | ### Local Presentation 38 | 39 | This starts a local server and opens any Markdown file as a reveal.js presentation in the default browser. 40 | 41 | ```bash 42 | $ reveal-md Lessons/ 43 | ``` 44 | 45 | ### Generate Slides 46 | 47 | Generate static HTML (for GitHub Pages): 48 | 49 | ```bash 50 | $ reveal-md Lessons/ --static Slides 51 | ``` 52 | 53 | ## Resources 54 | For more information, check out the [reveal-md documentation](https://github.com/webpro/reveal-md). -------------------------------------------------------------------------------- /Reveal/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Reveal/favicon.ico -------------------------------------------------------------------------------- /Setup.md: -------------------------------------------------------------------------------- 1 | ## Repository Setup Instructions 2 | 3 | The course's *upstream* repository (located at `https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures`) contains course materials including the schedule, class topics, tutorial milestones, challenges, starter code, unit tests, slides, and links to resources. 4 | It will be updated throughout the course, so you will need to regularly *pull* from it to get new materials. 5 | (Note that you cannot *push* to the course's upstream repository.) 6 | However, you can *clone* this repo to get upstream changes and also push your code to your own repo. 7 | 8 | **Important:** 9 | Please follow these instructions *exactly* to correctly set up your clone of this repository. If you skip a step or do them out of order, it may not work. 10 | 11 | **Step 1:** 12 | Set up your local clone of this course repo on your computer. 13 | 14 | 1. **Clone** (do not *fork*) this repo from GitHub onto your local computer. 15 | 16 | - First open your terminal and navigate into the folder where you keep your course material and projects: 17 | `cd ~/MakeSchool/Courses` (or something similar for your folders) 18 | 19 | - Then run this command to *clone* the course repo: 20 | `git clone https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures.git` 21 | 22 | - Now navigate into the new folder Git just created: 23 | `cd CS-1.2-Intro-Data-Structures` 24 | 25 | 1. [**Create a new empty repo** on GitHub](https://github.com/new) also named `CS-1.2-Intro-Data-Structures` and **do not** initialize it with a ReadMe. (Creating a *new* repo instead of a *fork* allows you to earn credit towards your GitHub commit streak.) 26 | 27 | 1. **Set the `origin` remote's URL** on your local repo to point to your new repo on GitHub: 28 | `git remote set-url origin https://github.com//CS-1.2-Intro-Data-Structures.git` 29 | 30 | 1. **Push your local repo** to your *remote* GitHub repo to link your `master` branch to your `origin` remote: 31 | `git push -u origin master` 32 | 33 | 1. **Commit your code** to your local repo frequently (each time you've made meaningful progress). 34 | 35 | 1. **Push your commits** to your remote GitHub repo when you want to publish and backup your code: 36 | `git push` (the `-u` in the previous command lets you omit `origin master` afterward). 37 | 38 | **Step 2:** 39 | Connect your local clone of this course repo to the *upstream* repo on GitHub. 40 | 41 | 1. Add this course's upstream repo as another *remote* to your local repo with: 42 | `git remote add upstream https://github.com/Make-School-Courses/CS-1.2-Intro-Data-Structures.git` 43 | 44 | 1. Verify that you have two remotes: `origin` (with your username in the URL) and `upstream` (with `Make-School-Courses`): 45 | `git remote -v` 46 | 47 | 1. When you want to access new course materials, first be sure you've committed and pushed your recent work (run `git status` to check) and then *pull* from the course's upstream repo with: 48 | `git pull upstream master` 49 | 50 | **Note:** 51 | To avoid unnecessary merge conflicts when pulling changes from `upstream`, write all of your project code inside the `Code` folder and **do not** modify or delete any existing files outside of the `Code` folder that may change upstream. 52 | -------------------------------------------------------------------------------- /Slides/AlgorithmAnalysis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/AlgorithmAnalysis.pdf -------------------------------------------------------------------------------- /Slides/ArraysLinkedLists.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/ArraysLinkedLists.pdf -------------------------------------------------------------------------------- /Slides/HashTables.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/HashTables.pdf -------------------------------------------------------------------------------- /Slides/Images/buckets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Images/buckets.png -------------------------------------------------------------------------------- /Slides/Images/chaining.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Images/chaining.png -------------------------------------------------------------------------------- /Slides/Images/flower.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Images/flower.png -------------------------------------------------------------------------------- /Slides/Images/functionrecipe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Images/functionrecipe.png -------------------------------------------------------------------------------- /Slides/Images/hashfunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Images/hashfunction.png -------------------------------------------------------------------------------- /Slides/Images/hashtable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Images/hashtable.png -------------------------------------------------------------------------------- /Slides/Images/houseblueprint.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Images/houseblueprint.jpeg -------------------------------------------------------------------------------- /Slides/Images/linearprobing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Images/linearprobing.png -------------------------------------------------------------------------------- /Slides/Images/str_array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Images/str_array.png -------------------------------------------------------------------------------- /Slides/Images/suburbia.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Images/suburbia.jpg -------------------------------------------------------------------------------- /Slides/Lesson5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Syllabus Template Slides 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 |
20 |
80 |
81 | 82 | 83 | 84 | 123 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Slides/Lesson6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Syllabus Template Slides 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 |
20 |
62 |
63 | 64 | 65 | 66 | 105 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /Slides/MarkovChains.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/MarkovChains.pdf -------------------------------------------------------------------------------- /Slides/Probability.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/Probability.pdf -------------------------------------------------------------------------------- /Slides/RegularExpressions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/RegularExpressions.pdf -------------------------------------------------------------------------------- /Slides/TweetGenerator.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Slides/TweetGenerator.pdf -------------------------------------------------------------------------------- /Slides/css/highlight/zenburn.css: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Zenburn style from voldmar.ru (c) Vladimir Epifanov 4 | based on dark.css by Ivan Sagalaev 5 | 6 | */ 7 | 8 | .hljs { 9 | display: block; 10 | overflow-x: auto; 11 | padding: 0.5em; 12 | background: #3f3f3f; 13 | color: #dcdcdc; 14 | } 15 | 16 | .hljs-keyword, 17 | .hljs-selector-tag, 18 | .hljs-tag { 19 | color: #e3ceab; 20 | } 21 | 22 | .hljs-template-tag { 23 | color: #dcdcdc; 24 | } 25 | 26 | .hljs-number { 27 | color: #8cd0d3; 28 | } 29 | 30 | .hljs-variable, 31 | .hljs-template-variable, 32 | .hljs-attribute { 33 | color: #efdcbc; 34 | } 35 | 36 | .hljs-literal { 37 | color: #efefaf; 38 | } 39 | 40 | .hljs-subst { 41 | color: #8f8f8f; 42 | } 43 | 44 | .hljs-title, 45 | .hljs-name, 46 | .hljs-selector-id, 47 | .hljs-selector-class, 48 | .hljs-section, 49 | .hljs-type { 50 | color: #efef8f; 51 | } 52 | 53 | .hljs-symbol, 54 | .hljs-bullet, 55 | .hljs-link { 56 | color: #dca3a3; 57 | } 58 | 59 | .hljs-deletion, 60 | .hljs-string, 61 | .hljs-built_in, 62 | .hljs-builtin-name { 63 | color: #cc9393; 64 | } 65 | 66 | .hljs-addition, 67 | .hljs-comment, 68 | .hljs-quote, 69 | .hljs-meta { 70 | color: #7f9f7f; 71 | } 72 | 73 | 74 | .hljs-emphasis { 75 | font-style: italic; 76 | } 77 | 78 | .hljs-strong { 79 | font-weight: bold; 80 | } 81 | -------------------------------------------------------------------------------- /Slides/css/print/pdf.css: -------------------------------------------------------------------------------- 1 | /** 2 | * This stylesheet is used to print reveal.js 3 | * presentations to PDF. 4 | * 5 | * https://github.com/hakimel/reveal.js#pdf-export 6 | */ 7 | 8 | * { 9 | -webkit-print-color-adjust: exact; 10 | } 11 | 12 | body { 13 | margin: 0 auto !important; 14 | border: 0; 15 | padding: 0; 16 | float: none !important; 17 | overflow: visible; 18 | } 19 | 20 | html { 21 | width: 100%; 22 | height: 100%; 23 | overflow: visible; 24 | } 25 | 26 | /* Remove any elements not needed in print. */ 27 | .nestedarrow, 28 | .reveal .controls, 29 | .reveal .progress, 30 | .reveal .playback, 31 | .reveal.overview, 32 | .fork-reveal, 33 | .share-reveal, 34 | .state-background { 35 | display: none !important; 36 | } 37 | 38 | h1, h2, h3, h4, h5, h6 { 39 | text-shadow: 0 0 0 #000 !important; 40 | } 41 | 42 | .reveal pre code { 43 | overflow: hidden !important; 44 | font-family: Courier, 'Courier New', monospace !important; 45 | } 46 | 47 | ul, ol, div, p { 48 | visibility: visible; 49 | position: static; 50 | width: auto; 51 | height: auto; 52 | display: block; 53 | overflow: visible; 54 | margin: auto; 55 | } 56 | .reveal { 57 | width: auto !important; 58 | height: auto !important; 59 | overflow: hidden !important; 60 | } 61 | .reveal .slides { 62 | position: static; 63 | width: 100% !important; 64 | height: auto !important; 65 | zoom: 1 !important; 66 | 67 | left: auto; 68 | top: auto; 69 | margin: 0 !important; 70 | padding: 0 !important; 71 | 72 | overflow: visible; 73 | display: block; 74 | 75 | perspective: none; 76 | perspective-origin: 50% 50%; 77 | } 78 | 79 | .reveal .slides .pdf-page { 80 | position: relative; 81 | overflow: hidden; 82 | z-index: 1; 83 | 84 | page-break-after: always; 85 | } 86 | 87 | .reveal .slides section { 88 | visibility: visible !important; 89 | display: block !important; 90 | position: absolute !important; 91 | 92 | margin: 0 !important; 93 | padding: 0 !important; 94 | box-sizing: border-box !important; 95 | min-height: 1px; 96 | 97 | opacity: 1 !important; 98 | 99 | transform-style: flat !important; 100 | transform: none !important; 101 | } 102 | 103 | .reveal section.stack { 104 | position: relative !important; 105 | margin: 0 !important; 106 | padding: 0 !important; 107 | page-break-after: avoid !important; 108 | height: auto !important; 109 | min-height: auto !important; 110 | } 111 | 112 | .reveal img { 113 | box-shadow: none; 114 | } 115 | 116 | .reveal .roll { 117 | overflow: visible; 118 | line-height: 1em; 119 | } 120 | 121 | /* Slide backgrounds are placed inside of their slide when exporting to PDF */ 122 | .reveal .slide-background { 123 | display: block !important; 124 | position: absolute; 125 | top: 0; 126 | left: 0; 127 | width: 100%; 128 | height: 100%; 129 | z-index: auto !important; 130 | } 131 | 132 | /* Display slide speaker notes when 'showNotes' is enabled */ 133 | .reveal.show-notes { 134 | max-width: none; 135 | max-height: none; 136 | } 137 | .reveal .speaker-notes-pdf { 138 | display: block; 139 | width: 100%; 140 | height: auto; 141 | max-height: none; 142 | top: auto; 143 | right: auto; 144 | bottom: auto; 145 | left: auto; 146 | z-index: 100; 147 | } 148 | 149 | /* Layout option which makes notes appear on a separate page */ 150 | .reveal .speaker-notes-pdf[data-layout="separate-page"] { 151 | position: relative; 152 | color: inherit; 153 | background-color: transparent; 154 | padding: 20px; 155 | page-break-after: always; 156 | border: 0; 157 | } 158 | 159 | /* Display slide numbers when 'slideNumber' is enabled */ 160 | .reveal .slide-number-pdf { 161 | display: block; 162 | position: absolute; 163 | font-size: 14px; 164 | } 165 | -------------------------------------------------------------------------------- /Slides/css/reset.css: -------------------------------------------------------------------------------- 1 | /* http://meyerweb.com/eric/tools/css/reset/ 2 | v4.0 | 20180602 3 | License: none (public domain) 4 | */ 5 | 6 | html, body, div, span, applet, object, iframe, 7 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 8 | a, abbr, acronym, address, big, cite, code, 9 | del, dfn, em, img, ins, kbd, q, s, samp, 10 | small, strike, strong, sub, sup, tt, var, 11 | b, u, i, center, 12 | dl, dt, dd, ol, ul, li, 13 | fieldset, form, label, legend, 14 | table, caption, tbody, tfoot, thead, tr, th, td, 15 | article, aside, canvas, details, embed, 16 | figure, figcaption, footer, header, hgroup, 17 | main, menu, nav, output, ruby, section, summary, 18 | time, mark, audio, video { 19 | margin: 0; 20 | padding: 0; 21 | border: 0; 22 | font-size: 100%; 23 | font: inherit; 24 | vertical-align: baseline; 25 | } 26 | /* HTML5 display-role reset for older browsers */ 27 | article, aside, details, figcaption, figure, 28 | footer, header, hgroup, main, menu, nav, section { 29 | display: block; 30 | } -------------------------------------------------------------------------------- /Slides/css/theme/README.md: -------------------------------------------------------------------------------- 1 | ## Dependencies 2 | 3 | Themes are written using Sass to keep things modular and reduce the need for repeated selectors across files. Make sure that you have the reveal.js development environment including the Grunt dependencies installed before proceeding: https://github.com/hakimel/reveal.js#full-setup 4 | 5 | ## Creating a Theme 6 | 7 | To create your own theme, start by duplicating a ```.scss``` file in [/css/theme/source](https://github.com/hakimel/reveal.js/blob/master/css/theme/source). It will be automatically compiled by Grunt from Sass to CSS (see the [Gruntfile](https://github.com/hakimel/reveal.js/blob/master/gruntfile.js)) when you run `npm run build -- css-themes`. 8 | 9 | Each theme file does four things in the following order: 10 | 11 | 1. **Include [/css/theme/template/mixins.scss](https://github.com/hakimel/reveal.js/blob/master/css/theme/template/mixins.scss)** 12 | Shared utility functions. 13 | 14 | 2. **Include [/css/theme/template/settings.scss](https://github.com/hakimel/reveal.js/blob/master/css/theme/template/settings.scss)** 15 | Declares a set of custom variables that the template file (step 4) expects. Can be overridden in step 3. 16 | 17 | 3. **Override** 18 | This is where you override the default theme. Either by specifying variables (see [settings.scss](https://github.com/hakimel/reveal.js/blob/master/css/theme/template/settings.scss) for reference) or by adding any selectors and styles you please. 19 | 20 | 4. **Include [/css/theme/template/theme.scss](https://github.com/hakimel/reveal.js/blob/master/css/theme/template/theme.scss)** 21 | The template theme file which will generate final CSS output based on the currently defined variables. 22 | -------------------------------------------------------------------------------- /Slides/css/theme/source/beige.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Beige theme for reveal.js. 3 | * 4 | * Copyright (C) 2011-2012 Hakim El Hattab, http://hakim.se 5 | */ 6 | 7 | 8 | // Default mixins and settings ----------------- 9 | @import "../template/mixins"; 10 | @import "../template/settings"; 11 | // --------------------------------------------- 12 | 13 | 14 | 15 | // Include theme-specific fonts 16 | @import url(../../lib/font/league-gothic/league-gothic.css); 17 | @import url(https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic); 18 | 19 | 20 | // Override theme settings (see ../template/settings.scss) 21 | $mainColor: #333; 22 | $headingColor: #333; 23 | $headingTextShadow: none; 24 | $backgroundColor: #f7f3de; 25 | $linkColor: #8b743d; 26 | $linkColorHover: lighten( $linkColor, 20% ); 27 | $selectionBackgroundColor: rgba(79, 64, 28, 0.99); 28 | $heading1TextShadow: 0 1px 0 #ccc, 0 2px 0 #c9c9c9, 0 3px 0 #bbb, 0 4px 0 #b9b9b9, 0 5px 0 #aaa, 0 6px 1px rgba(0,0,0,.1), 0 0 5px rgba(0,0,0,.1), 0 1px 3px rgba(0,0,0,.3), 0 3px 5px rgba(0,0,0,.2), 0 5px 10px rgba(0,0,0,.25), 0 20px 20px rgba(0,0,0,.15); 29 | 30 | // Background generator 31 | @mixin bodyBackground() { 32 | @include radial-gradient( rgba(247,242,211,1), rgba(255,255,255,1) ); 33 | } 34 | 35 | 36 | 37 | // Theme template ------------------------------ 38 | @import "../template/theme"; 39 | // --------------------------------------------- -------------------------------------------------------------------------------- /Slides/css/theme/source/black.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Black theme for reveal.js. This is the opposite of the 'white' theme. 3 | * 4 | * By Hakim El Hattab, http://hakim.se 5 | */ 6 | 7 | 8 | // Default mixins and settings ----------------- 9 | @import "../template/mixins"; 10 | @import "../template/settings"; 11 | // --------------------------------------------- 12 | 13 | 14 | // Include theme-specific fonts 15 | @import url(../../lib/font/source-sans-pro/source-sans-pro.css); 16 | 17 | 18 | // Override theme settings (see ../template/settings.scss) 19 | $backgroundColor: #191919; 20 | 21 | $mainColor: #fff; 22 | $headingColor: #fff; 23 | 24 | $mainFontSize: 42px; 25 | $mainFont: 'Source Sans Pro', Helvetica, sans-serif; 26 | $headingFont: 'Source Sans Pro', Helvetica, sans-serif; 27 | $headingTextShadow: none; 28 | $headingLetterSpacing: normal; 29 | $headingTextTransform: uppercase; 30 | $headingFontWeight: 600; 31 | $linkColor: #42affa; 32 | $linkColorHover: lighten( $linkColor, 15% ); 33 | $selectionBackgroundColor: lighten( $linkColor, 25% ); 34 | 35 | $heading1Size: 2.5em; 36 | $heading2Size: 1.6em; 37 | $heading3Size: 1.3em; 38 | $heading4Size: 1.0em; 39 | 40 | section.has-light-background { 41 | &, h1, h2, h3, h4, h5, h6 { 42 | color: #222; 43 | } 44 | } 45 | 46 | 47 | // Theme template ------------------------------ 48 | @import "../template/theme"; 49 | // --------------------------------------------- -------------------------------------------------------------------------------- /Slides/css/theme/source/blood.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Blood theme for reveal.js 3 | * Author: Walther http://github.com/Walther 4 | * 5 | * Designed to be used with highlight.js theme 6 | * "monokai_sublime.css" available from 7 | * https://github.com/isagalaev/highlight.js/ 8 | * 9 | * For other themes, change $codeBackground accordingly. 10 | * 11 | */ 12 | 13 | // Default mixins and settings ----------------- 14 | @import "../template/mixins"; 15 | @import "../template/settings"; 16 | // --------------------------------------------- 17 | 18 | // Include theme-specific fonts 19 | 20 | @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,700,300italic,700italic); 21 | 22 | // Colors used in the theme 23 | $blood: #a23; 24 | $coal: #222; 25 | $codeBackground: #23241f; 26 | 27 | $backgroundColor: $coal; 28 | 29 | // Main text 30 | $mainFont: Ubuntu, 'sans-serif'; 31 | $mainColor: #eee; 32 | 33 | // Headings 34 | $headingFont: Ubuntu, 'sans-serif'; 35 | $headingTextShadow: 2px 2px 2px $coal; 36 | 37 | // h1 shadow, borrowed humbly from 38 | // (c) Default theme by Hakim El Hattab 39 | $heading1TextShadow: 0 1px 0 #ccc, 0 2px 0 #c9c9c9, 0 3px 0 #bbb, 0 4px 0 #b9b9b9, 0 5px 0 #aaa, 0 6px 1px rgba(0,0,0,.1), 0 0 5px rgba(0,0,0,.1), 0 1px 3px rgba(0,0,0,.3), 0 3px 5px rgba(0,0,0,.2), 0 5px 10px rgba(0,0,0,.25), 0 20px 20px rgba(0,0,0,.15); 40 | 41 | // Links 42 | $linkColor: $blood; 43 | $linkColorHover: lighten( $linkColor, 20% ); 44 | 45 | // Text selection 46 | $selectionBackgroundColor: $blood; 47 | $selectionColor: #fff; 48 | 49 | 50 | // Theme template ------------------------------ 51 | @import "../template/theme"; 52 | // --------------------------------------------- 53 | 54 | // some overrides after theme template import 55 | 56 | .reveal p { 57 | font-weight: 300; 58 | text-shadow: 1px 1px $coal; 59 | } 60 | 61 | .reveal h1, 62 | .reveal h2, 63 | .reveal h3, 64 | .reveal h4, 65 | .reveal h5, 66 | .reveal h6 { 67 | font-weight: 700; 68 | } 69 | 70 | .reveal p code { 71 | background-color: $codeBackground; 72 | display: inline-block; 73 | border-radius: 7px; 74 | } 75 | 76 | .reveal small code { 77 | vertical-align: baseline; 78 | } -------------------------------------------------------------------------------- /Slides/css/theme/source/league.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * League theme for reveal.js. 3 | * 4 | * This was the default theme pre-3.0.0. 5 | * 6 | * Copyright (C) 2011-2012 Hakim El Hattab, http://hakim.se 7 | */ 8 | 9 | 10 | // Default mixins and settings ----------------- 11 | @import "../template/mixins"; 12 | @import "../template/settings"; 13 | // --------------------------------------------- 14 | 15 | 16 | 17 | // Include theme-specific fonts 18 | @import url(../../lib/font/league-gothic/league-gothic.css); 19 | @import url(https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic); 20 | 21 | // Override theme settings (see ../template/settings.scss) 22 | $headingTextShadow: 0px 0px 6px rgba(0,0,0,0.2); 23 | $heading1TextShadow: 0 1px 0 #ccc, 0 2px 0 #c9c9c9, 0 3px 0 #bbb, 0 4px 0 #b9b9b9, 0 5px 0 #aaa, 0 6px 1px rgba(0,0,0,.1), 0 0 5px rgba(0,0,0,.1), 0 1px 3px rgba(0,0,0,.3), 0 3px 5px rgba(0,0,0,.2), 0 5px 10px rgba(0,0,0,.25), 0 20px 20px rgba(0,0,0,.15); 24 | 25 | // Background generator 26 | @mixin bodyBackground() { 27 | @include radial-gradient( rgba(28,30,32,1), rgba(85,90,95,1) ); 28 | } 29 | 30 | 31 | 32 | // Theme template ------------------------------ 33 | @import "../template/theme"; 34 | // --------------------------------------------- -------------------------------------------------------------------------------- /Slides/css/theme/source/moon.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Solarized Dark theme for reveal.js. 3 | * Author: Achim Staebler 4 | */ 5 | 6 | 7 | // Default mixins and settings ----------------- 8 | @import "../template/mixins"; 9 | @import "../template/settings"; 10 | // --------------------------------------------- 11 | 12 | 13 | 14 | // Include theme-specific fonts 15 | @import url(../../lib/font/league-gothic/league-gothic.css); 16 | @import url(https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic); 17 | 18 | /** 19 | * Solarized colors by Ethan Schoonover 20 | */ 21 | html * { 22 | color-profile: sRGB; 23 | rendering-intent: auto; 24 | } 25 | 26 | // Solarized colors 27 | $base03: #002b36; 28 | $base02: #073642; 29 | $base01: #586e75; 30 | $base00: #657b83; 31 | $base0: #839496; 32 | $base1: #93a1a1; 33 | $base2: #eee8d5; 34 | $base3: #fdf6e3; 35 | $yellow: #b58900; 36 | $orange: #cb4b16; 37 | $red: #dc322f; 38 | $magenta: #d33682; 39 | $violet: #6c71c4; 40 | $blue: #268bd2; 41 | $cyan: #2aa198; 42 | $green: #859900; 43 | 44 | // Override theme settings (see ../template/settings.scss) 45 | $mainColor: $base1; 46 | $headingColor: $base2; 47 | $headingTextShadow: none; 48 | $backgroundColor: $base03; 49 | $linkColor: $blue; 50 | $linkColorHover: lighten( $linkColor, 20% ); 51 | $selectionBackgroundColor: $magenta; 52 | 53 | 54 | 55 | // Theme template ------------------------------ 56 | @import "../template/theme"; 57 | // --------------------------------------------- 58 | -------------------------------------------------------------------------------- /Slides/css/theme/source/night.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Black theme for reveal.js. 3 | * 4 | * Copyright (C) 2011-2012 Hakim El Hattab, http://hakim.se 5 | */ 6 | 7 | 8 | // Default mixins and settings ----------------- 9 | @import "../template/mixins"; 10 | @import "../template/settings"; 11 | // --------------------------------------------- 12 | 13 | 14 | // Include theme-specific fonts 15 | @import url(https://fonts.googleapis.com/css?family=Montserrat:700); 16 | @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic,700italic); 17 | 18 | 19 | // Override theme settings (see ../template/settings.scss) 20 | $backgroundColor: #111; 21 | 22 | $mainFont: 'Open Sans', sans-serif; 23 | $linkColor: #e7ad52; 24 | $linkColorHover: lighten( $linkColor, 20% ); 25 | $headingFont: 'Montserrat', Impact, sans-serif; 26 | $headingTextShadow: none; 27 | $headingLetterSpacing: -0.03em; 28 | $headingTextTransform: none; 29 | $selectionBackgroundColor: #e7ad52; 30 | 31 | 32 | // Theme template ------------------------------ 33 | @import "../template/theme"; 34 | // --------------------------------------------- -------------------------------------------------------------------------------- /Slides/css/theme/source/serif.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * A simple theme for reveal.js presentations, similar 3 | * to the default theme. The accent color is brown. 4 | * 5 | * This theme is Copyright (C) 2012-2013 Owen Versteeg, http://owenversteeg.com - it is MIT licensed. 6 | */ 7 | 8 | 9 | // Default mixins and settings ----------------- 10 | @import "../template/mixins"; 11 | @import "../template/settings"; 12 | // --------------------------------------------- 13 | 14 | 15 | 16 | // Override theme settings (see ../template/settings.scss) 17 | $mainFont: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif; 18 | $mainColor: #000; 19 | $headingFont: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif; 20 | $headingColor: #383D3D; 21 | $headingTextShadow: none; 22 | $headingTextTransform: none; 23 | $backgroundColor: #F0F1EB; 24 | $linkColor: #51483D; 25 | $linkColorHover: lighten( $linkColor, 20% ); 26 | $selectionBackgroundColor: #26351C; 27 | 28 | .reveal a { 29 | line-height: 1.3em; 30 | } 31 | 32 | 33 | // Theme template ------------------------------ 34 | @import "../template/theme"; 35 | // --------------------------------------------- 36 | -------------------------------------------------------------------------------- /Slides/css/theme/source/simple.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * A simple theme for reveal.js presentations, similar 3 | * to the default theme. The accent color is darkblue. 4 | * 5 | * This theme is Copyright (C) 2012 Owen Versteeg, https://github.com/StereotypicalApps. It is MIT licensed. 6 | * reveal.js is Copyright (C) 2011-2012 Hakim El Hattab, http://hakim.se 7 | */ 8 | 9 | 10 | // Default mixins and settings ----------------- 11 | @import "../template/mixins"; 12 | @import "../template/settings"; 13 | // --------------------------------------------- 14 | 15 | 16 | 17 | // Include theme-specific fonts 18 | @import url(https://fonts.googleapis.com/css?family=News+Cycle:400,700); 19 | @import url(https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic); 20 | 21 | 22 | // Override theme settings (see ../template/settings.scss) 23 | $mainFont: 'Lato', sans-serif; 24 | $mainColor: #000; 25 | $headingFont: 'News Cycle', Impact, sans-serif; 26 | $headingColor: #000; 27 | $headingTextShadow: none; 28 | $headingTextTransform: none; 29 | $backgroundColor: #fff; 30 | $linkColor: #00008B; 31 | $linkColorHover: lighten( $linkColor, 20% ); 32 | $selectionBackgroundColor: rgba(0, 0, 0, 0.99); 33 | 34 | section.has-dark-background { 35 | &, h1, h2, h3, h4, h5, h6 { 36 | color: #fff; 37 | } 38 | } 39 | 40 | 41 | // Theme template ------------------------------ 42 | @import "../template/theme"; 43 | // --------------------------------------------- -------------------------------------------------------------------------------- /Slides/css/theme/source/sky.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Sky theme for reveal.js. 3 | * 4 | * Copyright (C) 2011-2012 Hakim El Hattab, http://hakim.se 5 | */ 6 | 7 | 8 | // Default mixins and settings ----------------- 9 | @import "../template/mixins"; 10 | @import "../template/settings"; 11 | // --------------------------------------------- 12 | 13 | 14 | 15 | // Include theme-specific fonts 16 | @import url(https://fonts.googleapis.com/css?family=Quicksand:400,700,400italic,700italic); 17 | @import url(https://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700); 18 | 19 | 20 | // Override theme settings (see ../template/settings.scss) 21 | $mainFont: 'Open Sans', sans-serif; 22 | $mainColor: #333; 23 | $headingFont: 'Quicksand', sans-serif; 24 | $headingColor: #333; 25 | $headingLetterSpacing: -0.08em; 26 | $headingTextShadow: none; 27 | $backgroundColor: #f7fbfc; 28 | $linkColor: #3b759e; 29 | $linkColorHover: lighten( $linkColor, 20% ); 30 | $selectionBackgroundColor: #134674; 31 | 32 | // Fix links so they are not cut off 33 | .reveal a { 34 | line-height: 1.3em; 35 | } 36 | 37 | // Background generator 38 | @mixin bodyBackground() { 39 | @include radial-gradient( #add9e4, #f7fbfc ); 40 | } 41 | 42 | 43 | 44 | // Theme template ------------------------------ 45 | @import "../template/theme"; 46 | // --------------------------------------------- 47 | -------------------------------------------------------------------------------- /Slides/css/theme/source/solarized.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Solarized Light theme for reveal.js. 3 | * Author: Achim Staebler 4 | */ 5 | 6 | 7 | // Default mixins and settings ----------------- 8 | @import "../template/mixins"; 9 | @import "../template/settings"; 10 | // --------------------------------------------- 11 | 12 | 13 | 14 | // Include theme-specific fonts 15 | @import url(../../lib/font/league-gothic/league-gothic.css); 16 | @import url(https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic); 17 | 18 | 19 | /** 20 | * Solarized colors by Ethan Schoonover 21 | */ 22 | html * { 23 | color-profile: sRGB; 24 | rendering-intent: auto; 25 | } 26 | 27 | // Solarized colors 28 | $base03: #002b36; 29 | $base02: #073642; 30 | $base01: #586e75; 31 | $base00: #657b83; 32 | $base0: #839496; 33 | $base1: #93a1a1; 34 | $base2: #eee8d5; 35 | $base3: #fdf6e3; 36 | $yellow: #b58900; 37 | $orange: #cb4b16; 38 | $red: #dc322f; 39 | $magenta: #d33682; 40 | $violet: #6c71c4; 41 | $blue: #268bd2; 42 | $cyan: #2aa198; 43 | $green: #859900; 44 | 45 | // Override theme settings (see ../template/settings.scss) 46 | $mainColor: $base00; 47 | $headingColor: $base01; 48 | $headingTextShadow: none; 49 | $backgroundColor: $base3; 50 | $linkColor: $blue; 51 | $linkColorHover: lighten( $linkColor, 20% ); 52 | $selectionBackgroundColor: $magenta; 53 | 54 | // Background generator 55 | // @mixin bodyBackground() { 56 | // @include radial-gradient( rgba($base3,1), rgba(lighten($base3, 20%),1) ); 57 | // } 58 | 59 | 60 | 61 | // Theme template ------------------------------ 62 | @import "../template/theme"; 63 | // --------------------------------------------- 64 | -------------------------------------------------------------------------------- /Slides/css/theme/source/white.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * White theme for reveal.js. This is the opposite of the 'black' theme. 3 | * 4 | * By Hakim El Hattab, http://hakim.se 5 | */ 6 | 7 | 8 | // Default mixins and settings ----------------- 9 | @import "../template/mixins"; 10 | @import "../template/settings"; 11 | // --------------------------------------------- 12 | 13 | 14 | // Include theme-specific fonts 15 | @import url(../../lib/font/source-sans-pro/source-sans-pro.css); 16 | 17 | 18 | // Override theme settings (see ../template/settings.scss) 19 | $backgroundColor: #fff; 20 | 21 | $mainColor: #222; 22 | $headingColor: #222; 23 | 24 | $mainFontSize: 42px; 25 | $mainFont: 'Source Sans Pro', Helvetica, sans-serif; 26 | $headingFont: 'Source Sans Pro', Helvetica, sans-serif; 27 | $headingTextShadow: none; 28 | $headingLetterSpacing: normal; 29 | $headingTextTransform: uppercase; 30 | $headingFontWeight: 600; 31 | $linkColor: #2a76dd; 32 | $linkColorHover: lighten( $linkColor, 15% ); 33 | $selectionBackgroundColor: lighten( $linkColor, 25% ); 34 | 35 | $heading1Size: 2.5em; 36 | $heading2Size: 1.6em; 37 | $heading3Size: 1.3em; 38 | $heading4Size: 1.0em; 39 | 40 | section.has-dark-background { 41 | &, h1, h2, h3, h4, h5, h6 { 42 | color: #fff; 43 | } 44 | } 45 | 46 | 47 | // Theme template ------------------------------ 48 | @import "../template/theme"; 49 | // --------------------------------------------- -------------------------------------------------------------------------------- /Slides/css/theme/template/mixins.scss: -------------------------------------------------------------------------------- 1 | @mixin vertical-gradient( $top, $bottom ) { 2 | background: $top; 3 | background: -moz-linear-gradient( top, $top 0%, $bottom 100% ); 4 | background: -webkit-gradient( linear, left top, left bottom, color-stop(0%,$top), color-stop(100%,$bottom) ); 5 | background: -webkit-linear-gradient( top, $top 0%, $bottom 100% ); 6 | background: -o-linear-gradient( top, $top 0%, $bottom 100% ); 7 | background: -ms-linear-gradient( top, $top 0%, $bottom 100% ); 8 | background: linear-gradient( top, $top 0%, $bottom 100% ); 9 | } 10 | 11 | @mixin horizontal-gradient( $top, $bottom ) { 12 | background: $top; 13 | background: -moz-linear-gradient( left, $top 0%, $bottom 100% ); 14 | background: -webkit-gradient( linear, left top, right top, color-stop(0%,$top), color-stop(100%,$bottom) ); 15 | background: -webkit-linear-gradient( left, $top 0%, $bottom 100% ); 16 | background: -o-linear-gradient( left, $top 0%, $bottom 100% ); 17 | background: -ms-linear-gradient( left, $top 0%, $bottom 100% ); 18 | background: linear-gradient( left, $top 0%, $bottom 100% ); 19 | } 20 | 21 | @mixin radial-gradient( $outer, $inner, $type: circle ) { 22 | background: $outer; 23 | background: -moz-radial-gradient( center, $type cover, $inner 0%, $outer 100% ); 24 | background: -webkit-gradient( radial, center center, 0px, center center, 100%, color-stop(0%,$inner), color-stop(100%,$outer) ); 25 | background: -webkit-radial-gradient( center, $type cover, $inner 0%, $outer 100% ); 26 | background: -o-radial-gradient( center, $type cover, $inner 0%, $outer 100% ); 27 | background: -ms-radial-gradient( center, $type cover, $inner 0%, $outer 100% ); 28 | background: radial-gradient( center, $type cover, $inner 0%, $outer 100% ); 29 | } -------------------------------------------------------------------------------- /Slides/css/theme/template/settings.scss: -------------------------------------------------------------------------------- 1 | // Base settings for all themes that can optionally be 2 | // overridden by the super-theme 3 | 4 | // Background of the presentation 5 | $backgroundColor: #2b2b2b; 6 | 7 | // Primary/body text 8 | $mainFont: 'Lato', sans-serif; 9 | $mainFontSize: 40px; 10 | $mainColor: #eee; 11 | 12 | // Vertical spacing between blocks of text 13 | $blockMargin: 20px; 14 | 15 | // Headings 16 | $headingMargin: 0 0 $blockMargin 0; 17 | $headingFont: 'League Gothic', Impact, sans-serif; 18 | $headingColor: #eee; 19 | $headingLineHeight: 1.2; 20 | $headingLetterSpacing: normal; 21 | $headingTextTransform: uppercase; 22 | $headingTextShadow: none; 23 | $headingFontWeight: normal; 24 | $heading1TextShadow: $headingTextShadow; 25 | 26 | $heading1Size: 3.77em; 27 | $heading2Size: 2.11em; 28 | $heading3Size: 1.55em; 29 | $heading4Size: 1.00em; 30 | 31 | $codeFont: monospace; 32 | 33 | // Links and actions 34 | $linkColor: #13DAEC; 35 | $linkColorHover: lighten( $linkColor, 20% ); 36 | 37 | // Text selection 38 | $selectionBackgroundColor: #FF5E99; 39 | $selectionColor: #fff; 40 | 41 | // Generates the presentation background, can be overridden 42 | // to return a background image or gradient 43 | @mixin bodyBackground() { 44 | background: $backgroundColor; 45 | } 46 | -------------------------------------------------------------------------------- /Slides/index.html: -------------------------------------------------------------------------------- 1 | Lesson1.html -------------------------------------------------------------------------------- /Slides/plugin/markdown/example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | reveal.js - Markdown Demo 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 |
20 | 21 | 22 |
23 | 24 | 25 |
26 | 36 |
37 | 38 | 39 |
40 | 54 |
55 | 56 | 57 |
58 | 69 |
70 | 71 | 72 |
73 | 77 |
78 | 79 | 80 |
81 | 86 |
87 | 88 | 89 |
90 | 100 |
101 | 102 | 103 |
104 | 107 |
108 | 109 |
110 |
111 | 112 | 113 | 114 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /Slides/plugin/markdown/example.md: -------------------------------------------------------------------------------- 1 | # Markdown Demo 2 | 3 | 4 | 5 | ## External 1.1 6 | 7 | Content 1.1 8 | 9 | Note: This will only appear in the speaker notes window. 10 | 11 | 12 | ## External 1.2 13 | 14 | Content 1.2 15 | 16 | 17 | 18 | ## External 2 19 | 20 | Content 2.1 21 | 22 | 23 | 24 | ## External 3.1 25 | 26 | Content 3.1 27 | 28 | 29 | ## External 3.2 30 | 31 | Content 3.2 32 | 33 | 34 | ## External 3.3 35 | 36 | ![External Image](https://s3.amazonaws.com/static.slid.es/logo/v2/slides-symbol-512x512.png) 37 | -------------------------------------------------------------------------------- /Slides/plugin/math/math.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A plugin which enables rendering of math equations inside 3 | * of reveal.js slides. Essentially a thin wrapper for MathJax. 4 | * 5 | * @author Hakim El Hattab 6 | */ 7 | var RevealMath = window.RevealMath || (function(){ 8 | 9 | var options = Reveal.getConfig().math || {}; 10 | var mathjax = options.mathjax || 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js'; 11 | var config = options.config || 'TeX-AMS_HTML-full'; 12 | var url = mathjax + '?config=' + config; 13 | 14 | var defaultOptions = { 15 | messageStyle: 'none', 16 | tex2jax: { 17 | inlineMath: [ [ '$', '$' ], [ '\\(', '\\)' ] ], 18 | skipTags: [ 'script', 'noscript', 'style', 'textarea', 'pre' ] 19 | }, 20 | skipStartupTypeset: true 21 | }; 22 | 23 | function defaults( options, defaultOptions ) { 24 | 25 | for ( var i in defaultOptions ) { 26 | if ( !options.hasOwnProperty( i ) ) { 27 | options[i] = defaultOptions[i]; 28 | } 29 | } 30 | 31 | } 32 | 33 | function loadScript( url, callback ) { 34 | 35 | var head = document.querySelector( 'head' ); 36 | var script = document.createElement( 'script' ); 37 | script.type = 'text/javascript'; 38 | script.src = url; 39 | 40 | // Wrapper for callback to make sure it only fires once 41 | var finish = function() { 42 | if( typeof callback === 'function' ) { 43 | callback.call(); 44 | callback = null; 45 | } 46 | } 47 | 48 | script.onload = finish; 49 | 50 | // IE 51 | script.onreadystatechange = function() { 52 | if ( this.readyState === 'loaded' ) { 53 | finish(); 54 | } 55 | } 56 | 57 | // Normal browsers 58 | head.appendChild( script ); 59 | 60 | } 61 | 62 | return { 63 | init: function() { 64 | 65 | defaults( options, defaultOptions ); 66 | defaults( options.tex2jax, defaultOptions.tex2jax ); 67 | options.mathjax = options.config = null; 68 | 69 | loadScript( url, function() { 70 | 71 | MathJax.Hub.Config( options ); 72 | 73 | // Typeset followed by an immediate reveal.js layout since 74 | // the typesetting process could affect slide height 75 | MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub ] ); 76 | MathJax.Hub.Queue( Reveal.layout ); 77 | 78 | // Reprocess equations in slides when they turn visible 79 | Reveal.addEventListener( 'slidechanged', function( event ) { 80 | 81 | MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub, event.currentSlide ] ); 82 | 83 | } ); 84 | 85 | } ); 86 | 87 | } 88 | } 89 | 90 | })(); 91 | 92 | Reveal.registerPlugin( 'math', RevealMath ); 93 | -------------------------------------------------------------------------------- /Slides/plugin/multiplex/client.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var multiplex = Reveal.getConfig().multiplex; 3 | var socketId = multiplex.id; 4 | var socket = io.connect(multiplex.url); 5 | 6 | socket.on(multiplex.id, function(data) { 7 | // ignore data from sockets that aren't ours 8 | if (data.socketId !== socketId) { return; } 9 | if( window.location.host === 'localhost:1947' ) return; 10 | 11 | Reveal.setState(data.state); 12 | }); 13 | }()); 14 | -------------------------------------------------------------------------------- /Slides/plugin/multiplex/index.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var express = require('express'); 3 | var fs = require('fs'); 4 | var io = require('socket.io'); 5 | var crypto = require('crypto'); 6 | 7 | var app = express(); 8 | var staticDir = express.static; 9 | var server = http.createServer(app); 10 | 11 | io = io(server); 12 | 13 | var opts = { 14 | port: process.env.PORT || 1948, 15 | baseDir : __dirname + '/../../' 16 | }; 17 | 18 | io.on( 'connection', function( socket ) { 19 | socket.on('multiplex-statechanged', function(data) { 20 | if (typeof data.secret == 'undefined' || data.secret == null || data.secret === '') return; 21 | if (createHash(data.secret) === data.socketId) { 22 | data.secret = null; 23 | socket.broadcast.emit(data.socketId, data); 24 | }; 25 | }); 26 | }); 27 | 28 | [ 'css', 'js', 'plugin', 'lib' ].forEach(function(dir) { 29 | app.use('/' + dir, staticDir(opts.baseDir + dir)); 30 | }); 31 | 32 | app.get("/", function(req, res) { 33 | res.writeHead(200, {'Content-Type': 'text/html'}); 34 | 35 | var stream = fs.createReadStream(opts.baseDir + '/index.html'); 36 | stream.on('error', function( error ) { 37 | res.write('

reveal.js multiplex server.

Generate token'); 38 | res.end(); 39 | }); 40 | stream.on('readable', function() { 41 | stream.pipe(res); 42 | }); 43 | }); 44 | 45 | app.get("/token", function(req,res) { 46 | var ts = new Date().getTime(); 47 | var rand = Math.floor(Math.random()*9999999); 48 | var secret = ts.toString() + rand.toString(); 49 | res.send({secret: secret, socketId: createHash(secret)}); 50 | }); 51 | 52 | var createHash = function(secret) { 53 | var cipher = crypto.createCipher('blowfish', secret); 54 | return(cipher.final('hex')); 55 | }; 56 | 57 | // Actually listen 58 | server.listen( opts.port || null ); 59 | 60 | var brown = '\033[33m', 61 | green = '\033[32m', 62 | reset = '\033[0m'; 63 | 64 | console.log( brown + "reveal.js:" + reset + " Multiplex running on port " + green + opts.port + reset ); -------------------------------------------------------------------------------- /Slides/plugin/multiplex/master.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | // Don't emit events from inside of notes windows 4 | if ( window.location.search.match( /receiver/gi ) ) { return; } 5 | 6 | var multiplex = Reveal.getConfig().multiplex; 7 | 8 | var socket = io.connect( multiplex.url ); 9 | 10 | function post() { 11 | 12 | var messageData = { 13 | state: Reveal.getState(), 14 | secret: multiplex.secret, 15 | socketId: multiplex.id 16 | }; 17 | 18 | socket.emit( 'multiplex-statechanged', messageData ); 19 | 20 | }; 21 | 22 | // post once the page is loaded, so the client follows also on "open URL". 23 | window.addEventListener( 'load', post ); 24 | 25 | // Monitor events that trigger a change in state 26 | Reveal.addEventListener( 'slidechanged', post ); 27 | Reveal.addEventListener( 'fragmentshown', post ); 28 | Reveal.addEventListener( 'fragmenthidden', post ); 29 | Reveal.addEventListener( 'overviewhidden', post ); 30 | Reveal.addEventListener( 'overviewshown', post ); 31 | Reveal.addEventListener( 'paused', post ); 32 | Reveal.addEventListener( 'resumed', post ); 33 | 34 | }()); 35 | -------------------------------------------------------------------------------- /Slides/plugin/multiplex/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reveal-js-multiplex", 3 | "version": "1.0.0", 4 | "description": "reveal.js multiplex server", 5 | "homepage": "http://revealjs.com", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "engines": { 10 | "node": "~4.1.1" 11 | }, 12 | "dependencies": { 13 | "express": "~4.13.3", 14 | "grunt-cli": "~0.1.13", 15 | "mustache": "~2.2.1", 16 | "socket.io": "~1.3.7" 17 | }, 18 | "license": "MIT" 19 | } 20 | -------------------------------------------------------------------------------- /Slides/plugin/notes-server/client.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | // don't emit events from inside the previews themselves 4 | if( window.location.search.match( /receiver/gi ) ) { return; } 5 | 6 | var socket = io.connect( window.location.origin ), 7 | socketId = Math.random().toString().slice( 2 ); 8 | 9 | console.log( 'View slide notes at ' + window.location.origin + '/notes/' + socketId ); 10 | 11 | window.open( window.location.origin + '/notes/' + socketId, 'notes-' + socketId ); 12 | 13 | /** 14 | * Posts the current slide data to the notes window 15 | */ 16 | function post() { 17 | 18 | var slideElement = Reveal.getCurrentSlide(), 19 | notesElement = slideElement.querySelector( 'aside.notes' ); 20 | 21 | var messageData = { 22 | notes: '', 23 | markdown: false, 24 | socketId: socketId, 25 | state: Reveal.getState() 26 | }; 27 | 28 | // Look for notes defined in a slide attribute 29 | if( slideElement.hasAttribute( 'data-notes' ) ) { 30 | messageData.notes = slideElement.getAttribute( 'data-notes' ); 31 | } 32 | 33 | // Look for notes defined in an aside element 34 | if( notesElement ) { 35 | messageData.notes = notesElement.innerHTML; 36 | messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string'; 37 | } 38 | 39 | socket.emit( 'statechanged', messageData ); 40 | 41 | } 42 | 43 | // When a new notes window connects, post our current state 44 | socket.on( 'new-subscriber', function( data ) { 45 | post(); 46 | } ); 47 | 48 | // When the state changes from inside of the speaker view 49 | socket.on( 'statechanged-speaker', function( data ) { 50 | Reveal.setState( data.state ); 51 | } ); 52 | 53 | // Monitor events that trigger a change in state 54 | Reveal.addEventListener( 'slidechanged', post ); 55 | Reveal.addEventListener( 'fragmentshown', post ); 56 | Reveal.addEventListener( 'fragmenthidden', post ); 57 | Reveal.addEventListener( 'overviewhidden', post ); 58 | Reveal.addEventListener( 'overviewshown', post ); 59 | Reveal.addEventListener( 'paused', post ); 60 | Reveal.addEventListener( 'resumed', post ); 61 | 62 | // Post the initial state 63 | post(); 64 | 65 | }()); 66 | -------------------------------------------------------------------------------- /Slides/plugin/notes-server/index.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var express = require('express'); 3 | var fs = require('fs'); 4 | var io = require('socket.io'); 5 | var Mustache = require('mustache'); 6 | 7 | var app = express(); 8 | var staticDir = express.static; 9 | var server = http.createServer(app); 10 | 11 | io = io(server); 12 | 13 | var opts = { 14 | port : 1947, 15 | baseDir : __dirname + '/../../' 16 | }; 17 | 18 | io.on( 'connection', function( socket ) { 19 | 20 | socket.on( 'new-subscriber', function( data ) { 21 | socket.broadcast.emit( 'new-subscriber', data ); 22 | }); 23 | 24 | socket.on( 'statechanged', function( data ) { 25 | delete data.state.overview; 26 | socket.broadcast.emit( 'statechanged', data ); 27 | }); 28 | 29 | socket.on( 'statechanged-speaker', function( data ) { 30 | delete data.state.overview; 31 | socket.broadcast.emit( 'statechanged-speaker', data ); 32 | }); 33 | 34 | }); 35 | 36 | [ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) { 37 | app.use( '/' + dir, staticDir( opts.baseDir + dir ) ); 38 | }); 39 | 40 | app.get('/', function( req, res ) { 41 | 42 | res.writeHead( 200, { 'Content-Type': 'text/html' } ); 43 | fs.createReadStream( opts.baseDir + '/index.html' ).pipe( res ); 44 | 45 | }); 46 | 47 | app.get( '/notes/:socketId', function( req, res ) { 48 | 49 | fs.readFile( opts.baseDir + 'plugin/notes-server/notes.html', function( err, data ) { 50 | res.send( Mustache.to_html( data.toString(), { 51 | socketId : req.params.socketId 52 | })); 53 | }); 54 | 55 | }); 56 | 57 | // Actually listen 58 | server.listen( opts.port || null ); 59 | 60 | var brown = '\033[33m', 61 | green = '\033[32m', 62 | reset = '\033[0m'; 63 | 64 | var slidesLocation = 'http://localhost' + ( opts.port ? ( ':' + opts.port ) : '' ); 65 | 66 | console.log( brown + 'reveal.js - Speaker Notes' + reset ); 67 | console.log( '1. Open the slides at ' + green + slidesLocation + reset ); 68 | console.log( '2. Click on the link in your JS console to go to the notes page' ); 69 | console.log( '3. Advance through your slides and your notes will advance automatically' ); 70 | -------------------------------------------------------------------------------- /Slides/plugin/print-pdf/print-pdf.js: -------------------------------------------------------------------------------- 1 | /** 2 | * phantomjs script for printing presentations to PDF. 3 | * 4 | * Example: 5 | * phantomjs print-pdf.js "http://revealjs.com?print-pdf" reveal-demo.pdf 6 | * 7 | * @author Manuel Bieh (https://github.com/manuelbieh) 8 | * @author Hakim El Hattab (https://github.com/hakimel) 9 | * @author Manuel Riezebosch (https://github.com/riezebosch) 10 | */ 11 | 12 | // html2pdf.js 13 | var system = require( 'system' ); 14 | 15 | var probePage = new WebPage(); 16 | var printPage = new WebPage(); 17 | 18 | var inputFile = system.args[1] || 'index.html?print-pdf'; 19 | var outputFile = system.args[2] || 'slides.pdf'; 20 | 21 | if( outputFile.match( /\.pdf$/gi ) === null ) { 22 | outputFile += '.pdf'; 23 | } 24 | 25 | console.log( 'Export PDF: Reading reveal.js config [1/4]' ); 26 | 27 | probePage.open( inputFile, function( status ) { 28 | 29 | console.log( 'Export PDF: Preparing print layout [2/4]' ); 30 | 31 | var config = probePage.evaluate( function() { 32 | return Reveal.getConfig(); 33 | } ); 34 | 35 | if( config ) { 36 | 37 | printPage.paperSize = { 38 | width: Math.floor( config.width * ( 1 + config.margin ) ), 39 | height: Math.floor( config.height * ( 1 + config.margin ) ), 40 | border: 0 41 | }; 42 | 43 | printPage.open( inputFile, function( status ) { 44 | console.log( 'Export PDF: Preparing pdf [3/4]') 45 | printPage.evaluate( function() { 46 | Reveal.isReady() ? window.callPhantom() : Reveal.addEventListener( 'pdf-ready', window.callPhantom ); 47 | } ); 48 | } ); 49 | 50 | printPage.onCallback = function( data ) { 51 | // For some reason we need to "jump the queue" for syntax highlighting to work. 52 | // See: http://stackoverflow.com/a/3580132/129269 53 | setTimeout( function() { 54 | console.log( 'Export PDF: Writing file [4/4]' ); 55 | printPage.render( outputFile ); 56 | console.log( 'Export PDF: Finished successfully!' ); 57 | phantom.exit(); 58 | }, 0 ); 59 | }; 60 | } 61 | else { 62 | 63 | console.log( 'Export PDF: Unable to read reveal.js config. Make sure the input address points to a reveal.js page.' ); 64 | phantom.exit( 1 ); 65 | 66 | } 67 | } ); 68 | -------------------------------------------------------------------------------- /Web/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Make-School-Courses/CS-1.2-Intro-Data-Structures/6658b7087fcbfaa19bb97e1abc780debae0350dc/Web/.nojekyll -------------------------------------------------------------------------------- /Web/logo-icononly.svg: -------------------------------------------------------------------------------- 1 | logo-icononly -------------------------------------------------------------------------------- /Web/style.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --base-font-weight: 400; 3 | --base-color: white; 4 | --base-font-size: 14px; 5 | 6 | --sidebar-width: 22rem; 7 | --sidebar-nav-link-before-content: ""; 8 | --sidebar-nav-link-before-content-l3: ""; 9 | --sidebar-name-font-weight: 500; 10 | 11 | --search-result-heading-font-size: 1em; 12 | --search-result-item-font-size: 0.9em; 13 | --search-result-heading-font-weight: 400; 14 | --search-result-heading-margin: 0 0 0.1em; 15 | 16 | --heading-font-weight: 500; 17 | --heading-h1-font-weight: 700; 18 | --heading-h1-font-size: 2.5em; 19 | 20 | --notice-font-style: italic; 21 | --notice-font-weight: 500; 22 | 23 | --blockquote-em-font-style: normal; 24 | --blockquote-em-font-weight: 700; 25 | 26 | --blockquote-font-style: italic; 27 | --blockquote-font-weight: 500; 28 | 29 | --code-font-size: 1em; 30 | --code-font-weight: 500; 31 | --code-tab-size: 2; 32 | } 33 | 34 | .sidebar>h1 { 35 | margin: 2.3rem auto 1rem; 36 | } 37 | 38 | .sidebar>h1>a>img { 39 | height: auto; 40 | } 41 | 42 | .markdown-section { 43 | max-width: 840px; 44 | } 45 | 46 | .markdown-section a:hover { 47 | border-bottom: 1px dashed rgba(255, 255, 255, 0.5); 48 | padding-bottom: 3px; 49 | } 50 | 51 | .sidebar-nav>ul:nth-child(1)>li>a.section-link, 52 | .sidebar-nav>ul:nth-child(1)>li>ul.children>li>a.section-link { 53 | display: block; 54 | } 55 | 56 | #main>h1:nth-child(1) { 57 | display: none; 58 | } 59 | 60 | #main>h1:nth-child(1)[id] { 61 | display: block; 62 | } 63 | 64 | .sidebar ul li a { 65 | color: #333; 66 | font-size: 14px; 67 | font-weight: 400; 68 | overflow: hidden; 69 | text-decoration: none; 70 | text-overflow: ellipsis; 71 | white-space: nowrap; 72 | } 73 | 74 | .sidebar ul li strong a { 75 | font-weight: 700; 76 | } 77 | 78 | .sidebar ul li ul.app-sub-sidebar li a { 79 | font-weight: 400; 80 | } 81 | 82 | .sidebar ul li ul.app-sub-sidebar li a.active { 83 | font-weight: 700; 84 | } 85 | 86 | body .docsify-copy-code-button { 87 | background: none !important; 88 | line-height: 1.5rem; 89 | position: absolute; 90 | word-wrap: normal; 91 | color: #ccc; 92 | font-size: .7rem; 93 | font-weight: 700; 94 | left: 0; 95 | height: 25px; 96 | top: -4px; 97 | text-align: center; 98 | } 99 | 100 | body .docsify-copy-code-button.success { 101 | color: #11A31B; 102 | } 103 | 104 | body .docsify-copy-code-button::after {} 105 | 106 | .app-name-link img { 107 | height: 150px; 108 | width: 150px; 109 | } 110 | 111 | table>tbody>tr>td::before { 112 | display: none; 113 | } 114 | 115 | .btn-edit-on-github { 116 | transition: background-color 0.5s ease; 117 | border: none; 118 | border-radius: 3px; 119 | background-color: var(--theme-color); 120 | position: absolute; 121 | top: var(--sidebar-toggle-offset-top); 122 | right: 0; 123 | margin-right: 45px; 124 | padding: 6px 10px 6px 5px; 125 | height: var(--sidebar-toggle-height); 126 | } 127 | 128 | .btn-edit-on-github a, 129 | .btn-edit-on-github svg { 130 | transition: color 0.5s ease; 131 | color: white; 132 | } 133 | 134 | .btn-edit-on-github a { 135 | text-decoration: none; 136 | position: relative; 137 | font-weight: 700; 138 | top: -1px; 139 | padding-left: 5px; 140 | } 141 | 142 | .btn-edit-on-github:hover { 143 | cursor: pointer; 144 | background-color: var(--mono-tint2); 145 | } 146 | 147 | .btn-edit-on-github:hover svg, 148 | .btn-edit-on-github:hover a { 149 | text-decoration: none; 150 | color: white; 151 | } 152 | -------------------------------------------------------------------------------- /Web/sw.js: -------------------------------------------------------------------------------- 1 | /* =========================================================== 2 | * docsify sw.js 3 | * =========================================================== 4 | * Copyright 2016 @huxpro 5 | * Licensed under Apache 2.0 6 | * Register service worker. 7 | * ========================================================== */ 8 | 9 | const RUNTIME = 'docsify' 10 | const HOSTNAME_WHITELIST = [ 11 | self.location.hostname, 12 | 'fonts.gstatic.com', 13 | 'fonts.googleapis.com', 14 | 'unpkg.com', 15 | 'github.com', 16 | 'github.io', 17 | 'makeschool.com' 18 | ] 19 | 20 | // The Util Function to hack URLs of intercepted requests 21 | const getFixedUrl = (req) => { 22 | var now = Date.now() 23 | var url = new URL(req.url) 24 | 25 | // 1. fixed http URL 26 | // Just keep syncing with location.protocol 27 | // fetch(httpURL) belongs to active mixed content. 28 | // And fetch(httpRequest) is not supported yet. 29 | url.protocol = self.location.protocol 30 | 31 | // 2. add query for caching-busting. 32 | // Github Pages served with Cache-Control: max-age=600 33 | // max-age on mutable content is error-prone, with SW life of bugs can even extend. 34 | // Until cache mode of Fetch API landed, we have to workaround cache-busting with query string. 35 | // Cache-Control-Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=453190 36 | if (url.hostname === self.location.hostname) { 37 | url.search += (url.search ? '&' : '?') + 'cache-bust=' + now 38 | } 39 | return url.href 40 | } 41 | 42 | /** 43 | * @Lifecycle Activate 44 | * New one activated when old isnt being used. 45 | * 46 | * waitUntil(): activating ====> activated 47 | */ 48 | self.addEventListener('activate', event => { 49 | event.waitUntil(self.clients.claim()) 50 | }) 51 | 52 | /** 53 | * @Functional Fetch 54 | * All network requests are being intercepted here. 55 | * 56 | * void respondWith(Promise r) 57 | */ 58 | self.addEventListener('fetch', event => { 59 | // Skip some of cross-origin requests, like those for Google Analytics. 60 | if (HOSTNAME_WHITELIST.indexOf(new URL(event.request.url).hostname) > -1) { 61 | // Stale-while-revalidate 62 | // similar to HTTP's stale-while-revalidate: https://www.mnot.net/blog/2007/12/12/stale 63 | // Upgrade from Jake's to Surma's: https://gist.github.com/surma/eb441223daaedf880801ad80006389f1 64 | const cached = caches.match(event.request) 65 | const fixedUrl = getFixedUrl(event.request) 66 | const fetched = fetch(fixedUrl, { 67 | cache: 'no-store' 68 | }) 69 | const fetchedCopy = fetched.then(resp => resp.clone()) 70 | 71 | // Call respondWith() with whatever we get first. 72 | // If the fetch fails (e.g disconnected), wait for the cache. 73 | // If there’s nothing in cache, wait for the fetch. 74 | // If neither yields a response, return offline pages. 75 | event.respondWith( 76 | Promise.race([fetched.catch(_ => cached), cached]) 77 | .then(resp => resp || fetched) 78 | .catch(_ => { 79 | /* eat any errors */ 80 | }) 81 | ) 82 | 83 | // Update the cache with the version we fetched (only for ok status) 84 | event.waitUntil( 85 | Promise.all([fetchedCopy, caches.open(RUNTIME)]) 86 | .then(([response, cache]) => response.ok && cache.put(event.request, response)) 87 | .catch(_ => { 88 | /* eat any errors */ 89 | }) 90 | ) 91 | } 92 | }) 93 | -------------------------------------------------------------------------------- /_navbar.md: -------------------------------------------------------------------------------- 1 | * **[Syllabus](ReadMe.md)** 2 | 3 | - **Lessons** 4 | - [Stacks & Queues](https://docs.google.com/presentation/d/1_LBLE3oVDJGSyHZ284QsQHpsZre5qBsSJ0_wzI4St0I) 5 | - [Arrays & Linked Lists](https://docs.google.com/presentation/d/13aS2gdzdmcftyC0CQZUYJTflZGUO_jwZe8d03jSe12I) 6 | - [Search Algorithms & Recursion](https://docs.google.com/presentation/d/1Mk-FzOwiMZs5DaOZ0SSUtJcc3m0GyTe6zwcjmHKJIUE) 7 | - [Sorting Algorithms](https://docs.google.com/presentation/d/17keVchV4c5biNh5Eqb9MKC0Kcoms6d_jqCc3_t2eh_A) 8 | - [Hash Tables](https://docs.google.com/presentation/d/1ABMQ_WABDIQSxA7FFhJw9laITLmhXXoukJBb-cXtVyE) 9 | - [Trees](https://docs.google.com/presentation/d/1joafx-7JAd6Hs-xgpPANds9dvUN39E2NtLHt1QuV_cw) 10 | - [Graphs](https://docs.google.com/presentation/d/1qg42Ge40gZLP84ERSiHm2H6ihso9_nLLdTB01jn-bAc) 11 | - [Algorithm Analysis](https://docs.google.com/presentation/d/11Qe-_4PfvGXrlYDoT1btxCvC6SoFbW8l85cn1tnXH64) 12 | 13 | 14 | 15 | - **Assignments** 16 | - [Music Playlist](Lessons/playlist.md) 17 | - [Algorithm Problem Set](https://www.gradescope.com/courses/217652/assignments/938596) 18 | - [Frequency Counting](Lessons/word_freq.md) 19 | - [Data Structures Problem Set](https://www.gradescope.com/courses/217652/assignments/938601) 20 | 21 | * **[Gradescope](https://www.gradescope.com/courses/217652)** 22 | -------------------------------------------------------------------------------- /_sidebar.md: -------------------------------------------------------------------------------- 1 | 2 | - **Lessons** 3 | - [Stacks & Queues](https://docs.google.com/presentation/d/1_LBLE3oVDJGSyHZ284QsQHpsZre5qBsSJ0_wzI4St0I) 4 | - [Arrays & Linked Lists](https://docs.google.com/presentation/d/13aS2gdzdmcftyC0CQZUYJTflZGUO_jwZe8d03jSe12I) 5 | - [Search Algorithms & Recursion](https://docs.google.com/presentation/d/1Mk-FzOwiMZs5DaOZ0SSUtJcc3m0GyTe6zwcjmHKJIUE) 6 | - [Sorting Algorithms](https://docs.google.com/presentation/d/17keVchV4c5biNh5Eqb9MKC0Kcoms6d_jqCc3_t2eh_A) 7 | - [Hash Tables](https://docs.google.com/presentation/d/1ABMQ_WABDIQSxA7FFhJw9laITLmhXXoukJBb-cXtVyE) 8 | - [Trees](https://docs.google.com/presentation/d/1joafx-7JAd6Hs-xgpPANds9dvUN39E2NtLHt1QuV_cw) 9 | - [Graphs](https://docs.google.com/presentation/d/1qg42Ge40gZLP84ERSiHm2H6ihso9_nLLdTB01jn-bAc) 10 | - [Algorithm Analysis](https://docs.google.com/presentation/d/11Qe-_4PfvGXrlYDoT1btxCvC6SoFbW8l85cn1tnXH64) 11 | 12 | 13 | 14 | - **Assignments** 15 | - [Music Playlist](Lessons/playlist.md) 16 | - [Algorithm Problem Set](https://www.gradescope.com/courses/217652/assignments/938596) 17 | - [Frequency Counting](Lessons/word_freq.md) 18 | - [Data Structures Problem Set](https://www.gradescope.com/courses/217652/assignments/938601) 19 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CS 1.2 5 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 16 | 18 | 21 | 24 | 25 | 26 | 27 | 29 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
42 | 43 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /reveal-md.json: -------------------------------------------------------------------------------- 1 | { 2 | "separator": "^\n\n", 3 | "verticalSeparator": "^\n\n", 4 | "theme": "black", 5 | "watch": true, 6 | "title": "Syllabus Template Slides", 7 | "static": "Slides", 8 | "scripts": [ 9 | ], 10 | "assetsDir": "assets", 11 | "staticDirs": "Lessons/Images", 12 | "css": [ 13 | "Reveal/makeschool.css" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /reveal.json: -------------------------------------------------------------------------------- 1 | { 2 | "controls": true, 3 | "progress": true, 4 | "autoPlayMedia": false, 5 | "slideNumber": "c/t", 6 | "showSlideNumber": "all", 7 | "controlsTutorial": true, 8 | "controlsLayout": "edges", 9 | "transition": "slide", 10 | "transitionSpeed": "medium", 11 | "minScale": 0.5, 12 | "maxScale": 3 13 | } 14 | -------------------------------------------------------------------------------- /src/PlaylistLinkedList-StarterCode/Playlist.py: -------------------------------------------------------------------------------- 1 | from Song import Song 2 | 3 | class Playlist: 4 | def __init__(self): 5 | self.__first_song = None 6 | 7 | 8 | # TODO: Create a method called add_song that creates a Song object and adds it to the playlist. This method has one parameter called title. 9 | 10 | def add_song(self, title): 11 | pass 12 | 13 | 14 | 15 | # TODO: Create a method called find_song that searches for whether a song exits in the playlist and returns its index. 16 | # The method has one parameters, title, which is the title of the song to be searched for. If the song is found, return its index. Otherwise, return -1. 17 | 18 | def find_song(self, title): 19 | pass 20 | 21 | 22 | # TODO: Create a method called remove_song that removes a song from the playlist. This method takes one parameter, title, which is the song that should be removed. 23 | 24 | def remove_song(self, title): 25 | pass 26 | 27 | 28 | 29 | # TODO: Create a method called length, which returns the number of songs in the playlist. 30 | 31 | def length(self): 32 | pass 33 | 34 | 35 | # TODO: Create a method called print_songs that prints a numbered list of the songs in the playlist. 36 | 37 | # Example: 38 | # 1. Song Title 1 39 | # 2. Song Title 2 40 | # 3. Song Title 3 41 | 42 | def print_songs(self): 43 | pass 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/PlaylistLinkedList-StarterCode/Song.py: -------------------------------------------------------------------------------- 1 | class Song: 2 | 3 | def __init__(self, title): 4 | self.__title = title 5 | self.__next_song = None 6 | 7 | 8 | # TODO: Create a getter method for the title attribute, called get_title 9 | def get_title(self): 10 | pass 11 | 12 | 13 | # TODO: Create a setter method for the next_song attribute, called set_title. Make sure titles are type cased to strings and are Title Cased. 14 | def set_title(self, title): 15 | pass 16 | 17 | 18 | # TODO: Create a getter method for the next_song attribute, called get_next_song 19 | def get_next_song(self): 20 | pass 21 | 22 | 23 | # TODO: Create a setter method for the next_song attribute, called set_next_song 24 | def set_next_song(self, next_title): 25 | pass 26 | 27 | 28 | # TODO: Using the __str___ dunder method, return a string of the song title. 29 | def __str__(self): 30 | pass 31 | 32 | 33 | # TODO: Using the __repr__ dunder method, return a string formatted as the following:'Song Title -> Next Song Title' 34 | def __repr__(self): 35 | pass 36 | -------------------------------------------------------------------------------- /src/PlaylistLinkedList-StarterCode/main.py: -------------------------------------------------------------------------------- 1 | from Playlist import Playlist 2 | 3 | playlist = Playlist() 4 | 5 | while True: 6 | 7 | # Prints welcome message and options menu 8 | print(''' 9 | 10 | Welcome to Playlist Maker 🎶 11 | 12 | ===================================== 13 | Options: 14 | 1: View playlist 15 | 2: To add a new song to playlist 16 | 3: To remove a song from playlist 17 | 4: To search for song in playlist 18 | 5: Return the length of the playlist 19 | ===================================== 20 | 21 | ''') 22 | 23 | # Prints welcome message and options menu 24 | user_selection = int(input('Enter one of the 5 options: ')) 25 | 26 | # Option 1: View playlist 27 | if user_selection == 1: 28 | playlist.print_songs() 29 | 30 | 31 | # Option 2: To add a new song to playlist 32 | elif user_selection == 2: 33 | song_title = input('What song do you want to add? ') 34 | playlist.add_song(song_title) 35 | 36 | 37 | 38 | # Option 3: To remove a song from playlist 39 | elif user_selection == 3: 40 | song_title = input('What song do you want to remove? ') 41 | playlist.remove_song(song_title) 42 | 43 | 44 | # Option 4: To search for song in playlist 45 | elif user_selection == 4: 46 | 47 | song_title = input('Which song do you want to find? ') 48 | index = playlist.find_song(song_title) 49 | 50 | if index == -1: 51 | print(f"The song {song_title} is not in the set list.") 52 | else: 53 | print(f"The song {song_title} is song number {index+1}") 54 | 55 | 56 | # Option 5: Return the length of the playlist 57 | elif user_selection == 5: 58 | print(f"This set list has {playlist.length()} songs.") 59 | 60 | # Message for invalid input 61 | else: 62 | print('That is not a valid option. Try again.\n') 63 | 64 | -------------------------------------------------------------------------------- /src/Queue.py: -------------------------------------------------------------------------------- 1 | class Queue: 2 | def __init__(self): 3 | self.items = [] 4 | 5 | def isEmpty(self): 6 | return self.items == [] 7 | 8 | def enqueue(self, item): 9 | self.items.insert(0,item) 10 | 11 | def dequeue(self): 12 | return self.items.pop() 13 | 14 | def size(self): 15 | return len(self.items) 16 | -------------------------------------------------------------------------------- /src/SearchAlgorithms.py: -------------------------------------------------------------------------------- 1 | def sequential_search(lst, target): 2 | for i in range (len(lst)): 3 | if lst[i] == target: 4 | return i 5 | return -1 6 | 7 | 8 | def binarySearch(lst, target): 9 | first = 0 10 | last = len(lst)-1 11 | found = False 12 | 13 | while first<=last and not found: 14 | midpoint = (first + last)//2 15 | if lst[midpoint] == target: 16 | found = True 17 | else: 18 | if target < lst[midpoint]: 19 | last = midpoint-1 20 | else: 21 | first = midpoint+1 22 | 23 | return found 24 | 25 | 26 | def binarySearch_recursion(lst, target): 27 | if len(lst) == 0: 28 | return False 29 | else: 30 | midpoint = len(lst)//2 31 | if lst[midpoint]==target: 32 | return True 33 | else: 34 | if target lst[j+1]: 15 | lst[j], lst[j+1] = lst[j+1], lst[j] 16 | sorted = False 17 | if sorted: 18 | break 19 | 20 | array = [5, 2, 12, 12, 1] 21 | 22 | bubble_sort(array) 23 | print("sorted array (using bubble sort)", array) 24 | 25 | ####################################################### 26 | 27 | # Selection Sort 28 | # Code from Educative 29 | 30 | def selection_sort(lst): 31 | n = len(lst) 32 | for i in range(n): 33 | # Initially, assume the first element of the unsorted part as the minimum. 34 | minimum = i 35 | 36 | for j in range(i+1, n): 37 | if (lst[j] < lst[minimum]): 38 | # Update position of minimum element if a smaller element is found. 39 | minimum = j 40 | 41 | # Swap the minimum element with the first element of the unsorted part. 42 | temp = lst[i] 43 | lst[i] = lst[minimum] 44 | lst[minimum] = temp 45 | 46 | return lst 47 | 48 | ######################################################## 49 | # Insertion Sort (simple) 50 | 51 | def insertion_sort_simple(lst): 52 | for i in range(1, len(lst)): 53 | j = i 54 | while j > 0 and lst[j-1] > lst[j]: 55 | lst[j-1], lst[j] = lst[j], lst[j-1] 56 | j = j - 1 57 | return lst 58 | 59 | array = [5, 2, 12, 12, 1] 60 | print("Original array: %s" % array) 61 | print("Sorted array (using simple insertion sort): %s" % insertion_sort_simple(array)) 62 | 63 | ###################################################### 64 | 65 | # Insertion Sort (slightly optimized) 66 | def insertion_sort(lst): 67 | for i in range(1, len(lst)): 68 | key = lst[i] 69 | j = i - 1 70 | while j >= 0 and lst[j] > key: 71 | lst[j + 1] = lst[j] 72 | lst[j] = key 73 | j -= 1 74 | 75 | return lst 76 | 77 | 78 | array = [5, 2, 12, 12, 1] 79 | print("Original array: %s" % array) 80 | print("Sorted array (slightly optimized): %s" % insertion_sort(array)) 81 | 82 | 83 | ##################################################### 84 | 85 | 86 | # Merge Sort 87 | def merge_sort(lst): 88 | if len(lst) > 1: 89 | mid = len(lst) // 2 90 | left = lst[:mid] 91 | right = lst[mid:] 92 | 93 | # Recursive call on each half 94 | merge_sort(left) 95 | merge_sort(right) 96 | 97 | # Two iterators for traversing the two halves 98 | i = 0 99 | j = 0 100 | 101 | # Iterator for the main list 102 | k = 0 103 | 104 | while i < len(left) and j < len(right): 105 | if left[i] < right[j]: 106 | # The value from the left half has been used 107 | lst[k] = left[i] 108 | # Move the iterator forward 109 | i += 1 110 | else: 111 | lst[k] = right[j] 112 | j += 1 113 | # Move to the next slot 114 | k += 1 115 | 116 | # For all the remaining values 117 | while i < len(left): 118 | lst[k] = left[i] 119 | i += 1 120 | k += 1 121 | 122 | while j < len(right): 123 | lst[k]=right[j] 124 | j += 1 125 | k += 1 126 | 127 | 128 | ################################################# 129 | 130 | 131 | # Quick Sort 132 | 133 | def quick_sort(lst): 134 | 135 | elements = len(lst) 136 | 137 | #Base case 138 | if elements < 2: 139 | return lst 140 | 141 | current_position = 0 #Position of the partitioning element 142 | 143 | for i in range(1, elements): #Partitioning loop 144 | if lst[i] <= lst[0]: 145 | current_position += 1 146 | temp = lst[i] 147 | lst[i] = lst[current_position] 148 | lst[current_position] = temp 149 | 150 | temp = lst[0] 151 | lst[0] = lst[current_position] 152 | lst[current_position] = temp #Brings pivot to it's appropriate position 153 | 154 | left = quick_sort(lst[0:current_position]) #Sorts the elements to the left of pivot 155 | right = quick_sort(lst[current_position+1:elements]) #sorts the elements to the right of pivot 156 | 157 | lst = left + [lst[current_position]] + right #Merging everything together 158 | 159 | return lst 160 | -------------------------------------------------------------------------------- /src/Stack.py: -------------------------------------------------------------------------------- 1 | class Stack: 2 | def __init__(self): 3 | self.items = [] 4 | 5 | def isEmpty(self): 6 | return self.items == [] 7 | 8 | def push(self, item): 9 | self.items.append(item) 10 | 11 | def pop(self): 12 | return self.items.pop() 13 | 14 | def peek(self): 15 | return self.items[len(self.items)-1] 16 | 17 | def size(self): 18 | return len(self.items) 19 | -------------------------------------------------------------------------------- /src/linked-list/LinkedList.py: -------------------------------------------------------------------------------- 1 | from Node import Node 2 | 3 | class LinkedList: 4 | 5 | def __init__(self): 6 | self.head = None 7 | 8 | def add(self, new_data): 9 | # 1. Create a new node 10 | new_node = Node(new_data) 11 | 12 | # 2. Set new node's next pointer to where the head is pointing 13 | new_node.next = self.head 14 | 15 | # 3. Set head pointer to point at the new node 16 | self.head = new_node 17 | 18 | 19 | def is_empty(self): 20 | return self.head == None 21 | 22 | 23 | def size(self): 24 | counter = 0 25 | current_node = self.head 26 | 27 | while current_node != None: 28 | counter += 1 29 | current_node = current_node.next 30 | 31 | return counter -------------------------------------------------------------------------------- /src/linked-list/Node.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | 3 | def __init__(self, data): 4 | self.__data = data 5 | self.__next = None 6 | 7 | def set_data(self, new_data): 8 | self.__data = new_data -------------------------------------------------------------------------------- /src/linked-list/main.py: -------------------------------------------------------------------------------- 1 | from LinkedList import LinkedList 2 | from Node import Node 3 | 4 | node1 = Node(1) 5 | my_linkedlist = LinkedList() 6 | my_linkedlist.head(node1) 7 | 8 | my_list = [3, 4, 54] -------------------------------------------------------------------------------- /src/linked-list/whole_linked_list.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | def __init__(self,initdata): 3 | self.data = initdata # Data part 4 | self.next = None # Address part 5 | 6 | def getData(self): # getter method 7 | return self.data 8 | 9 | def getNext(self): # getter method 10 | return self.next 11 | 12 | def setData(self,newdata): # setter method 13 | self.data = newdata 14 | 15 | def setNext(self,newnext): # setter method 16 | self.next = newnext 17 | 18 | 19 | class LinkedList: 20 | 21 | def __init__(self): 22 | self.head = None 23 | 24 | def isEmpty(self): 25 | return self.head == None 26 | 27 | def add(self,item): 28 | temp = Node(item) 29 | temp.setNext(self.head) 30 | self.head = temp 31 | 32 | def size(self): 33 | current = self.head 34 | count = 0 35 | while current != None: 36 | count = count + 1 37 | current = current.getNext() 38 | 39 | return count 40 | 41 | def search(self,item): 42 | current = self.head 43 | found = False 44 | while current != None and not found: 45 | if current.getData() == item: 46 | found = True 47 | else: 48 | current = current.getNext() 49 | 50 | return found 51 | 52 | def remove(self,item): 53 | current = self.head 54 | previous = None 55 | found = False 56 | while not found: 57 | if current.getData() == item: 58 | found = True 59 | else: 60 | previous = current 61 | current = current.getNext() 62 | 63 | if previous == None: 64 | self.head = current.getNext() 65 | else: 66 | previous.setNext(current.getNext()) 67 | 68 | def print(self): 69 | current = self.head 70 | while current != None: 71 | print(current.data) 72 | current = current.getNext() 73 | 74 | 75 | mylist = LinkedList() 76 | 77 | mylist.add(31) 78 | mylist.print() 79 | mylist.add(77) 80 | mylist.print() 81 | # mylist.add(17) 82 | # mylist.add(93) 83 | # mylist.add(26) 84 | # mylist.add(54) 85 | 86 | # print(mylist.size()) 87 | # print(mylist.search(93)) 88 | # print(mylist.search(100)) 89 | 90 | # mylist.add(100) 91 | # print(mylist.search(100)) 92 | # print(mylist.size()) 93 | 94 | # mylist.remove(54) 95 | # print(mylist.size()) 96 | # mylist.remove(93) 97 | # print(mylist.size()) 98 | # mylist.remove(31) 99 | # print(mylist.size()) 100 | # print(mylist.search(93)) 101 | --------------------------------------------------------------------------------