CSE 101 Data Structures and Algorithms

CSE 101 Introduction to Data Structures and Algorithms Programming 6C/C++ 101gorithmsAssignment6to⋯ ⋯⋯ +xb2≤263−1normalizedx。 阅读详情

CSE 101

Introduction to Data Structures and Algorithms

Programming Assignment 3

In this assignment you will build a Graph module in C that implements the Depth First Search (DFS) algorithm. You will use your Graph module to find the strongly connected components of a digraph.  Read the handout on graph algorithms, and sections 22.3-22.5 of the text.  Also see the pseudo-code posted on the class webpage at Examples/Pseudo-Code/GraphAlgorithms.

A digraph G = (V, E) is said to be strongly connected iff for every pair of vertices u, v ∈ V, vertex u is reachable from v, and vertex v is reachable from u.  Most directed graphs are not strongly connected.  In general, we say a subset X ⊆ V is strongly connected iff every vertex in X is reachable from every other vertex in X.  A strongly connected subset that is maximal with respect to this property is called a strongly connected component of G.  In other words, X  ⊆ V isa strongly connected component of G, if and only if (i) X is strongly connected, and (ii) the addition of one more vertex to X would create a subset that is not strongly connected.

Example

We can see that this digraph contains 4 strongly connected components:   C1   = {1, 2, 5}, C2   = {3, 4}, C3  = {6, 7}, and C4   = {8}.

To find the strong components of a digraph G call DFS(G).  As vertices are finished, place them onto a stack.  When DFS is complete the stack will store the vertices ordered by decreasing finish times.  Next, compute the transpose GT  of G.  (The digraph GT   is obtained by reversing directions on all edges of G.) Finally run DFS(GT ), but in the main loop (lines 5-7) of DFS, process vertices in order of decreasing finish times from the first call to DFS.  This is accomplished by popping vertices off the stack.  When the whole process is complete, the trees in the resulting DFS forest span the strong components of G. Note the strongly connected components of G are identical to the strong components of GT .   See the algorithm  Strongly- Connected-Components in section 22.5 (p.617) of the text.

Your graph module will again use the adjacency list representation.   It will, among other things, provide the capability of running DFS, and computing the transpose of a directed graph.  DFS requires that vertices possess attributes for color (white, black, grey), discover time, finish time, and parent.  Below is a catalog of required functions and prototypes, constituting the majority of Graph.h.

// Constructors-Destructors

Graph newGraph (int n);

void freeGraph (Graph* pG);

// Access functions

int getOrder(Graph G);

int getSize(Graph G);

int getParent(Graph G, int u);  /* Pre: 1<=u<=n=getOrder(G) */

int getDiscover(Graph G, int u);   /* Pre: 1<=u<=n=getOrder(G) */

int getFinish(Graph G, int u);   /* Pre: 1<=u<=n=getOrder(G) */

// Manipulation procedures

void addArc (Graph G, int u, int v);  /* Pre: 1<=u<=n, 1<=v<=n */

void addEdge(Graph G, int u, int v);  /* Pre: 1<=u<=n, 1<=v<=n */

void DFS(Graph G, List S);    /* Pre: length (S)==getOrder(G) */

// Other Functions

Graph transpose (Graph G);

Graph copyGraph(Graph G);

void printGraph(FILE* out , Graph G);

Function newGraph() will return a reference to a new graph object containing n vertices and no edges. freeGraph() frees all heap memory associated with a graph and sets its Graph argument to NULL. Function getOrder() returns the number of vertices in G, while functions getParent(), getDiscover(), and getFinish() return the appropriate field values for the given vertex.  Note that the parent of a vertex may be NIL.  The discover and finish times of vertices will be undefined before DFS is called.   You must #define constant macros for NIL and UNDEF representing those values and place the definitions in the Graph.h.   The descriptions of functions addEdge() and addArc() are exactly as they were in pa2.  Note that, as in pa2, it is required that adjacency lists are always processed in increasing order by vertex label. It is the responsibility of functions addEdge() and addArc() to maintain adjacency lists in sorted order.

