Structures From Scratch
You'll build a linked list, a stack, a queue, a hash map and a binary tree yourself, test them, and use each one once.
About
Your language ships all of these already. You build them anyway, once, so that when a program is slow you know what's going on under the floor. A hash map from scratch takes an evening and means you'll never be mystified by one again. That's the whole goal.
At a glance
- Per requirement
- 35 XP
- Completion bonus
- 300 XP
- Requirements
- 6
- Takes
- Three weeks
- Skill level
- Intermediate (months of practice)
- Cost
- Free
- Supplies
- Nothing special
- Where
- At home
- Other people
- On your own
Requirements
-
1
Build a singly linked list with append, prepend, delete and find, with tests. Each node holds a value and a pointer to the next one. Draw it on paper before you code it. The delete case where the node is the head is where the bugs live. Take a screenshot of tests covering an empty list, one node, and deleting the head. Photo
-
2
Build a stack and a queue, then use the stack to check balanced brackets. Give the stack push, pop and peek, and the queue enqueue and dequeue. Then feed the stack a string like ([{}]) and another like ([)] and have it say which one is balanced. Take a screenshot of both answers. Photo
-
3
Build a hash map with your own hash function and collision handling. You need an array of buckets, a hash function that turns a string into an index, and chaining or probing for when two keys collide. Make it resize when it's 75 percent full. Insert 100,000 keys and look one up. Take a screenshot of the lookup and the bucket count after resizing. Photo
-
4
Build a binary search tree with insert, search and in-order traversal. In-order traversal should print sorted output, and that's your test. Then insert 1 through 1,000 in order and measure the depth. It's a linked list in disguise, which is why balanced trees exist. Take a screenshot of the depth. Photo
-
5
Replace a built-in container in one of your old programs with your own version. Swap the dictionary in your word counter for your hash map. It should give the same output, a bit slower, and it's yours. Take a screenshot of the diff and the matching output. Photo
-
6
Time your hash map against the built-in on a million inserts and say why it's slower. It will be slower, and two to twenty times is normal. Write three sentences on what the built-in does that yours doesn't. Take a screenshot of both timings with your note. Photo