Week1-1Dynamic Connectivity

来源:互联网 发布:爱淘宝红包链接 编辑:程序博客网 时间:2024/06/05 11:08

Steps to developing a usable algorithm


Given a set of N objects, main operations are:

-Union Command: Connect 2 objects: union( a, b )
-Find/Connected query: is there a path connecting the 2 objects? connect ( a, b )


Answer the question if there is a path between 2 points in the map, not to find out the path( in Part 2 ).


Applications

这里写图片描述


Modelling the Connection

-Reflexive
-Symmetric
-Transitive

Connected Component

Maximal set of objects that have mutually connected.

Find Query

Check if 2 objects are in the same connected component.

Union Command

Replace components containing 2 objects with their union.


Data Type API

这里写图片描述

Test Code

这里写图片描述

0 0
原创粉丝点击