Function DFS() will perform. the depth first search algorithm on G.  The List argument S has two purposes in this function.  First it defines the order in which vertices are to be processed in the main loop (5-7) of DFS.   Second, when DFS  is complete, it will store the vertices by decreasing finish times (hence S is considered to be a stack). Thus S can be classified as both an input and output parameter to function DFS(). You should utilize the List module from pa1 to implement S and the adjacency lists representing G.  DFS() has two preconditions: (i) length(S) == n, and (ii) S contains some permutation of the integers {1, 2, … , n} where n = getOrder(G).  You are required to check the first precondition but not the second.

Recall DFS() calls the recursive algorithm Visit() (referred to as DFS-Visit() in the text), and uses a variable called time that is static over all recursive calls to Visit().  Observe that this function is not mentioned in the above catalog (Graph.h) and therefore is to be considered a private helper function in Graph.c.  There are at least three possible approaches to implementing Visit(). You can define Visit() as a top-level function in Graph.c and let time be a global variable whose scope is the entire file.  This option has the drawback that other functions in Graph.c have access to time and would be able to alter its value.  For this reason, global variables are generally considered to be a poor programming practice.  The second approach is to let time be a local variable in DFS(), then pass the address of time to Visit(), making it an input-output variable to Visit(). This is perhaps the simplest option, and is recommended. The third approach is to again let time be a local variable in DFS(), then nest the definition of Visit() within the definition of DFS(). Since time is local to DFS(), its scope includes the defining block for Visit() and is therefore static throughout all recursive calls to Visit(). This maybe tricky if you’re not used to nesting function definitions since there are issues of scope to deal with.  If you pick this option, first experiment with a few examples to make sure you know how it works.  Note that although nesting function definitions is not a feature of standard C, and is not supported by many compilers, it is supported by the GNU gcc compiler (see https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html.)       There's   actually    a    fourth   option    for implementing time that may be the easiest of all.  Just give Visit() its own local copy of time, then let it take the current value of time as input, and return the new value of time when it's done.  No global variable, no passing by reference and no nested function definitions.  These design decisions are left to you, and are the type of thing that should be stated in your README.md file.

Function transpose() returns a reference to  a new graph object representing the transpose of G, and copyGraph() returns a reference to a new graph that is a copy of G.  Both transpose() and copyGraph() may be considered constructors since they create new graph objects.  Function printGraph() prints the adjacency list representation of G to the file pointed to by out.  Obviously, there is much in common between the Graph module in this project and the one in pa2.  If you wish, you may simply add functionality necessary for this project to the previous one, although it is not required that you do so.   You should make note of choices such as this in your README.md file.

The client of your Graph module will be called FindComponents. It will take two command line arguments giving the names of the input and output files respectively:

$ FindComponents infile outfile

FindComponents.c will do the following:

•   Read the input file.

•   Assemble a graph object G using newGraph() and addArc().

•   Print the adjacency list representation of G to the output file.

•   Run DFS on G and GT , processing the vertices in the second call by decreasing finish times from the first call.

•   Determine the strong components of G.

•   Print the strong components of G to the output file in topologically sorted order.

After the second call to DFS(), the List parameter S can be used to determine the strong components of G, and to determine a topological  sort of those  components.   You  should trace the algorithm  Strongly- Connected-Components (p.617) on several small examples, keeping track of the List S to see how this can be done.  Input and output file formats are illustrated in the following example, which corresponds to the directed graph on the first page of this handout:

Input:                                           Output:

8                                                   Adjacency list representation of G:

1 2                                                1: 2

2 3                                                2: 3 5 6

2 5                                                  3: 4 7

2 6                                                  4: 3 8

3 4                                                5: 1 6

3 7                                                6: 7

4 3                                                7: 6 8

4 8                                                   8: 8

5 1

5 6                                                 G contains 4 strongly connected components:

6 7                                                Component 1: 1 5 2

