Day4_Homework

写出该无向图的邻接矩阵

:由于是无向图,即相邻两边都有路径到达对方。该邻接矩阵为: [ 0 1 1 1 1 0 1 0 1 1 0 1 1 0 1 0 ] \left[ \begin{matrix} 0&1&1&1\\ 1&0&1&0\\ 1&1&0&1\\ 1&0&1&0 \end{matrix} \right] 0111101011011010




定义无向网络

:有向网络为:A directed net is a tuple G = ( V , w )   , \mathbf{G}=(\mathbf{V},w)\ , G=(V,w) , where V \mathbf{V} V is the set of nodes,and w : V × V → R w:\mathbf{V \times V}\to\mathbb{R} w:V×VR is the weight function where   w ( v i , v j ) \ w(v_i,v_j)  w(vi,vj) is the weight of the arc ⟨ v i , v j ⟩ \langle v_i,v_j \rangle vi,vj

则无向图为:A indirected net is a tuple G = ( V , w )   , \mathbf{G}=(\mathbf{V},w)\ , G=(V,w) , where V \mathbf{V} V is the set of nodes,and w : V × V → R w:\mathbf{V \times V}\to\mathbb{R} w:V×VR is the weight function where   w ( v i , v j ) \ w(v_i,v_j)  w(vi,vj) is the weight of the arc ( v i , v j ) (v_i,v_j) (vi,vj)




自己画一棵树, 将其元组各部分写出来 (特别是函数 p p p).

:该树如下:

A
B
C
D
E
F

定义如下:Let ϕ \phi ϕ be the empty node, a tree is a triple T = ( V , r , p ) T=(\mathbf{V},r,p) T=(V,r,p) where

  • V ≠ ∅ \mathrm{V} \ne \emptyset V= is the set of nodes;
  • r ∈ V r \in \mathrm{V} rVis the root node;
  • p : V → V   ∪ { ∅ } p:\mathrm{V} \to\mathrm{V} \ \cup\{\emptyset\} p:VV {}is the parent mapping satisfying
  • p ( r ) = ϕ p(r)=\phi p(r)=ϕ
  • ∀ v ∈ V , ∃ 1 n ≥ 0 , s t . p ( n ) ( v ) = r \forall v \in \mathbf{V}, \exist 1 n \ge 0, st. p^{(n)}(v) = r vV,1n0,st.p(n)(v)=r

其中 V = { A , B , C , D , E , F } \mathbf{V}=\{A,B,C,D,E,F\} V={A,B,C,D,E,F}
r   i s   t h e   r o o t   ,   r   i s   A r \mathrm{\ is \ the \ root} \ ,\ r \ \mathrm{is}\ A r is the root , r is A




针对该树, 将代码中的变量值写出来 (特别是 parent 数组).

:Java代码如下:

public class Tree {
	/**
	 * 节点数. 表示节点 v_0 至 v_{n-1}.
	 */
	int n;
	
	/**
	 * 根节点. 0 至 n-1.
	 */
	int root;
	
	/**
	 * 父节点.
	 */
	int[] parent;

	/**
	 * 构造一棵树, 第一个节点为根节点, 其余节点均为其直接子节点, 也均为叶节点.
	 */
	public Tree(int paraN) {
		n = paraN;
		parent = new int[n];
		parent[0] = -1; // -1 即 \phi
	}// Of the constructor
}//Of class Tree

其中 n = 6 , r o o t = A , p n=6, root =A,p n=6,root=A,p数组: p [ − 1 , 0 , 0 , 0 , 1 , 1 ] p[-1,0,0,0,1,1] p[1,0,0,0,1,1] (nodes的按从左到右编号)




画一棵三叉树, 并写出它的 child 数组.

:该树如下:

V0
V1
V2
V3
V4
V5

该三叉树的child数组为:用矩阵表示为
[ 1 2 3 4 5 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 ] \left[ \begin{matrix} 1 & 2 &3 \\ 4 & 5 & -1 \\ -1 & -1 & -1\\ -1 & -1 & -1\\ -1 & -1 & -1\\ -1 & -1 & -1 \end{matrix} \right] 141111251111311111




按照本贴风格, 重新定义树. 提示: 还是应该定义 parent 函数, 字母表里面只有一个元素.

A   t r e e   i s   a   5 − t u p l e   M = ( Σ , V , r , T , p ) , w h e r e a )   Σ = { c }   i s   t h e   a l p h a b e t ,   r e p r e s e n t   a   c h i l d   n o d e b )   V = { v 1 , . . . . . , v n }   i s   t h e   s e t   o f   n o d e s c )   r ∈   V   i s   t h e   r o o t   o f   t h e   t r e e ,   a l s o   i s   t h e   s t a r t   n o d e d )   ϕ   i s   t h e   s e t   o f   t e r m i n a l   s t a t e e )   p : V ∪ { ϕ } × Σ ∗ → V ∪ { ϕ }   i s   t h e   t r a n s i t i o n   f u n t i o n A n y   s ∈ Σ ∗   i s   a c c e p t e d   b y   t h e   a u t o m a t a   i f f   ∀ v ∈   V , ∃ 1 s ∈ Σ ∗ s t . c ( r , s ) = v \mathrm{A\ tree \ is\ a\ 5-tuple\ M}=(\Sigma,\mathbf{V},\mathbf{r},\mathbf{T},p),\mathrm{where} \\a)\ \Sigma=\{c\}\mathrm{\ is\ the\ alphabet,\ represent\ a\ child\ node} \\b)\ \mathbf{V}=\{v_1,.....,v_n\}\ \mathrm{is\ the\ set\ of\ nodes} \\c)\ \mathbf{r}\in\ \mathbf{V}\ \mathrm{is\ the\ root\ of\ the\ tree,\ also\ is\ the\ start\ node} \\d)\ \phi\ \mathrm{is\ the\ set\ of\ terminal\ state} \\e)\ p:\mathbf{V}\cup \{\phi\}\times\Sigma^* \to \mathbf{V}\cup\{\phi\}\ \mathrm{is\ the\ transition\ funtion} \\Any\ s\in\Sigma^*\ \mathrm{is\ accepted\ by\ the\ automata\ iff\ \forall}v\in\ \mathbf{V},\exists1s\in\Sigma^*st.c(\mathbf{r},s)=v A tree is a 5tuple M=(Σ,V,r,T,p),wherea) Σ={c} is the alphabet, represent a child nodeb) V={v1,.....,vn} is the set of nodesc) r V is the root of the tree, also is the start noded) ϕ is the set of terminal statee) p:V{ϕ}×ΣV{ϕ} is the transition funtionAny sΣ is accepted by the automata iff v V,1sΣst.c(r,s)=v




根据图、树、 m m m-叉树的学习, 谈谈你对元组的理解.

:今天又学习了一遍元组,最深刻的印象就是元组可以存储不同类型的数据以及用不同的数据类型来描述复杂的对象。同时也回想起Python元组的一些性质如:元组属于不可变序列,不能修改元组中的元素,因此,元组没有增加元素,修改元素,删除元素相关的方法等性质。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值