Ada Developers Academy / Lovelace Learning Labs
Advanced Data Structures 1 - Trees
Week 4
Download
$ git clone <paste-url>
$ cd <created-directory>
Install
$ npm install
Run tests in watch mode
$ npm test
- Read through the existing code in
heap.js
and skim the tests inheap.test.js
- Implement
insert
and_float
to make the appropriate tests pass - Implement
removeMax
and_sink
to make the appropriate tests pass - Implement
_buildheap
to make the appropriate tests pass - Implement
heapsort
to make the appropriate tests pass
Submit your assignment in Learn before starting to work on these, then do them on a branch
- Test and implement a function to remove an element from the heap. What does the interface for this look like?
- Modify your heap to use a 0-indexed array.
- Make your heap accept arbitrary data:
- Modify the constructor to take an optional callback
isHigherPriority
, and use it to compare records infloat
andsink
- What should the default value of
isHigherPriority
be? - Test your capabilities by creating a min-heap
- What should the default value of
- Modify
insert
to take an opaque record object instead of a priority and element. Fix all the tests that break! - Modify
removeMax
to return an opaque record object. Fix all the tests that break! - Test your implementation by heapsorting an array of integers, an array of strings, and an array of complex objects
- Modify the constructor to take an optional callback