FDS数据结构错题集1

HW 2-1

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

双向链表的结点包括三个部分:前驱指针域、数据域和后继指针域。 (1)前驱指针域(lLink),又称为左链指针,用于存放一个指针,该指针指向上一个结点的开始存储地址。 (2)数据域(data),用于存储该结点的数据元素,数据元素类型由应用问题决定。 (3)后继指针域(rLink),又称为右链指针,用于存放一个指针,该指针指向下一个结点的开始存储地址。

lLinkdatarLink
前驱指针数据后继指针

这里写图片描述

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.

  • 18
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值