SE106 Exercise Class 7 Quiz Homework 9 Lab 4 Review Solution 1 A: Impossible B: push 1, 2, 3, pop 3, 2, push 4, 5, pop 5, push 6, pop 6, 4, 1 C: Impossible D: Impossible Solution 1 C Radix sort efficiency is O(d·n) for n keys which have d or fewer digits. In general d cannot be considered a constant. Solution 3 Hint: Use in-order traverse and reverse in-order traverse simultaneously. Use the stack to save the traverse route. Solution 3 Homework 9 wxdwfc@sjtu.edu.cn Problem’s problem • Not using a priority queue.(not so efficient) • Wrong in-output format • not using -1 to indicate that the node is not reachable. • The first n means [0,n] inclusively. Solution Solution Solution Lab4 Lab4 • 迟交 • Trace07 • 压缩解压后文件不同 • 不是最优的Huffman-Tree Lab4 • Huffman树如何存 • 保存映射关系 • 变长 • 定长 • 保存节点信息 • 直接读取得到树 • 保存出现次数 • 读取次数重建树 5130309006 汤劲戈 5130379005 殷国航 Review L1:Template Structures • Shallow vs. Deep Copying • Total template specialization • Partially specialize a function template • Generic Programming • Parametric type • Iterator • Algorithm/Functor TMP: Template metaprogramming Effective C++ Item 48 L3:Smart Pointers L4:Collection Classes Vector collection Grid Stack ordering Queue Map benefits array by index fast; simple Vector by insertion, by index by index, 2D LIFO FIFO sorted order unpredictable sorted order unpredictable random access; fast to modify at end great for 2D data simple; fast simple; fast sorted; pretty fast very fast sorted; pretty fast very fast Grid Stack Queue Set HashSet Map HashMap Set weaknesses little functionality; cannot resize slow to modify in middle/front must be rectangular little functionality little functionality must be comparable unordered must be comparable unordered L5-6: Recursion • Recursive Strategies • Recursive Backtracking • Recursion VS Iteration • Tail-recursion L7: Sorting and Efficiency L8: Maps and Hashing Let λ = n / m (load factor) Unsuccessful Search Chaining 1+α Open Addressing ( assuming uniform hashing ) 1 / (1 – α) Successful Search 1+α (1 + average number before element in chain) L9-10: Expression Tree and Parsing Strategies L11: BST-Binary Search Trees If you process the current node before either recursive call, the result is a preorder traversal. If you process the current node after the recursive call on the left subtree but before the recursive call on the right subtree, the result is an inorder traversal. In the case of the simple BST implementation that uses strings as keys, the keys will appear in lexicographic order. If you process the current node after completing both recursive calls, the result is a postorder traversal. Postorder traversals are particularly useful if you are trying to free all the nodes in a tree. L12-13: AVL Tree L14-15: Red-Black Tree L16: Huffman Coding L16: MinHeap and HeapSort L17: Splay Trees L18-19: Graphs Dijkstra’s Algorithm Minimum Spanning Tree L20: B Tree/B+ Tree L21: General Tree and Forest L22: Sets Merry Xmas!