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)的更多相关文章

  1. ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)

    题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...

  2. 关于Yuri Boykov and Vladimir Kolmogorov 于2004年提出的max flow / min cut的算法的详解

    出处:http://blog.csdn.net/euler1983/article/details/5959622 算法优化algorithmgraphtree任务 这篇文章说的是Yuri Boyko ...

  3. 图的最小切隔问题Minimum Cuts

    前提条件是这样的:输入一个图(可以是有向图,也可以是无向图,允许平行边存在),我们要做的事情是将这个图切割成两个子图,(切割的定义:将图中的所有顶点分为两个集合A和B,要求这两个集合非空)假设这个图中 ...

  4. HDU 6214.Smallest Minimum Cut 最少边数最小割

    Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Oth ...

  5. 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 ...

  6. Smallest Minimum Cut HDU - 6214(最小割集)

    Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Oth ...

  7. 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 ...

  8. 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 ...

  9. HDU-6214 Smallest Minimum Cut(最少边最小割)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 Problem Description Consider a network G=(V,E) w ...

随机推荐

  1. .NET中的委托——摘自MSDN

    封装一个方法,该方法只有一个参数并且不返回值. 命名空间:  System程序集:  mscorlib(在 mscorlib.dll 中) 语法   C#   public delegate void ...

  2. cocos2dx arpg单机手游

    这只是一个DEMO. ARPG 单机手游, 个人DEMO. 支持剧情编辑, 支持气泡对话, 支持人物图像对话, 支持随时角色切换, 支持NPC跟随, 共同作战, 支持LUA扩展, 支持BUFF技能, ...

  3. Java面向对象程序设计--接口和内部类

    1.接口的定义: In the Java programming language, an interface is not a class but          staff[0] =       ...

  4. c++相关知识回顾

    1.typedef typedef用来定义同类型的同义词.如: typedef unsingned int size_t; typedef int ptrdiff_t; typedef T * ite ...

  5. 我的Hibernate入门

    今天忙了一整天,终于搭建好了我的第一个Hibernate程序,中间关于hibernate.cfg.xml的问题搞了半天,不过最后还是搞明白了,下面来讲一讲过程. 首先在你的eclipse中安装Hibe ...

  6. 超链接字体颜色设置(通过html/css的设置方法)

    超链接字体颜色设置是通过css来设置,a链接的颜色设置常用的有以下两种,1.超链接a的初始状态颜色,2.超链接字体的鼠标滑过颜色,还有两种病不常用:3.超链接字体的已访问颜色,4.超链接字体在按下鼠标 ...

  7. JavaScript学习心得(七)

    一 创建事件监听器 开发人员往往使用事件和元素组合来命名事件处理函数. 创建事件监听器方法: 嵌入式事件处理器即将JavaScript函数赋值给HTML元素属性(不推荐使用:污染HTML:无法应用渐进 ...

  8. VS2012编译生成XP可以执行的程序

    首先需要的就是下载VS2012的Update 4更新包,然后打开项目的属性页,在 配置属性->平台工具集 选项中选择 Visual Studio 2012 - Windows XP (v110_ ...

  9. mysql 中创建存储过程

    mysql中创建存储过程和存储函数虽相对其他的sql语言相对复杂,但却功能强大,存储过程和存储函数更像是一种sql语句中特定功能的一种封装,这种封装可以大大简化外围调用语句的复杂程度. 首先以表emp ...

  10. [BZOJ 2178] 圆的面积并 【Simpson积分】

    题目链接:BZOJ - 2178 题目分析 用Simpson积分,将圆按照 x 坐标分成连续的一些段,分别用 Simpson 求. 注意:1)Eps要设成 1e-13  2)要去掉被其他圆包含的圆. ...