数学表达式魔训作业Day4

11. 图与网络

作业:

  1. 写出该无向图的邻接矩阵.

[ 0 1 1 1 1 0 1 0 1 1 0 1 1 0 1 0 ] \left[\begin{array}{llll}0 & 1 & 1 & 1\\ 1 & 0 & 1 & 0\\ 1 & 1 & 0 & 1\\ 1 & 0 & 1 & 0 \end{array}\right] 0111101011011010

  1. 定义无向网络

A undirected net is a tuple G = ( V , w ) 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 \mathbf{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 and w ( v j , v i ) w(v_j, v_i) w(vj,vi) is the weight of the arc ⟨ v j , v i ⟩ \langle v_j, v_i \rangle vj,vi.

12. 树

作业:

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

在这里插入图片描述
This tree is a triple T = ( V , r , p ) T = (\mathbf{V}, r, p) T=(V,r,p);
V = { v 0 , v 1 , v 2 , v 3 , v 4 } V = \{v0, v1, v2, v3, v4\} V={v0,v1,v2,v3,v4};
r = v 0 r = v0 r=v0;
p ( v 3 ) = p ( v 4 ) = v 1 , p ( v 1 ) = p ( v 2 ) = v 0 , p ( v 0 ) = ϕ p(v3) = p(v4) = v1, p(v1) = p(v2) = v0, p(v0) = \phi p(v3)=p(v4)=v1,p(v1)=p(v2)=v0,p(v0)=ϕ

  1. 针对该树, 将代码中的变量值写出来 (特别是 parent 数组).
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; // 即 \phi
	}// Of the constructor
}//Of class Tree

n = 6;
root = 0;
parent = [0, 1, 2, 3, 4, -1]

13. m 叉树

作业:

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

在这里插入图片描述
[ 1 2 3 4 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 − 1 ] \left[\begin{array}{llll}1 & 2 & 3 \\ 4 & -1 & -1\\ -1 & -1 & -1\\ -1 & -1 & -1\\-1 & -1 & -1 \end{array}\right] 141112111131111

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

A tree is a 5-tuple T = ( Σ , V ′ , r , ϕ , p ) T = (\Sigma, \bm{V'}, \bm{r}, \bm{\phi}, p) T=(Σ,V,r,ϕ,p), where

  • Σ \Sigma Σ is the alphabet, Σ = { k } \Sigma= \{k\} Σ={k} ;
  • V ′ \bm{V'} V is the set of states, V ′ = V ∪ { ϕ } \bm{V'}=\bm{V} \cup \{\phi\} V=V{ϕ}, V = { v 1 , … , v n } \mathbf{V} = \{v_1, \dots, v_n\} V={v1,,vn} ;
  • r ∈ V ′ r \in \bm{V'} rV is the root;
  • ϕ ∈ V ′ \phi \in \bm{V'} ϕV is the terminal states;
  • p : V ′ × Σ ∗ → V ′ p: \bm{V'}\times \Sigma^* \to \bm{V'} p:V×ΣV is the transition function, satisfying ∀ v ∈ V \forall v \in \bm{V} vV, ∃ 1 \exists 1 1 s ∈ Σ ∗ s \in \Sigma^* sΣ st. c ( v , s ) = r c(v, s) = r c(v,s)=r.
  1. 根据图、树、m mm-叉树的学习, 谈谈你对元组的理解.

我认为元组就是将对象的几个属性集合起来对对象进行描述。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值