7 6                                                 Component 2: 3 4

7 8                                                Component 3: 7 6

8 8                                                 Component 4: 8

0 0

Observe that the input file format is very similar to that of pa2.  The first line gives the number of vertices in the graph, subsequent lines specify directed edges, and input is terminated by the ‘dummy’ line 0 0.  You are required to submit the following eight files:

README.md Makefile

List.h

List.c

Graph.h

Graph.c

GraphTest.c

FindComponents.c

As usual README.md contains a catalog of submitted files and any special notes to the grader.  Makefile should be capable of making the executables GraphTest and FindComponents and should contain a clean utility that removes all binary files.   Graph.c  and  Graph.h  are  the  implementation and interface files respectively for your Graph module.   GraphTest.c will  contain your own tests of your  Graph module. FindComponents.c implements the top-level client and main program for this project.   To get full credit, your project must implement all required files and functions, compile without errors or warnings, produce correct output on our unit tests, and produce no memory leaks under valgrind.  By now everyone knows that points are deducted both for neglecting to include required files, for misspelling any filenames and for submitting additional unwanted files but let me say it anyway: do not submit binary files of any kind.

Note that FindComponents.c needs to pass a List to the function DFS(), so FindComponents.c is also a client of the List module.  In fact, any client of Graph is also a client of List just by the presence of the List parameter to DFS().  Therefore Graph.h should itself #include the file List.h.  (See the handout entitled C Header File Guidelines for more on this topic.)

A Makefile for this project will be posted on the course webpage which you may alter as you see fit.  As usual start Early and ask questions if anything is not completely clear.

【信息科学与工程学】【制造工程】第三十六篇 机械工程与自动化101 本系统通过多模型集成、知识增强、主动学习和持续优化等关键技术,实现了高效、高质量的自动化文本语料标注。系统采用模块化设计,支持灵活扩展,能够处理不同类型的文本数据,适应多样的标注需求。 阅读详情

相关推荐

cse101_computer_history:CSE101计算机历史作业

这是供我们使用GIT存放的示例自述文本文件 记忆与储存 介绍: Electronic computer memory and storage was first created in the 1940’s using the Manchester Mark I Williams-Kilburn tube. This creation drastically revolutionized the usage of computers by speeding up data storage and recovery. Over the past 70 years computer memory and storage have evolved greatly. Now we have the ability to create a whole computer the size of a r

企业数据孤岛破解与智能体集成技术实践

数据孤岛是企业数字化转型中的典型挑战,指不同系统间数据无法互通的状态。其成因包括技术异构性、组织壁垒和历史系统遗留问题,导致数据利用率低下和业务效率损失。现代数据集成技术通过控制平面与数据平面的双层架构,结合流批一体的处理能力,实现数据的自由流动与智能协作。其中,智能体技术采用发布-订阅模式,使各业务单元像数字员工般协同工作,在风控、营销等场景展现价值。典型实践表明,采用Kafka、Flink等技术栈可有效提升吞吐量并控制延迟,而分层缓存和异步处理等优化手段能显著提高系统性能。通过分阶段实施和持续运营,企业

weixin_30325971的博客 416

FPGA新手避坑指南:手把手教你搞定RTL8211千兆网PHY的时序配置(附Verilog代码)

本文详细解析了FPGA与RTL8211千兆网PHY芯片的时序配置问题,重点介绍了TXDLY/RXDLY引脚设置、FPGA发送端和接收端的Verilog实现,以及调试与验证的完整流程。通过硬件电路设计和代码示例,帮助开发者解决网络连接不稳定、丢包等常见问题,提升千兆网通信的稳定性。

weixin_28732953的博客 544

Day2 CSE101 L2

Lecture 2 Input-Process-Output Model :Input data -->Process -->Output data 1. Thiswas an essential scheme of the von Neumann model. 2. Three componentsrequired for this model: Ha...

weixin_30446197的博客 274

Hopf振荡器在机器人步态控制里到底怎么用?一个CPG仿生案例说清楚

