数据结构期末考试总结

尽全力去准备程刚的期末考试,没想到还是得不到90+的分数,心情郁闷。不过,试卷还是极有水平的,下面我就把所有当时感觉困难的题目,都放在这里详细剖析一下,以供学习参考:

2.链式栈使用什么结构?
类比数组栈,可以想象出链表栈的结构啊。由于头进头出,所以链表构成的栈只需设置一个top pointer指向队列开头,整个栈使用单链表即可。

什么时候使用double linked-list?
能回溯(双向移动)是其最大的优点

Following are advantages/disadvantages of doubly linked list over singly linked list.

Advantages over singly linked list
1) A DLL can be traversed in both forward and backward direction.
2) The delete operation in DLL is more efficient if pointer to the node to be deleted is given.
In singly linked list, to delete a node, pointer to the previous node is needed. To get this previous node, sometimes the list is traversed. In DLL, we can get the previous node using previous pointer.

Disadvantages over singly linked list
1) Every node of DLL Require extra space for an previous pointer. It is possible to implement DLL with single pointer though (See this and this).
2) All operations require an extra pointer previous to be maintained. For example, in insertion, we need to modify previous pointers together with next pointers. For example in following functions for insertions at different positions, we need 1 or 2 extra steps to set previous pointer.

综上所述,使用double-linked list对于stack这种单指针操作(插入或删除)的数据结构来说纯粹是浪费额外空间,single-linked list完全可以胜任。

7.二分搜索树怎么搜索?
此题存疑,根据二分搜索范围不断缩小的特点。我认为有两个答案都不可能出现。

11.前、中、后序的线索树,哪个找不到后继?
一般说来,thread binary tree都指的是按inorder遍历下的顺序来构建predecessor, successor的。对于inorder来说,构建线索的思路如下:

先找current node的左子树最右节点,有的话即为predecessor,不用构建thread。没有左子树才构建thread
再找current node的右子树最左节点,有的话即为successor,不用构建thread。没有右子树才构建thread

构建thread binary tree完成后,能加快中序遍历的访问速度,操作与构建相反:先看current node有无right thread,如有就直接跳到其线索后继;没有时才使用leftMost()函数找其右子树的最左节点(没建立线索的后继)

以下代码演示single-thread binary tree的情况(只为建立successor thread, 不考虑前驱)

struct Node 
{
    int data;
    Node *left, *right;
    bool rightThread;  
}

// Utility function to find leftmost node in a tree rooted with n
struct Node* leftMost(struct Node *n)
{
    if (n == NULL)
       return NULL;

    while (n->left != NULL)
        n = n
  • 12
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值