完成《数据结构》大题.md

main
InkSoul 2023-08-03 22:06:09 +08:00
parent 15f48f82df
commit 1aec2e7698
18 changed files with 441 additions and 0 deletions

View File

@ -0,0 +1,441 @@
---
title: "《数据结构》大题"
date: 2023-08-03T19:21:43+08:00
---
![](../../images/《数据结构》大题/大题1.jpg)
1
链式存储结构
2
![](../../images/《数据结构》大题/大题1图1.png)
front为队首指针rear为队尾指针
初始时,创建只有一个空闲结点的循环单链表
frontrear均指向空闲结点
队空判别front = rear
队满判别front = rear->next
3
![](../../images/《数据结构》大题/大题1图2.png)
4
入队:
```
若(front == rear -> next)
则在rear后插入一个新的空闲结点;
入队元素保存到rear所指结点中;
rear = rear -> next;
返回
```
出队:
```
若(front == rear)
则出队失败,返回;
取front所指结点的元素e;
front = front -> next;
返回e;
```
---
![](../../images/《数据结构》大题/大题2.jpg)
1
二叉树
2
$01011010\cdots$
从左至右依次扫描01串中的各位从二叉树根开始根据串中当前位沿树中当前结点的左子指针或右子指针0左1右下移直到叶子结点输出叶子结点保存的字段。然后再从根节点开始重复这个过程直到01串结束译码完成
3
$01011010\cdots$
对每个编码C建立从根开始对应于该编码的一条路径从左到右扫描CC为0则沿结点左指针下移为1沿结点右指针。遇到空指针时创建新结点让空指针指向该结点并继续移动移动中
1. 若遇到叶结点,则表明不具有前缀特性,返回
2. 若处理C的所有位中均没创建新结点则表明不具有前缀特性返回
3. 若在C的最后一个编码创建了新结点则继续验证下一个编码
若所有编码都通过,则编码具有前缀特性
---
![](../../images/《数据结构》大题/大题3.jpg)
1
表集合{10(A),35(B),40(C),50(D),60(E),200(F)}
1. AB合并最多比较次数 35+10-1 = 44
2. AB与C合并最多比较次数 40+45-1=84
3. DE合并最多比较次数50+60-1=109
4. ABC与DE合并最多比较次数85+110-1=194
5. ABCDE与F合并最多比较次数195+200-1 = 394
比较的总次数最多 = 825次
2
对多个有序表进行两两合并时,若表长不同,则最坏情况下总得比较次数依赖于表的合并次序,借助哈夫曼树的思想,依次选择最短的两个表进行合并,此时可以获得最坏情况下的最佳合并效率
---
![](../../images/《数据结构》大题/大题4.jpg)
1
有两类结点:叶结点数$n_0$,度为k的分支结点$n_k$
则$n_{总} = n_0 + n_k = n_0+m,$树的边e = n -1
且e = mk的$n_0+m = mk+1$
因此,$n_0 = (k-1)m+1$
2
最多即为满k叉树第j层结点为$k^{j-1}$
所以 最多 = $\sum_{j=1}^n k^{j-1} = \frac{k^h-1}{k-1}$
最少 = $1+(h-2)k+k = 1+(h-1)k$
---
![](../../images/《数据结构》大题/大题5.jpg)
2
唯一若AE替代CE则形成了回路
3
当带权连通图的任意一个环中所包含的边权值不相同时MST是唯一的
---
![](../../images/《数据结构》大题/大题6.jpg)
1
$A = \begin{bmatrix}
0 & 1 & 1 & 0 & 1 \\\\
1 & 0 & 0 & 1 & 1 \\\\
1 & 0 & 0 & 1 & 0 \\\\
0 & 1 & 1 & 0 & 1 \\\\
1 & 1 & 0 & 1 & 0 \\\\
\end{bmatrix}$
2
$$
A^2 = \begin{bmatrix}
0 & 1 & 1 & 0 & 1 \\\\
1 & 0 & 0 & 1 & 1 \\\\
1 & 0 & 0 & 1 & 0 \\\\
0 & 1 & 1 & 0 & 1 \\\\
1 & 1 & 0 & 1 & 0 \\\\
\end{bmatrix}
\times
\begin{bmatrix}
0 & 1 & 1 & 0 & 1 \\\\
1 & 0 & 0 & 1 & 1 \\\\
1 & 0 & 0 & 1 & 0 \\\\
0 & 1 & 1 & 0 & 1 \\\\
1 & 1 & 0 & 1 & 0 \\\\
\end{bmatrix} =
\begin{bmatrix}
3 & 1 & 0 & 3 & 1 \\\\
1 & 3 & 2 & 1 & 2 \\\\
0 & 2 & 2 & 0 & 2 \\\\
3 & 1 & 0 & 3 & 1 \\\\
1 & 1 & 2 & 1 & 3 \\\\
\end{bmatrix}
$$
0行3列的值表示从顶点0到顶点3之间长度为2的路径共有3条
3
从顶点i到顶点j的长度为m的路径条数
---
![](../../images/《数据结构》大题/大题7.jpg)
1
无向图
2
链式存储结构
$$
\begin{array}
|\text{Flag = 1} | \text{Next}| \\\\
\hline
\text{ID}| \\\\
\hline
\text{IP}| \\\\
\hline
\text{Metrix}| \\\\
\end{array}
$$
$$
\begin{array}
|\text{Flag = 2} | \text{Next}| \\\\
\hline
\text{Prefix}| \\\\
\hline
\text{Mask}| \\\\
\hline
\text{Metrix}| \\\\
\end{array}
$$
表头结点
|RouterID|
|:---:|
|LN-link|
|Next|
数据结构类型
```c
//link的结构
typedef Struct
{
unsigned int ID,IP;
}LinkNode;
//net的结构
typedef Struct{
unsigned int prefix,Mask;
}NetNode;
//弧结点
typedef struct{
int Flag;
union{
LinkNode Lnode;
NetNode Noded;
}LinkOrNet;
unsigned int *next;
}arcNode;
//表头结点
typedef struct hNode
{
unsigned int RouterID;
ArcNode * LN_link;
struct hNode *next;
}HNode;
```
(3)
![](../../images/《数据结构》大题/大题7图1.jpg)
|目的网络|路径|代价|
|:---:|:---:|:---:|
|192.1.1.0/24|直接到达|1|
|192.1.5.0/24|R1->R3->192.1.5.0/24|3
|192.1.6.0/24|R1->R2->192.1.6.0/24|4
|192.1.7.0/24|R1->R2->R4->192.1.7.0/24|8
---
![](../../images/《数据结构》大题/大题8.jpg)
不一定能求得最短路径
按题方法求得最短路径A->B->C
实际最短路径A->D->C
---
![](../../images/《数据结构》大题/大题9.jpg)
1
$$
A=\begin{bmatrix}
0 & 4 & 6 & \infty & \infty & \infty \\\\
\infty & 0 & 5 & \infty & \infty & \infty \\\\
\infty & \infty & 0 & 4 & 3 & \infty \\\\
\infty & \infty & \infty & 0 & \infty & 3 \\\\
\infty & \infty & \infty & \infty & 0 & 3 \\\\
\infty & \infty & \infty & \infty & \infty & 0 \\\\
\end{bmatrix}
$$
2
![](../../images/《数据结构》大题/大题9图1.png)
3
关键路径 0->1->2->3->5
长度为 4+5+4+3 = 16
---
![](../../images/《数据结构》大题/大题10.jpg)
总费用均为16
2
用邻接矩阵存储构造最小生成树则使用Prim算法
3
TTL = 5=>IP分组的最大传递距离 = 5
方案一太远,不能收到
方案二邻近可以收到
---
![](../../images/《数据结构》大题/大题11.jpg)
1
一维数组大小7/0.7 = 10,下标为 0~9
$$
\begin{array}{c|lcr}
\text{key} & 7 & 8 & 30 & 11 & 18 & 9 & 14 \\\\
\hline
\text{H(key)} & 0 & 3 & 6 & 5 & 5 & 6 & 0 \\\\
\end{array}
$$
$$
\begin{array}{c|lcr}
\text{地址} & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \\\\
\hline
\text{关键字} & 7 & 14 & & 8 & & 11 & 30 & 18 & 9 & \\\\
\end{array}
$$
2
查找成功:
$$
\begin{array}{c|lcr}
\text{key} & 7 & 8 & 30 & 11 & 18 & 9 & 14 \\\\
\hline
\text{比较次数} & 1 & 1 & 1 & 1 & 3 & 3 & 2 \\\\
\end{array}
$$
$ASL_{成功} = \frac{1+1+1+1+3+3+2}{7} = \frac{12}{7}$
查找失败:
$$
\begin{array}{c|lcr}
\text{地址} & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\\\
\hline
\text{关键字} & 3 & 2 & 1 & 2 & 1 & 5 & 4 \\\\
\end{array}
$$
$ASL_{失败} = \frac{3+2+1+2+1+5+4}{7} = \frac{18}{7}$
---
![](../../images/《数据结构》大题/大题12.jpg)
1
按查找概率逆序排列
顺序查找方法
平均查找长度 = $1\times 0.35 + 2\times 0.35+3\times 0.15+4\times 0.15 = 2.1$
2
方法一:
按查找概率逆序排列
顺序查找方法
平均查找长度 = $1\times 0.35 + 2\times 0.35+3\times 0.15+4\times 0.15 = 2.1$
方法二:
二叉排序树的查找方法:
$ASL=0.15\times1 + 0.35\times2 + 0.35\times2 + 0.15\times3 = 2.0$
---
![](../../images/《数据结构》大题/大题13.jpg)
1
b的内容为{-10,10,11,19,25,25}
2
比较次数 = (n-1) + (n-2)+(n-3)$\cdots$+1 = $\frac{n(n-1)}{2}$
3
不是
将if修改为
```c
if(a[i]<=a[j])
{
count[j]++;
}
else
{
count[i]++;
}
```
如果不加=两个相等的元素在比较时前面的元素的count值会加1导致原序列中靠前的元素在排序后的序列处于靠后的位置
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB