Graphs and Minimum Cuts(Karger's Min-Cut Algorithm)
Graphs
Two ingredients
1. vertices (nodes) v
2. edges(undirected or directed)
Examples: road networks, the web, social networks
The minimum Cut problem
Input: undirected graph G = (V, E) (parallel edges allowed)
Goal: compute a cut with fewest number of Crossing edges (a min cut)
Sparse vs. Dense Graphs
let n = # of vertices, m = # of edges
In most applications, m is Omega(n) and O(n^2)
In a "sparse graph", m is O(n) or close to it
In a "dense graph", m is closer to Theta(n^2)
Two ways to represent a Graph
1. The Adjacency Matrix
2. The Adjacency List
Which one is better? Depends on graph density and operation needed.
Random Contraction Algorithm
while there are more than 2 vertices:
-pick a remaining edge(u, v) uniformly at random
-merge(or "contract") u and v into a single vertex
-remove self-loops
return cut represented by final 2 vertices
Karger's Min-Cut Algorithm -------Random Contraction Algorithm(Python code):
import random
import copy
import time def contract(ver, e):
while len(ver) > 2: #create a new graph every time (not efficient)
ind = random.randrange(0, len(e))
[u, v] = e.pop(ind) #pick a edge randomly
ver.remove(v) #remove v from vertices
newEdge = list()
for i in range(len(e)):
if e[i][0] == v: e[i][0] = u
elif e[i][1] == v: e[i][1] = u
if e[i][0] != e[i][1]: newEdge.append(e[i]) # remove self-loops
e = newEdge
return(len(e)) #return the number of the remained edges if __name__ == '__main__':
f = open('kargerMinCut.txt')
_f = list(f)
edges = list() #initialize vertices and edges
vertices = list()
for i in range(len(_f)): #got 2517 different edges
s = _f[i].split()
vertices.append(int(s[0]))
for j in range(1, len(s)):
if [int(s[j]), int(s[0])] not in edges:
edges.append([int(s[0]), int(s[j])]) result = list()
starttime = time.clock()
for i in range(2000): #we take n^2logn times so that the Pr(allfail) <= 1/n where n is the number of vertics
v = copy.deepcopy(vertices) #notice: deepcopy
e = copy.deepcopy(edges)
r = contract(v, e)
result.append(r)
endtime = time.clock()
#print(result)
print(min(result))
print(endtime - starttime)
Graphs and Minimum Cuts(Karger's Min-Cut Algorithm)的更多相关文章
- ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)
题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...
- 关于Yuri Boykov and Vladimir Kolmogorov 于2004年提出的max flow / min cut的算法的详解
出处:http://blog.csdn.net/euler1983/article/details/5959622 算法优化algorithmgraphtree任务 这篇文章说的是Yuri Boyko ...
- 图的最小切隔问题Minimum Cuts
前提条件是这样的:输入一个图(可以是有向图,也可以是无向图,允许平行边存在),我们要做的事情是将这个图切割成两个子图,(切割的定义:将图中的所有顶点分为两个集合A和B,要求这两个集合非空)假设这个图中 ...
- HDU 6214.Smallest Minimum Cut 最少边数最小割
Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Oth ...
- HDU 6214 Smallest Minimum Cut(最少边最小割)
Problem Description Consider a network G=(V,E) with source s and sink t. An s-t cut is a partition o ...
- Smallest Minimum Cut HDU - 6214(最小割集)
Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Oth ...
- HDU - 6214:Smallest Minimum Cut(最小割边最小割)
Consider a network G=(V,E) G=(V,E) with source s s and sink t t . An s-t cut is a partition of nodes ...
- HDU 6214 Smallest Minimum Cut 【网络流最小割+ 二种方法只能一种有效+hdu 3987原题】
Problem Description Consider a network G=(V,E) with source s and sink t . An s-t cut is a partition ...
- HDU-6214 Smallest Minimum Cut(最少边最小割)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 Problem Description Consider a network G=(V,E) w ...
随机推荐
- jQuery HTML CSS 方法
jQuery HTML / CSS 方法 下面的表格列出了所有用于处理 HTML 和 CSS 的 jQuery 方法. 下面的方法适用于 HTML 和 XML 文档.除了:html() 方法. 方法 ...
- 3D Game Programming with directx 11 习题答案 8.2
第八章 第二题 1.首先找到Directx Texture Tool,它位于 2.填入配置 3.用画图工具画好每个level的图片,例如level0 4.用Directx Texture Tool添加 ...
- How To Read a Paper.md
@ Titile How To Read a Paper.md @ author Keshav, 译 uuplusu # 1. Intro 1. 读论文重要 2. 没有人教 3. ...
- Leetcode系列-Search in Rotated Sorted Array
做Leetcode题有一段时间了,但都是断断续续的,到现在才做了30题左右,感觉对自己来说还是有点难度的.希望自己能继续坚持下去,在校招前能解决超过一百题吧. 其实这些题就是用来训练你的解题思路的,做 ...
- swift官方文档中的函数闭包是怎么理解的?
官方文档中的16页: numbers.map({ (number: Int) -> Int in let result = * number return result }) 不知道这个怎么用, ...
- How To mount/Browse Windows Shares【在linux{centos}上挂载、浏览window共享】
How to mount remote Windows shares Contents Required packages Basic method Better Method Even-better ...
- linux之GDB常用命令汇总
查看gdb的版本号 (1)rpm -q gdb 会显示是否安装gdb及版本号 (2)gdb --version也可以 breakpoint b main; b 20; 设置断点 breakpoint ...
- bzoj2011: [Ceoi2010]Mp3 Player
Description Georg有个MP3 Player,没有任何操作T秒钟就会锁定,这时按下任意一个键就会变回没锁定的状态,但不会改变频道.只有在没锁定的状态下按键才有可能改变频道. MP3的频道 ...
- matlab常用小函数(二)
numel 元素个数 assert 表达式为假时输出某个字符串 int2str 整形转化为字符串型 numel(A) 返回A中的元素个数,A可以是任何的数据结构,如向量.矩阵.元胞.结构体等 asse ...
- Delphi 版本号(D1到XE6),发现一个delphi.wikia.com网站
Borland Compiler Conditional Defines Edit Talk1 2,909PAGES ONTHIS WIKI Product Name Version Cond ...