HW 2-1
To delete p
from a doubly linked list, we must do:
双向链表的结点包括三个部分:前驱指针域、数据域和后继指针域。 (1)前驱指针域(lLink),又称为左链指针,用于存放一个指针,该指针指向上一个结点的开始存储地址。 (2)数据域(data),用于存储该结点的数据元素,数据元素类型由应用问题决定。 (3)后继指针域(rLink),又称为右链指针,用于存放一个指针,该指针指向下一个结点的开始存储地址。
lLink data rLink 前驱指针 数据 后继指针
p->prior->next=p->next;p->next->prior=p->prior
HW 2-2
If the most commonly used operations are to visit a random position and to insert and delete the last element in a linear list, then which of the following data structures is the most efficient?
一些时间复杂度
Array
操作 时间复杂度 查找第K个 O(1) 插入 O(N) 删除 O(N) Linked List
操作 时间复杂度 查找第K个 O(N) 插入 O(1) 删除 O(1)
选择sequential list就是按照顺序存储方式存储的线性表
查找O(1),删除最后一个O(1)最 efficent
HW 2-3
To merge two singly linked ascending lists, both with N nodes, into one singly linked ascending list the minimum possible number of comparisons is
最简单情况:把一个接到另一个后面,即一张表的尾元素小于另一张表的首元素,最小比较一次,通常情况下,从List1的第一个从List2的第一个比到最后一个,是O(N)。
HW F2-2
经典的Reverse Linked List with a dummy header
List Reverse( List L ){
List cur,tmp=NULL,head;
cur = L;
if(cur==NULL||cur->Next==NULL){
return L;
}
head = L;
L = L->Next;
while(L->Next){
cur = L->Next;
L->Next = tmp;
tmp = L;
L = cur;
}
L->Next = tmp;
tmp = L;
head->Next = tmp;
return head;
}
It is always possible to represent a tree by a one-dimensional integer array.
HW5
2.In a binary search tree which contains several integer keys including 4, 5, and 6, if 4 and 6 are on the same level, then 5 must be their parent. X
不是能有两个5, 而是可以很高.(like 5 3 7 2 4 6 8)
3.For a binary search tree, in which order of traversal that we can obtain a non-decreasing sequence?Inorder.