原创 05-樹9 Huffman Codes

題目 In 1953, David A. Huffman published his paper "A Method for the Construction of Minimum-Redundancy Codes", and hence

原创 05-樹8 File Transfer

題目 We have a network of computers and a list of bi-directional connections. Each of these connections allows a file tra

原创 04-樹5 Root of AVL Tree

題目 An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any nod

原创 04-樹4 是否同一棵二叉搜索樹

題目 給定一個插入序列就可以唯一確定一棵二叉搜索樹。然而,一棵給定的二叉搜索樹卻可以由多種不同的插入序列得到。例如分別按照序列{2, 1, 3}和{2, 3, 1}插入初始爲空的二叉搜索樹,都得到一樣的結果。於是對於輸入的各種插入序列,你

原创 04-樹6 Complete Binary Search Tree

題目 A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subt

原创 05-樹7 堆中的路徑

題目 將一系列給定數字插入一個初始爲空的小頂堆H[]。隨後對任意給定的下標i,打印從H[i]到根結點的路徑。 輸入格式: 每組測試第1行包含2個正整數N和M(≤1000),分別是插入元素的個數、以及需要打印的路徑條數。下一行給出區間[-1

原创 03-樹3 Tree Traversals Again

  題目 An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that

原创 02-線性結構3 Reversing Linked List

題目 Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For e

原创 03-樹1 樹的同構

題目 給定兩棵樹T1和T2。如果T1可以通過若干次左右孩子互換就變成T2,則我們稱兩棵樹是“同構”的。例如圖1給出的兩棵樹就是同構的,因爲我們把其中一棵樹的結點A、B、G的左右孩子互換後,就得到另外一棵樹。而圖2就不是同構的。 圖1

原创 03-樹2 List Leaves

題目 Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. Input Specificati

原创 02-線性結構4 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

原创 02-線性結構1 兩個有序鏈表序列的合併

題目 本題要求實現一個函數,將兩個鏈表表示的遞增整數序列合併爲一個非遞減的整數序列。 函數接口定義: List Merge( List L1, List L2 ); 其中List結構定義如下: typedef struct Node

原创 02-線性結構2 一元多項式的乘法與加法運算

題目 設計函數分別求兩個一元多項式的乘積與和。 輸入格式: 輸入分2行,每行分別先給出多項式非零項的個數,再以指數遞降方式輸入一個多項式非零項係數和指數(絕對值均爲不超過1000的整數)。數字間以空格分隔。 輸出格式: 輸出分2行,分別以

原创 01-複雜度3 二分查找

題目 本題要求實現二分查找算法。 函數接口定義: Position BinarySearch( List L, ElementType X ); 其中List結構定義如下: typedef int Position; typedef

原创 01-複雜度1 最大子列和問題

題目 給定K個整數組成的序列{ N​1​​, N​2​​, ..., N​K​​ },“連續子列”被定義爲{ N​i​​, N​i+1​​, ..., N​j​​ },其中 1≤i≤j≤K。“最大子列和”則被定義爲所有連續子列元素的和中最