本文深入解析了Hopf振荡器在机器人步态控制中的实际应用,通过CPG仿生案例详细展示了从数学方程到关节指令的完整流程。重点探讨了Hopf振荡器的极限环稳定性、参数调节技巧及自适应控制策略,为机器人运动控制提供了高效解决方案。

weixin_29284657的博客 203

unity中判断是否联网,判断网络状态的两种方式

unity中判断是否联网,判断网络状态的两种方式

wla2996gpy032的博客 1879

XJTLU CSE101 revision note

/* This is my revision note of the CSE101 module. Hopefully you can find it somehow helpful. ------by Livingstone, 2020. */ Overview of this course How the computer works at the machine code level Un...

weixin_44573514的博客 2991

2.1 SRv6 TE Policy

SRv6 TE Policy是在SRv6技术基础上发展的一种新的隧道引流技术。SRv6 TE Policy路径表示为指定路径的段列表(Segment List),称为SID列表(Segment ID List)。每个SID列表是从源到目的地的端到端路径,并指示网络中的设备遵循指定的路径,而不是遵循IGP计算的最短路径。如果数据包被导入SRv6 TE Policy中,SID列表由头端添加到数据包上,网络的其余设备执行SID列表中嵌入的指令。

m0_70976024的博客 1238

CSE 101 Introduction to Data Structures and Algorithms Programming 4Python

101hmsAssignment4sparseAandBijCith row ofAwith thejBnAandBThe sumSD, ofAandB−BijxwithAAAAAAandBtype x;naandbaAbB3 9 51 1 1.01 2 2.01 3 3.02 1 4.02 2 5.02 3 6.03 1 7.03 2 8.03 3 9.0。

gave3gift的博客 766

IPD的分析工具与模型(十六)CBB公用基础模块管理实现资源共享,缩短开发周期

CBB流程的开发环节,基于CBB规划中所识别和设计的CBB,进行CBB的详细设计(包括参数设计和接口设计),并最终实现CBB的落地开发。作为特殊类型的技术构件,CBB的开发流程,可沿用技术开发中的构件开发流程,具体包括概念、计划、开发和迁移等步骤,具体可参见前文的相关介绍。有了蓝图与架构设计,落地实施是关键攻坚。具体工作内容包括:具体工作内容包括:a. 以相似性、聚类、相对独行性、可组合、可扩展性、可维护性等原则为指导,按照产品的功能特征和业务类型,聚焦零散的功能点,形成功能模块,实现产品功能模块的划分;

corgi2020的博客 2008

深入Linux内核:PTP硬件时间戳(HW Timestamp)是如何炼成的?

本文深入探讨了Linux内核中PTP硬件时间戳(HW Timestamp)的实现原理与实战应用。通过分析IEEE 1588协议在网络时间同步中的关键作用,详细解析了硬件时间戳在Linux内核中的架构设计、驱动开发及性能优化技巧,帮助开发者实现纳秒级精度的时间同步。

weixin_30727835的博客 655

CSE 101 Introduction to Data Structures and Algorithms Programming 2Haskell

101AlgorithmsAssignment1: 2 32: 1 4 5 63: 1 44: 2 3 55: 2 4 66: 2 5n, wherennn61 21 32 42 52 63 44 55 60 0nparent3 40 02 36 73 6GssourceGssssvsstovGfromstovkfromsk+vinGcolorv。

gave2gift的博客 595

C#与倍福Plc通信——使用仿真软件模拟倍福PLC运行

安装这个软件之前先安装VisualStudio,本文安装这个软件时已经安装了VisualStudio2019。1、下载倍福PLC编程软件TwinCAT。

qq_34059233的博客 3667

CSE 101 Introduction to Data Structures and Algorithms Fall 2024C/C++

101AlgorithmsFalland CSE 16;and CSE 30;DataStructuresC++15%115%Final Exam。

gruningrain的博客 523

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

CSE 101 Introduction to Data Structures and Algorithms Midterm 2 Review ProblemsC/C++

