Posted on Categories:CS代写, 算法, 计算机代写

# 计算机代写|算法代写Algorithm代考|CS341 Prim’s Algorithm

avatest™

## avatest™帮您通过考试

avatest™的各个学科专家已帮了学生顺利通过达上千场考试。我们保证您快速准时完成各时长和类型的考试，包括in class、take home、online、proctor。写手整理各样的资源来或按照您学校的资料教您，创造模拟试题，提供所有的问题例子，以保证您在真实考试中取得的通过率是85%以上。如果您有即将到来的每周、季考、期中或期末考试，我们都能帮助您！

•最快12小时交付

•200+ 英语母语导师

•70分以下全额退款

## 计算机代写|算法代写Algorithm代考|Prim’s Algorithm

In this section, we examine a second technique to construct minimum-weight spanning trees; namely, Prim’s algorithm. We again start with the intermediate spanning forest $\mathcal{F}$ that contains all the vertices of our input graph $G(V, E, w)$, but none of the edges. While Kruskal’s algorithm determines which edges to add to $\mathcal{F}$ by examining the entire graph, Prim’s algorithm takes a more local perspective. We provide as input a specified source vertex $s \in V(G)$. Let $T^$ be the component of $\mathcal{F}$ that contains $s$. Prim’s algorithm examines the edges of $G$ that have exactly one endpoint in $T^$ and select a light edge $e$ from these to add to $\mathcal{F}$. As $e$ has exactly one endpoint in $T^*, e$ connects two distinct components of $\mathcal{F}$. So by Corollary $61, e$ is a safe edge with respect to $\mathcal{F}$. This is the key observation in establishing that Prim’s algorithm returns a minimum-weight spanning tree.
We now turn to formalizing Prim’s algorithm.

We associate to each edge an attribute processed to indicate whether that edge has been placed into the priority queue. This ensures that each edge is considered at most once, which helps ensure that the algorithm will terminate.

Now at lines 6-8, we initialize the priority queue to contain only edges that are incident to the source vertex. This ensures that the first edge placed into the intermediate spanning forest is incident to the source vertex. Now by adding an edge to $\mathcal{F}$, we introduce a new vertex $v$ to the component containing our source vertex. Prim’s algorithm then adds to the prioritiy queue the edges incident to $v$, provided such edges have not already been polled from the queue. So the while loop at line 9 preserves the invariant that every edge in the priority queue has at least one endpoint in the component containing our source vertex.

Prim’s algorithm only adds an edge if it connects two components. Such an edge $e$ is polled from the priority queue, and so (i) has an endpoint in the component containing the source vertex, and (ii) is a minimum-weight edge connecting two distinct components. Therefore, $e$ is a safe edge.

## 计算机代写|算法代写Algorithm代考|Prim’s Algorithm: Example

We now work through an example of Prim’s algorithm.
Example 71. Consider the following graph $G(V, E, w)$ pictured below. Suppose we select the source vertex $A$.
Prim’s algorithm proceeds as follows.

1. We initialize the intermediate spanning forest to contain all the vertices of $G$, but no edges. We then initialize the priority queue to contain the edges incident to our source vertex $A$. So:
$$Q=[({A, B}, 10),({A, C}, 12)],$$
and our intermediate spanning forest $\mathcal{F}$ is pictured below.
A
F
C
E
2. We poll the edge ${A, B}$ from the queue and mark ${A, B}$ as processed. Note that $w({A, B})=10$. As ${A, B}$ has exactly one endpoint on the component containing $A$ (which is the isolated vertex $A$ ), we add ${A, B}$ to $\mathcal{F}$. We then push into the priority queue the unprocessed edges incident to $B$. So:
$$Q=[({B, C}, 1),({B, D}, 7),({A, C}, 12)],$$
and the updated intermediate spanning forest $\mathcal{F}$ is pictured below.

## 计算机代写|算法代写Algorithm代考|Prim’s Algorithm

Prim 的算法检萛边缘 $G$ 恰好有一个端点缺少上上标或下标参数

Prim 的算法仅在连接两个组件时才添加一条边。这样的边豚 $e$ 从优先级队列中轮询，因此 (i) 在包含源页点的组件中有一个端点， 并且 (ii) 是连接两个不同组件的最小权重边。所以， $e$ 是安全边。

## 计算机代写|算法代写Algorithm代考|Prim’s Algorithm: Example

Prim 的算法如下进行。

1. 我们初始化中间生成森林以包含所有的顶点 $G$ ，但没有边。然后我们初始化优先级队列以包含入射到我们的源项点的边 $A$. 所以:
$$Q=[(A, B, 10),(A, C, 12)]$$
和我们的中间生成林 $\mathcal{F}$ 如下图所示。
A
$\mathrm{F}$
C
E
2. 我们轮询边溕 $A, B$ 从队列中标记 $A, B$ 作为处理。注意 $w(A, B)=10$. 作为 $A, B$ 在包含的组件上只有一个端点 $A$ (这是孤 立的顶点 $A$ )，我们增加 $A, B$ 到 $\mathcal{F}$. 然后我们将末处理的边褖推入优先级队列 $B$. 所以:
$$Q=[(B, C, 1),(B, D, 7),(A, C, 12)],$$
和更新的中间生成林 $\mathcal{F}$ 如下图所示。

## MATLAB代写

MATLAB 是一种用于技术计算的高性能语言。它将计算、可视化和编程集成在一个易于使用的环境中，其中问题和解决方案以熟悉的数学符号表示。典型用途包括：数学和计算算法开发建模、仿真和原型制作数据分析、探索和可视化科学和工程图形应用程序开发，包括图形用户界面构建MATLAB 是一个交互式系统，其基本数据元素是一个不需要维度的数组。这使您可以解决许多技术计算问题，尤其是那些具有矩阵和向量公式的问题，而只需用 C 或 Fortran 等标量非交互式语言编写程序所需的时间的一小部分。MATLAB 名称代表矩阵实验室。MATLAB 最初的编写目的是提供对由 LINPACK 和 EISPACK 项目开发的矩阵软件的轻松访问，这两个项目共同代表了矩阵计算软件的最新技术。MATLAB 经过多年的发展，得到了许多用户的投入。在大学环境中，它是数学、工程和科学入门和高级课程的标准教学工具。在工业领域，MATLAB 是高效研究、开发和分析的首选工具。MATLAB 具有一系列称为工具箱的特定于应用程序的解决方案。对于大多数 MATLAB 用户来说非常重要，工具箱允许您学习应用专业技术。工具箱是 MATLAB 函数（M 文件）的综合集合，可扩展 MATLAB 环境以解决特定类别的问题。可用工具箱的领域包括信号处理、控制系统、神经网络、模糊逻辑、小波、仿真等。