SE106 Exercise Class 7 Quiz Homework 9 Lab 4 Review.

Post on 20-Jan-2018

218 views 0 download

description

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.

transcript

SE106 Exercise Class 7

QuizHomework 9

Lab 4Review

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 3Hint:

Use in-order traverse and reverse in-order traverse simultaneously.

Use the stack to save the traverse route.

Solution 3

Homework 9wxdwfc@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

• Huffman 树如何存• 保存映射关系

• 变长• 定长

• 保存节点信息• 直接读取得到树

• 保存出现次数• 读取次数重建树

Lab4

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 ClassesVector Grid Stack Queue Map Set

collection ordering benefits weaknesses

array by index fast; simple little functionality; cannot resize

Vector by insertion, by index

random access; fast to modify at end

slow to modify in middle/front

Grid by index, 2D great for 2D data must be rectangularStack LIFO simple; fast little functionality

Queue FIFO simple; fast little functionalitySet sorted order sorted; pretty fast must be comparable

HashSet unpredictable very fast unorderedMap sorted order sorted; pretty fast must be comparable

HashMap unpredictable very fast 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

Successful Search

Chaining 1+α

1 + α (1 + average number before element in chain)

Open Addressing( assuming uniform hashing )

1 / (1 – α)

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 : GraphsDijkstra’s Algorithm

Minimum Spanning Tree

L20 : B Tree/B+ Tree

L21 : General Tree and Forest

L22 : Sets

Merry Xmas !