101Problems1) 2n3) n4) 2ln(n)6) n√n7) n28) ln(n2)9) √nwithoutexceptcleanup().Formula。

gavegift的博客 665

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

CSE 101 Introduction to Data Structures and Algorithms Winter 2025C/C++

101lgorithmsand CSE 16;and CSE 30;AlgorithmsDataStructuresDataC++15%15%20%Final Exam。

fought3的博客 351

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

CSE 101 Introduction to Data Structures and Algorithms Winter 2024C/C++

101AlgorithmsWinterand CSE 16;and CSE 30;ptantalo/DataStructuresC++1Final Exam。

bitstdcadd的博客 486

CSE 101 Introduction to Data Structures and Algorithms Final Review ProblemsC/C++

101a. n√n = Ω(n2)b. nπ= O(n3)c. n2Θ(9log3n))d. n√3n = ω (√n)ω(n1.45)int key;Node* left;12345678910d[x]p[x]TT。

leijunmingg的博客 560

CSE 101 Introduction to Data Structures and Algorithms Programming 3C/C++

101AlgorithmsAssignment3stronglyconnecteduvvustronglyconnectedXXstronglyconnectedcomponentofGGGGGnGSwithinisGGGGSGS5 10 0List.hList.cGraph.hGraph.cCGuidelines。

gave3gift的博客 485

【算法拾光】队列|在每个树⾏中找最⼤值 + 最后⼀块⽯头的重量

本文总结两道经典算法题:一是通过层序遍历(BFS)逐层找最大值,利用队列分层处理,每层维护最大值;二是用大根堆(优先队列)模拟石头碰撞过程,每次取最大两块石头,差值重新入堆,直至剩余一块或无石。前者适用于树的层次遍历,后者适合动态获取最值场景。核心思想:队列用于分层遍历,堆用于高效取极值。

wuqingyigexiaoba的博客 202

把 KV Cache 压到 FP4:BitDecoding-FP4 的算法-系统协同设计复盘

长上下文推理卡在KV Cache的显存与带宽上,而现有FP4方案要么精度崩、要么速度废。这篇文章复盘BitDecoding-FP4如何用三个算法补丁加一个系统重构,在B300上把服务吞吐提升2.4–3.0倍,精度几乎不掉。

helloagent的博客 319

【算法拾光】链表 哈希表|K个一组翻转链表 + 两数之和

K个一组翻转链表需分段反转,借助哑节点与前驱指针维护连接,避免断链;两数之和利用哈希表实现O(1)查找,空间换时间,高效定位目标组合。前者考察链表指针操作,后者聚焦映射关系构建,均为面试高频题。

wuqingyigexiaoba的博客 341

排序算法深度笔记(下):非比较类排序的线性突破与工程边界

排序算法时间复杂度额外空间复杂度稳定性是否基于比较选择排序O(N^2)(O(1))不稳定是冒泡排序O(N^2)(O(1))稳定是插入排序O(N^2)(O(1))稳定是归并排序O(N\log N)(O(N))稳定是快速排序O(N\log N)O(log N)不稳定是堆排序O(N\log N)O(1)不稳定是计数排序(O(N + M))O(M))稳定否基数排序O(N)稳定否桶排序平均O(N) / 最坏O(N^2)

2401_87069538的博客 617

优选算法:分治-归并排序

交易逆序对的总数

Wangshijie1015的博客 154

408 算法 06|堆与 Top-K:最小的 10 个数,到底该用数组还是堆

2022(42) 找 100 万个数里最小的 10 个,官方给了"10 元素有序数组"和"大根堆"两种答案。我把两种都实现并数了比较次数:k=10 时两者几乎打平,k=10000 时堆少 111 倍。另附 2021(42) 计数排序的比较次数与稳定性实测。

m0_56226131的博客 453
上一篇: CET313 - Artificial Intelligence
下一篇: EY Data Science Take Home Challenge
wx____codehelp
博客等级 码龄2年 538粉丝 99原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值