MIT6 006S20 Review1 Sol
MIT6 006S20 Review1 Sol
006
Massachusetts Institute of Technology
Instructors: Erik Demaine, Jason Ku, and Justin Solomon Quiz 1 Review
Quiz 1 Review
High Level
• Need to solve large problems n with constant-sized code, correctly and efficiently
• Analyzing running time: How to count?
– Asymptotics
– Recurrences (substitution, tree method, Master Theorem)
– Model of computation: Word-RAM, Comparison
Algorithm: Sorting
Reduce your problem to a problem you already know how to solve using known algorithms. You
should know how each of these sorting algorithms are implemented, as well as be able to choose
the right algorithm for a given task.
Data Structures
Reduce your problem to using a data structure storing a set of items, supporting certain search and
dynamic operations efficiently. You should know how each of these data structures implement the
operations they support, as well as be able to choose the right data structure for a given task.
Sequence data structures support extrinsic operations that maintain, query, and modify an exter-
nally imposed order on items.
Operations O(·)
Sequence Container Static Dynamic
Data Structure build(X) get at(i) insert first(x) insert last(x) insert at(i,x)
Array n 1 n n n
Linked List n n 1 n n
Dynamic Array n 1 n 1(a) n
Sequence AVL n log n log n log n log n
Set data structures support intrinsic operations that maintain, query, and modify a set of items
based on what the items are, i.e., based on the unique key associated with each item.
Operations O(·)
Set Container Static Dynamic Order
Data Structure build(X) find(k) insert(x) find min() find prev(k)
Array n n n n n
Sorted Array n log n log n n 1 log n
Direct Access u 1 1 u u
Hash Table n(e) 1(e) 1(a)(e) n n
Set AVL n log n log n log n log n log n
Problem Solving
Testing Strategies
• Read every problem first, rank them in the order of your confidence
• For most problems, you can receive ≥ 50% of points in two sentences or less
• Probably better to do half the problems well than all the problems poorly
Types of problems
Type Internals Externals Tests understanding of:
Mechanical Y N how core material works
Reduction N Y how to apply core material
Modification Y Y how to adapt core material
(augmentation, divide & conquer, amortization, etc.)
Questions to ask:
• Is this a Mechanical, Reduction, or Modification type problem?
• If data structures, do you need to support Sequence ops? Set ops? both?
• Describe all data structure(s) used (including what data they store) and their invariants
Then peak rainfall is simply peak(v, t) with v being the root of the tree, which can be computed
using at most O(log n) recursive calls. So this operation runs in worst-case O(log n) time.
Note, this problem can also be solved where each latitude AVL tree is keyed by rainfall, augment-
ing nodes with maximum time in subtree. We leave this as an exercise to the reader.
MIT OpenCourseWare
https://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms