Graph Theory: Representation and Algorithms

Summer Project - 2019
Graph Theory: Representation and Algorithms
1 Introduction
In order to complete this project successfully, the student should be familiar with many basic
notions of graph theory. The questions below whose answers should be included in the project
report will force the student to go over these necessary background notions about graphs. Most
of the background can be studied in the following references, specially Cormen textbook where
graph definitions can be found in Appendix B.4 and the Graph Algorithms can be read in chapters
22 to 26.
1. Introduction to Algorithms, T.H. Cormen et al., 3/e, The MIT Press, 2009.
2. Data Structures & Algorithms in Java, R. Lafore, 2/e, Sams Publishing, 2002.
3. Data Structures & Problem Solving Using C++, M. Weiss, 2/e, Pearson, 2003.
4. Data Structures & Algorithm in C++, M.T. Goodrich et al., 2/e, Wiley, 2011.
1.1 Theoretical Questions
Throughout all this project, we are only concerned with finite graphs.
1. Define the following concepts:
(a) Undirected graph (ungraph) G = (V,E).
(b) Directed graph (digraph) G = (V,E).
(c) Degree (deg) of a vertex in an ungraph.
(d) The in-degree (deg?) and the out-degree (deg+) of a vertex in a digraph.
(e) A simple graph.
(f) A path and simple path in an ungraph and a digraph.
(g) A cycle in ungraph and digraph.
(h) A (strongly) connected ungraph (digraph) and the (strongly) connected components of
a graph (digraph).
(i) A weighted graph.
(j) A directed acyclic graph (DAG).
2. Prove the following (where |E| is the number of edges in G):
(a) If G = (V,E) is an ungraph then

v∈V
degv = 2|E|.
(b) If G = (V,E) is a digraph then

v∈V
deg+ v = ∑
v∈V
deg v = |E|.
3. Prove that any undirected graph has an even number of vertices of odd degree.
4. Show that in a simple graph with at least two vertices there must be two vertices that have
the same degree.
5. Give the definition of a complete graph G = Kn with n vertices. What is the number of edges
in Kn? Explain how this is computed.
6. Given the following digraph G = (V,E)
Figure 1: Digraph.
(a) Give the in-degree and the out-degree of each vertex of G.
(b) Give its adjacency-list representation.
(c) Give its adjacency-matrix representation.
(d) List all the directed cycles in G.
(e) List all the cycles in the underlying undirected graph Gu of G.
(f) Is G strongly connected?
(g) What are its strongly connected components?
2
7. Consider the digraph below.
(0,0) (1,0) (2,0) (3,0)
(0,1) (1,1) (2,1) (3,1)
(0,2) (1,2) (2,2) (3,2)
(0,3) (1,3) (2,3) (3,3)
(a) How many different directed simple paths are there from vertex (3,1) to vertex (3,3)?
List all of them by giving the ordered sequence of vertices.
(b) How many strongly connected components are there in this graph? Specify all of them
by giving the list of vertices.
8. Given an adjacency-list representation of a directed graph, how long does it take to compute
the out-degree of every vertex? How long does it take to compute the in-degrees?
9. The transpose of a directed graph G = (V,E) is the graph G
T = (V,ET), whereE
T = {(v,u) ∈ V ×V : (u, v) ∈ E}.
Thus, GT
is G with all its edges reversed. Describe efficient algorithms for computing GT
from G, for both the adjacency-list and adjacency-matrix representations of G. Analyze the
running times of your algorithms.
10. Give examples of:
(a) Digraphs that are not DAGs
(b) DAGs whose underlying ungraph has (undirected) cycles.
(c) DAGS whose underlying ungraph has no cycles.
3
11. Describe the Depth-First-Traversal and the Breadth-First-Traversal procedures (as described
in Cormen). Show the results of the DFT on the digraph in Figure. Assume that the for
loop of lines 5-7 of the DFT procedure considers the vertices in alphabetical order, and

代写Graph Theory作业、代做Data Structures作业、代写C++,Java程序语言作业
assume that each adjacency list is ordered alphabetically. Show the discovery and finishing
times for each vertex, and show the classification of each edge.
Figure 2: A digraph for DFS.
12. Describe the algorithm based on the DFS for producing a topological sort order when the
digraph is a DAG.
13. Show the ordering of vertices produced by TOPOLOGICAL-SORT when it is run on the
dag of Figure ??, under the assumption of the previous exercise.
Figure 3: DAG for Topological Sorting.
14. Describe the Dijkstra’s single-source shortest-paths algorithm and run it on the directed
graph of Figure, first using vertex s as the source and then using vertex z as the source.
Show all the results.
Figure 4: A digraph for shortest path.
4
2 Programming Project
This project involves implementing an adjacency list representation of a weighted graph, and
using it to apply Dijkstra’s shortest paths algorithm (single-source, all destinations(SSAD)) to a
weighted directed graph. The program will read the specification of the problem from a given file
named for instance "File.txt ". The input file will begin with two lines specifying the number of
vertices in the graph, G = (V,E), and the source vertex. Each of those values will be preceded by
a label that ends with a colon character (‘:‘). The next line will be blank. The remainder of the file
will be a matrix (similar to the adjacency-matrix representation) of |V| rows, each containing |V|
integer values for the weights of the edges in the graph. Weights will be integers in the range 1 to
99. Missing edges will be designated by the value 0. Here’s an example:
Output will be written to a file named for instance "Result.txt ". The output file should consist of
two sections, one displaying information about the given graph and the other displaying the results
of running the Dijkstra’s shortest paths SSAD algorithm.
The graph information display consists of a row of labels (see example), followed by |V| rows of
output displaying the graph information in a format similar to the adjacency-list representation of
the graph. For each vertex, there will be one row of data listing the vertex number, followed by a
list of neighbor records. A neighbor record consists of a neighbor (vertex) number, followed by a
colon character, followed by the weight of the corresponding edge. The graph information display
is followed by a blank line.
The SSAD results display begins with two lines of labels (see example), one showing the source
vertex and a blank line, followed by |V| rows showing the results for each possible destination
vertex (including the source vertex itself). Each of these lines consists of three sections, the destination
vertex number, the length (total weight) of the shortest path found, and the actual path
(a sequence of vertex numbers separated by spaces). If a vertex is not reachable from the source
vertex, you should display instead of the length.
5
Here’s an output example that corresponds to the input example above:
2.1 Notes
There are some explicit requirements for the programming project:
Code has to be written in C++, no other platform is accepted.
You must implement a C++ class for the weighted adjacency list representation of a directed
graph; whether it is a template or not is entirely up to you.
Your main class must be called digraph.
The data read from a file and specifying the graph can be stored in a dynamic one dimensional
or two dimensional array as a private member of the class together with the source
vertex.
6
That class must include a member function that writes the display of the graph in the proper
format indicated above.
You have to write an extensive REPORT containing the answers to the 14 theoretical questions
and explaining the programming project, and how to operate your program. For each
input file specification, you have to draw the corresponding digraph in your report and
HIGHLIGHT the shorted path found by the Dijkstra’s SSAD algorithm for each destination
vertex (when the path exists obviously).
Dijkstra’s SSAD algorithm must be implemented as a separate function, not as a member
of the digraph class. That function should take an initialized graph object as one of its
parameters (and the source vertex as the second), and compute the path lengths and shortest
paths, but it should not write any of the display to the output file. That should be done by a
different function that creates the necessary digraph object and calls the SSAD method.
Since you’ll be implementing the complete program, the interfaces of the digraph class and
the SSAD function are up to you.
2.2 Testing
We will include a number of files specifying weighted graphs, and the corresponding SSAD solutions.
You may want to develop additional test cases yourself (there will be some bonus points for
doing that). For marking purposes, it is important to format your output as specified above.

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected]

微信:codehelp

原文地址:https://www.cnblogs.com/clearc/p/11336280.html

