FDS作业记录 · 链表

1、

For a sequentially stored linear list of length N, the time complexities for deleting the first element and inserting the last element are O(1) and O(N), respectively.

T()

F()

链表结构的插入和删除操作时间复杂度都是O(N)

2、

To delete p from a doubly linked list, we must do:

A.p->prior=p->prior->prior; p->prior->next=p;

B.p->next->prior=p; p->next=p->next->next;

C.p->prior->next=p->next; p->next->prior=p->prior;

D.p->next=p->prior->prior; p->prior=p->next->next;

注意是double linked list,即有向前的指针又有向后的。

将p删除,我们需要把p的前驱结点的next指向p的后驱结点,p的后驱结点的prior指向p的前驱结点

故选C

3、

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?

A.doubly linked list

B.singly linked circular list

C.doubly linked circular list with a dummy head node

D.sequential list

我们需要进行的操作是访问随机位置并插入、删除最后一个元素。

因为需要快速进行访问操作,所以排除简单链表结构,如A的双向链表,B的单向环链表和C的双向环链表。

只有D的线性表符合要求。

PS:线性表本质上是数组。

4、

To merge two singly linked ascending lists, both with N nodes, into one singly linked ascending list, the minimum possible number of comparisons is:

A.1

B.N

C.2N

D.NlogN

将两个升序链表重新连接为一个大的升序链表, 比较次数最少的情况应该是两链表(记为A,B)中的数据都是连续递增的,这样只需要遍历A表(B表),与B表(A表)的第一个元素进行比较即可。如A表数据为1,2,3,4,B表数据为5,6,7,8,则只需要比较4次。

故最少比较N次

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值