Local Search (part 1)
Haim Kaplan and Uri Zwick
Algorithms in Action
Tel Aviv University
Last updated: March 2017
1
An example
2
Max Cut
Partition πΊ = (π, πΈ) into 2 parts π, π β π such that the
number of edges π’, π£ , π’ β π, π£ β π β π is maximized
π
π =πβπ
3
Few comments
β’ This problem is NP-hard, best
approximation guarantee is 0.878, NP-hard
to get more than 0.91
β’ The analogous problem of finding a
minimum cut is easier (how ?)
4
The idea
Start with some cut and
try to improve it by making local changes
Stop when there is no local change that improves the cut
5
Local change
π
π
6
Local change
π
π
7
Local change
π
π
8
Local change
π
π
9
Local change
π
π
10
Local change
π
π
11
Local vs. global OPT
β’ When we stop we have a cut that we cannot
improve by a local change (local opt)
β’ This need not be the largest cut (global opt)
12
Local OPT
π
π
A
D
B
C
13
Global OPT
π
π
B
D
A
C
14
Analysis
There are two main parameters of interest:
β’ Time: How long it takes to get to a local
optimum ?
β’ Quality of the local optimum ?
15
Quality of local opt
π =πβπ
π
v
Can this be the situation at a local optimum ?
16
Quality of local opt
π =πβπ
π
v
βπ£ πΎ π£ β€ πΏ(π£)
πΏ π£ = #edges incident to v that cross the cut
πΎ π£ = #edges incident to v that do not cross the cut
17
Quality of local opt
π=πβπ
π
v
πΎ π£ β€
π£
2
π’, π£
π’, π£ β π ππ π’, π£ β π
πΏ π£
π£
β€2
π’, π£
π’ β π, π£ β π
18
Quality of local opt
π=πβπ
π
v
πΎ π£ β€
π£
π’, π£
π£
π’, π£ β π ππ π’, π£ β π
πππ |πΈ|
β€
β€
2
2
πΏ π£
π’, π£
β€
π’, π£
π’ β π, π£ β π
π’ β π, π£ β π
19
Steps to local opt
π( πΈ )
Each step the size of the cut increases by at least one
20
Weighted graphs
Partition πΊ = (π, πΈ) into 2 parts π, π β π such that the
βπ π’, π£ , π’ β π, π£ β π β π is maximized
π
π =πβπ
21
Weighted graphs
Works the same:
Make a swap if it increases the weight of the cut
πππ π
β€
β€ π€ π’, π£ π’ β π, π£ β π
2
2
π = βπ€(π’, π£)
22
Hopfield networks
A neural network that is used as memory (Content
Addressable Memory)
Initialized with a noisy or incomplete pattern it converges to
the correct pattern
23
Memory cells (pixels) are nodes
in a weighted undirected graph
π π β {β1,1}
π π
π€ππ
π π
24
Retrieving form memory
Initialize with a
tentative content
1
1
β1
-1
1
-1
1
25
Retrieving form memory
Each neuron π in
turn checks if
βπ π€ππ π π π π > 0 ?
If so then π π flips
When no neuron
wants to flip we
found the content
1
1
β1
-1
1
-1
1
26
Retrieving form memory
Each neuron π in
turn checks if
π΄βπ΅ >0?
β1
-1
1
1
If so then π π flips
1
When a neuron flips
the value of the cut
increases ο¨ converges
to a local max cut
-1
1
27
Storing in memory
We want to
compute weights
such that the local
max cuts have a
specific form
Large (positive) weight
between cells in
different states, small
(negative) weight
between cells of the
same state
β1
-1
1
1
1
-1
1
28
Hebbian learning
Suppose we want to store π₯ = (π₯1 , π₯2 , β¦ , π₯π )
Set π€ππ = βπ₯π π₯π
29
Hebbian learning
1
1
β1
-1
1
β1
β1
1
-1
1
30
Storing in memory
The desired cut is
even the global max
1
β1
-1
1
1
β1
1
-1
1
31
Hebbian learning
Suppose we want π₯ = (π₯1 , π₯2 , β¦ , π₯π ), π¦ = π¦1 , π¦2 , β¦ , π¦π , and
π§ = (π§1 , π§2 , β¦ , π§π ) to be local maxima
Set π€ππ = βπ₯π π₯π βπ¦π π¦π βπ§π π§π
Each neuron π in turn checks if βπ π€ππ π π π π > 0 ?
Each neuron π in turn checks if
βπ(βπ₯π π₯π βπ¦π π¦π βπ§π π§π )π π π π > 0 ?
π₯ is stable iff for all π
(βπ₯π π₯π βπ¦π π¦π βπ§π π§π )π₯π π₯π β€ 0 ?
π
32
Hebbian learning
π₯ is stable iff for all π
(βπ₯π π₯π βπ¦π π¦π βπ§π π§π )π₯π π₯π β€ 0
π
βπ₯π2
π₯
2
β π¦π π₯π π₯, π¦ β π§π π₯π π₯, π§ β€ 0
βπ β π¦π π₯π π₯, π¦ β π§π π₯π π₯, π§ β€ 0
βπ¦π π₯π π₯, π¦ β π§π π₯π π₯, π§ β€ π
This will hold if we are not trying to store too many vectors or
if the vectors are nearly orthogonalβ¦
33
Storage capacity:
Stochastic analysis
How may random β1/1 vectors can we store with high
probability ?
β€ 0.138π
34
Back to max cut
35
Steps to local opt
We construct a example with a long running time
The example uses two kinds of vertices
36
Steps to local opt
π2
π3 π£
π4
π1
π€ π3 > π€ π1 + π€ π2 + π€ π4
37
Steps to local opt
π2
π3 π£
π4
π1
π€ π3 > π€ π1 + π€ π2 + π€ π4
38
Steps to local opt
π2
π3 π£
π4
π1
π€ π3 > π€ π1 + π€ π2 + π€ π4
39
Steps to local opt
π2
π3 π£
π4
π3
π1
π€ π4 > π€ π2 , π€ π3 > π€ π1
π2
π£
π4
π€ π3 > π€ π1 + π€ π2 + π€ π4
π1
π€ π2 + π€ π3 > π€ π1 + π€ π4
40
Steps to local opt
π2
π3 π£
π4
π3
π1
π€ π4 > π€ π2 , π€ π3 > π€ π1
π2
π£
π4
π€ π3 > π€ π1 + π€ π2 + π€ π4
π1
π€ π2 + π€ π3 > π€ π1 + π€ π4
41
Steps to local opt
π2
π3 π£
π4
π3
π1
π€ π4 > π€ π2 , π€ π3 > π€ π1
π2
π£
π4
π€ π3 > π€ π1 + π€ π2 + π€ π4
π1
π€ π2 + π€ π3 > π€ π1 + π€ π4
42
Steps to local opt
π2
π3 π£
π4
π3
π1
π€ π4 > π€ π2 , π€ π3 > π€ π1
π2
π£
π4
π€ π3 > π€ π1 + π€ π2 + π€ π4
π1
π€ π2 + π€ π3 > π€ π1 + π€ π4
43
Steps to local opt
π2
π3 π£
π4
π3
π1
π€ π4 > π€ π2 , π€ π3 > π€ π1
π2
π£
π4
π€ π3 > π€ π1 + π€ π2 + π€ π4
π1
π€ π2 + π€ π3 > π€ π1 + π€ π4
44
Steps to local opt
45
Steps to local opt
46
Steps to local opt
47
Steps to local opt
48
Steps to local opt
49
Steps to local opt
50
Steps to local opt
51
Steps to local opt
52
Steps to local opt
53
Steps to local opt
54
Steps to local opt
55
Steps to local opt
56
Steps to local opt
57
Steps to local opt
58
Steps to local opt
59
Steps to local opt
π£0
π£1
Moral: 2 flips of π£0 caused 4 flips of π£1
60
Steps to local opt
π£0
π£1
π£2
61
Steps to local opt
π£0
π£1
π£2
62
Steps to local opt
π£0
π£1
π£2
63
Steps to local opt
π£0
π£1
π£2
64
Steps to local opt
π£0
π£1
π£2
65
Steps to local opt
π£0
π£1
π£2
66
Steps to local opt
π£0
π£1
π£2
67
Steps to local opt
π£0
π£1
π£2
68
Steps to local opt
π£0
π£1
π£2
69
Steps to local opt
π£0
π£1
π£2
70
Steps to local opt
π£0
π£1
π£2
71
Steps to local opt
π£0
π£1
π£2
72
Steps to local opt
π£0
π£1
π£2
73
Steps to local opt
π£0
π£1
π£2
At this point π£2 flipped 4 times and the circled gadget is in its
initial configuration
74
Steps to local opt
π£0
π£1
π£2
75
Steps to local opt
π£0
π£1
π£2
76
Steps to local opt
π£0
π£1
π£2
77
Steps to local opt
π£0
π£1
π£2
78
Steps to local opt
π£0
π£1
π£2
79
Steps to local opt
π£0
π£1
π£2
80
Steps to local opt
π£0
π£1
π£2
81
Steps to local opt
π£0
π£1
π£2
82
Steps to local opt
π£0
π£1
π£2
83
Steps to local opt
π£0
π£1
π£2
84
Steps to local opt
π£0
π£1
π£2
85
Steps to local opt
π£0
π£1
π£2
86
Steps to local opt
π£0
π£1
π£2
By induction we can make π£π flip 2π+1 times
87
#Steps - Summary
β’ Still π π , π = βπβπΈ π€ π , if all weights
are integers (pseudo polynomial)
β’ We can prevent long running time if we
only do a move if it improves by at least
2ππ€(π,π)
π
β’ Then the # of moves is bounded by
π
π log(π)
π
88
Big improvement - analysis
π
π
v
βπ£ π€ Ξ π£
β€π€ Ξ π£
2ππ€(π, π)
+
π
Ξ π£ = set of edges incident to v that cross the cut
Ξ π£ = set of edges incident to v that do not cross the cut
Big improvement - analysis
π=πβπ
π
v
π€(Ξ π£ ) β€
π£
π€ Ξ π£
π£
2ππ€(π, π)
+
π
2π€ π’, π£ π’, π£ β π ππ π’, π£ β π
β€ 2π€ π’, π£ π’ β π, π£ β π + 2ππΏ
90
Big improvement - analysis
π€ π’, π£ π’, π£ β π ππ π’, π£ β π
β€ π€ π’, π£ π’ β π, π£ β π + ππΏ
π β πΏ β€ πΏ + ππΏ
π β€ 2+π πΏ
1
1
πππ β€
πβ€πΏ
2+π
2+π
Max-cut notes
β’ The ½ approximation guarantee is not that
impressive: A random partition gives this
guarantee in expectation
β’ Can also get ½ approximation
deterministically by inserting the vertices
one by one to the ``rightββ side of the cut
92
Max-cut notes
β’ But still, our local search scheme gives in
practice larger cuts.
93
© Copyright 2026 Paperzz