原创 1004 Counting Leaves (30 分) 輸出樹每層的葉子節點數

A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child

原创 1147 Heaps (30 分) 堆的判斷

1147 Heaps (30 分) In computer science, a heap is a specialized tree-based data structure that satisfies the heap proper

原创 1123 Is It a Complete AVL Tree (30 分) 構造AVL輸出層次遍歷並判斷是否爲完全二叉樹

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

原创 1064 Complete Binary Search Tree (30 分) 建立完全二叉搜索樹並輸出其層次遍歷

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

原创 1020 Tree Traversals (25 分) 給出後序和中序遍歷,輸出層序遍歷

1020 Tree Traversals (25 分) Suppose that all the keys in a binary tree are distinct positive integers. Given the postor

原创 1098 Insertion or Heap Sort (25 分) 插入排序or堆排序

1098 Insertion or Heap Sort (25 分) According to Wikipedia: Insertion sort iterates, consuming one input element each re

原创 1145 Hashing - Average Search Time (25 分) 建立Hash表並輸出平均查詢次數

The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try t

原创 [PAT] 模板整理

1.並查集 int fa[MAX]; int find(int x) { int r=x,i=x,j; while(fa[r]!=r) r=fa[r]; while(fa[i]!=i) j=fa[i],fa[i]=r,i=j;

原创 1142 Maximal Clique (25 分) 判斷最大團

1142 Maximal Clique (25 分) A clique is a subset of vertices of an undirected graph such that every two distinct vertice

原创 1146 Topological Order (25 分) 拓撲序列是否合法

1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is

原创 【MOOC-浙大數據結構】第九周的編程作業——排序

1.排序  int a[100005]; int main() { int n,i,j; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); fo

原创 1066 Root of AVL Tree (25 分) 構造平衡二叉樹並輸出根節點

1066 Root of AVL Tree (25 分) An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two

原创 1103 Integer Factorization (30 分) dfs 剪枝

The K−P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You ar

原创 1089 Insert or Merge (25 分) 插入排序or歸併排序

According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growing a sorted outp

原创 1115 Counting Nodes in a BST (30 分) 二叉搜索樹BST 輸出層結點數

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