时间: 2024-11-05 14:39:53

Graph Theory: Representation and Algorithms的相关文章

Graph Theory Algorithms

1 /** 2 * 图论 3 **/ 4 5 /***************************** 图的抽象数据类型 ************************************/ 6 ADT Graph 7 { 8 数据: 9 Graph = (Vertex, Edge)是可以用不同方式存储的图,Vertex是顶点集, 10 Edge = {<vertex_1, vertex_2> | vertex_1, vertex_2属于Vertex,vertex_1不等于verte

2017 UESTC Training for Graph Theory

2017 UESTC Training for Graph Theory A       思维 题意:给你一个有n个点和m条边的无向连通图,每条边都有一个权值w.我们定义,对于一条路径,它的Charm value为该路径上所有边的权值的最大值与最小值的差.询问从1到n的所有路径的Charm value的最小值. tags:有点思维定式了..一条路径里只要最大最小值,所以边可以重复走.这样我们只要把边从小到大枚举,把第 i 条边作为最小边,然后对于每个 i ,我们按顺序逐一加入比它大的边,直到点

Graph Theory

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 140    Accepted Submission(s): 74 Problem Description Little Q loves playing with different kinds of graphs very much. One day he thought about

ACM学习历程—NPU1045 2015年陕西省程序设计竞赛网络预赛(热身赛)C题 Graph Theory(递推 &amp;&amp; 组合数学 &amp;&amp; 大数)

Description In graph theory, a matching or independent edge set in a graph G = (V , E) is a set of edges ME such that no two edges in the matching M share a common vertex. The Nobel Prize in XiXiHaHa was awarded to Jerryxf team, amongst other things,

2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Problem L. Graph Theory Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1536    Accepted Submission(s): 830 Problem Description Ther

图论介绍(Graph Theory)

1 图论概述 1.1 发展历史 第一阶段: 1736:欧拉发表首篇关于图论的文章,研究了哥尼斯堡七桥问题,被称为图论之父 1750:提出了拓扑学的第一个定理,多面体欧拉公式:V-E+F=2 第二阶段(19~20世纪): 1852: Francis Guthrie提出四色问题 1856: Thomas P. Kirkman & William R.Hamilton研究了哈密尔顿图 1878: Alfred Kempe给出给出四色定理证明 1890: 希伍德(Heawood)推翻原有四色定理证明 1

TCO14 2C L2: CliqueGraph,graph theory, clique

称号:http://community.topcoder.com/stat?c=problem_statement&pm=13251&rd=16017 參考:http://apps.topcoder.com/wiki/display/tc/TCO+2014+Round+2C 假设用先计算出每条边,用邻接矩阵来表示图,然后用BFS或 Floyd-Warshall算法来计算距离的话.时间复杂度是O(N^3),会超时.依据题名的提示知要利用clique graph的性质来做.基本思想是在BFS的

2017 Training for Graph Theory

A - 梦后楼台高锁,酒醒帘幕低垂(并查集 + 贪心) 给你一个有nn个点和mm条边的无向连通图,每条边都有一个权值ww.我们定义,对于一条路径,它的Charm valueCharm value为该路径上所有边的权值的最大值与最小值的差.询问从11到nn的所有路径的Charm valueCharm value的最小值. Input 第一行有两个整数n,m(1≤n≤200,n−1≤m≤1000)n,m(1≤n≤200,n−1≤m≤1000),表示该图有nn个点和mm条边.接下来mm行,每行三个整数

UESTC_方老师和农场 2015 UESTC Training for Graph Theory&lt;Problem L&gt;

L - 方老师和农场 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status 方老师重新开了一家农场,农场一共有N个节点和M条双向边,但是有一个很大的问题就是有比如一个农场A到达农场B只有一条路径,问至少添加多少条边使得任意两个农场之间的路径多于一条. Input 多组数据,EOF结束. 第1行:N和M. 第2到第M+1行:每一行2个数Ui和Vi,表示Ui到