摘要:Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous 閱讀全文
摘要:前言 我們知道,要構造Huffman Tree,每次都要從堆中彈出最小的兩個權重的節點,然后把這兩個權重的值相加存放到新的節點中,同時讓這兩個節點分別成為新節點的左右兒子,再把新節點插入到堆中。假設節點個數為n,則重復n-1次后,最后堆中的那個節點就是Huffman Tree的根。 用堆實現當然可以 閱讀全文
摘要:Huffman Codes In 1953, David A. Huffman published his paper "A Method for the Construction of Minimum-Redundancy Codes", and hence printed his name in 閱讀全文
摘要:File Transfer We have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one compu 閱讀全文
摘要:問題引入 在做題的時候需要在堆區申請一個二維數組。所以當時很自然用這種方式來申請: int *a = new int[row][col]; ,編譯器會報錯。 首先,有個錯誤是我把二維數組名理解成一個一級指針。這是因為之前打印輸出二維數組名的地址時,二維數組名就是一個指向二維數組第一個元素地址的指針, 閱讀全文
摘要:是否同一棵二叉搜索樹 給定一個插入序列就可以唯一確定一棵二叉搜索樹。然而,一棵給定的二叉搜索樹卻可以由多種不同的插入序列得到。例如分別按照序列{2, 1, 3}和{2, 3, 1}插入初始為空的二叉搜索樹,都得到一樣的結果。于是對于輸入的各種插入序列,你需要判斷它們是否能生成一樣的二叉搜索樹。 輸入 閱讀全文
摘要:Complete Binary Search Tree A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of 閱讀全文
摘要:Pop Sequence Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell 閱讀全文
摘要:List Leaves Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. Input Specification: Each input file co 閱讀全文
摘要:Tree Traversals Again An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node 閱讀全文