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

    #include <iostream> using namespace std; typedef struct Node { Node *next; int data; }Node, *L ...

  2. 子网/ip/子网掩码

    IP地址由网络地址和主机地址组成 而现在IP由“子网掩码”通过子网网络地 址细分出 A,B,C类更小的网络.这种方式 实际上就是将原来的A类,B类,C类等分类 中的的主机地址部分用作子网地址,可以 将 ...

  3. JavaScript学习总结【6】、JS BOM

    1.BOM 简介 所谓的 BOM 即浏览器对象模型(Browser Object Model).BOM 赋予了 JS 操作浏览器的能力,即 window 操作.DOM 则用于创建删除节点,操作 HTM ...

  4. ajax 异步上传视频带进度条并提取缩略图

    最近在做一个集富媒体功能于一身的项目.需要上传视频.这里我希望做成异步上传,并且有进度条,响应有状态码,视频连接,缩略图. 服务端响应 { "thumbnail": "/ ...

  5. awk基础 [马哥视频]

    awk基础 1.1 print print的使用格式: print item1,item2, …. 要点: 各项目自己使用逗号隔开,而输出时则以空白字符分隔: 输出的item可以为字符串或者数值,当前 ...

  6. mac os x 10.9.1 安装 Homebrew软件包管理工具及brew安装maven3.1.1

    Mac OSX上的软件包管理工具,安装软件或者卸载软件. 打开终端输入(如不行,可参考homebrew官网): ruby -e "$(curl -fsSL https://raw.githu ...

  7. 学习Swift -- 拓展

    拓展(Extension) 扩展就是向一个已有的类.结构体.枚举类型或者协议类型添加新功能.这包括在没有权限获取原始源代码的情况下扩展类型的能力(即逆向建模).扩展和 Objective-C 中的分类 ...

  8. 拦截QT关闭窗口的CloseEvent

    QDialog类下有一个虚函数 void QDialog::closeEvent (  QCloseEvent   *  e   )  [virtual protected] 通过实现closeEve ...

  9. 线性表之顺序存储结构(C语言动态数组实现)

    线性表的定义:N个数据元素的有限序列 线性表从存储结构上分为:顺序存储结构(数组)和 链式存储结构(链表) 顺序存储结构:是用一段连续的内存空间存储表中的数据 L=(a1,a2,a3....an) 链 ...

  10. [BZOJ 3894] 文理分科 【最小割】

    题目链接:BZOJ - 3894 题目分析 最小割模型,设定一个点与 S 相连表示选文,与 T 相连表示选理. 那么首先要加上所有可能获得的权值,然后减去最小割,即不能获得的权值. 那么对于每个点,从 ...