... start recording
Questions and/or comments on last homework ...
l==1
...Tips for the midterm paper :
function(data)
repeatedly; only the first time will get unsorted data. Where we are and where we're going :
i.e. "priority queue as binary heap using indexed array"
... we started working through this last time; let's finish that. I've attached heap_v1.py (a slightly expanded version of what we started in class), and heap_final.py (working code).
The next data structure I'd like to look at is an important one - the "hash table" , also called a "dictonary" or a "key/value store" or even a "map".
Hash tables a built-in feature of many programming languages, and even a part of how functions work - each "frame" is essentially a dictionary of variable names and values.
To get us all on the same page, let's first review
how these work in python : a = {}; a['foo'] = 'bar'; a.get("thing", None)
.
Their features are :
Places to start read about them :
There are many variations but the core ideas are
I'd like to write something together similar to this dictionary.py from a 2019 algorithms course of mine.
The goal is to implement a python dictionary with C-like data structures - not with the python builtin.
class HashTable:
def __init__(self):
pass # TODO
def get(self, key):
""" return corresponding value or None if not found """
# TODO
return None
def set(self, key, value):
""" put (key,value) into the hash table """
pass # TODO
Over the next week I'd like us to work on a more realistic C hash table with some sort of collision algorithm. (C doesn't have a builtin data structure like this.)
I'm thinking of something along the lines of a class project for next week, working on a template that I'll create, using strings as keys.
Python has objects with "properties" and methods, and dictionaries with key lookup .
Javascript puts those two ideas into one thing ... see for example working with objects .
I'd like to use put a shortcut summary of everything we're doing this term in one place, as a reference and kind of "mind map" of the ideas and concepts.
Under constructions ... the wiki . (This is a page that only we can see, and all of us can edit.)
last modified | size | ||
heap_final.py | Thu Mar 25 2021 12:47 am | 6.8K | |
heap_v1.py | Thu Mar 25 2021 12:47 am | 4.9K |