This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Referenced from Stanford CS193p | |
| #: important | |
| ##: very important | |
| Basic Operators | |
| - Terminology | |
| - Assignment Operator | |
| - Arithmetic Operators |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Referenced from Stanford CS193p | |
| #: important | |
| ##: very important | |
| The Basics | |
| - Constants and Variables | |
| - Comments | |
| - Semicolons |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Uses python3 | |
| import sys | |
| def get_majority_element_linear_A(a, left, right): | |
| elements_dict = {} | |
| majority_threshold = len(a) // 2 | |
| result = -1 # -1: no majority, 0: majority | |
| # record all elements into dictionary and test if it's the majority element | |
| start = time.time() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MaxBinaryHeap: | |
| def __init__(self, values=[]): | |
| self.values = values | |
| self.build_max_heap() | |
| def max(self): | |
| """return first element in the array""" | |
| if len(self.values) > 0: | |
| return self.value[0] | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MaxBinaryHeap: | |
| def __init__(self, values=[]): | |
| self.values = values | |
| self.build_max_heap() | |
| def max(self): | |
| """return first element in the array""" | |
| if len(self.values) > 0: | |
| return self.value[0] | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 04f30a2483859caa3e70e3c1f7cfa6bd7ab4da39a5d0af26774e9d509ab90a642841b4693464967e225e1713ce0142f46f02bfa844c8888ce0ec0e570dc3e85bd0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.20.1/vis.min.css" /> | |
| <link rel="stylesheet" href="index.css"> | |
| <style id="jsbin-css"> | |
| html, body { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #reference: https://en.wikipedia.org/wiki/Zebra_Puzzle | |
| # keypoint in python here: | |
| #1. generator expression | |
| #2. *args to function calls | |
| #3. itertools module | |
| #4. is (if two variables point to the same object) | |
| #5. rearrage for and if clause to stop program earlier (if not this program may run estimately an hour) | |
| #5. time module | |
| import itertools |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class HashTable: | |
| def __init__(self): | |
| self.size = 11 | |
| self.slots= [None] * self.size | |
| self.data = [None] * self.size | |
| def put(self, key, data): | |
| hashvalue = self.hashfunction(key, len(self.slots)) | |
| if self.slots[hashvalue] == None: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The Three Laws of Recursion | |
| # 1. A recursive algorithm must have a base case. | |
| # 2. A recursive algorithm must change its state and move toward the base case. | |
| # 3. A recursive algorithm must call itself, recursively. | |
| import turtle | |
| myTurtle = turtle.Turtle() | |
| myWin = turtle.Screen() |