- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
A $m \times m$ grid is a graph of which the vertices are ordered pairs of natural numbers $(n_1, n_2)$ with $1 \leq n_1 \leq m$ and $1 \leq n_2 \leq m$.
Two vertices $(k_1,k_2)$ and $(k_3,k_4)$ are neighbors iff $|k_1-k_2|+|k_3-k_4|=1$.
We suppose that a unique number $y_w$ is assigned to each vertex.
A vertex $w$ is local minimum if $y_w<y_u$ for all the neighbors $u$ of $w$.
Given such a graph and an assignement of natural numbers at the vertices, we want to find a local minimum of $G$.
How could we show that the above algorithm always returns a local mimum of $G$?
How many time does the algorithm require in the worst case?
Does it require $\Theta(m^2)$ because it could go through all the vertices? Or am I wrong? (Thinking)
A $m \times m$ grid is a graph of which the vertices are ordered pairs of natural numbers $(n_1, n_2)$ with $1 \leq n_1 \leq m$ and $1 \leq n_2 \leq m$.
Two vertices $(k_1,k_2)$ and $(k_3,k_4)$ are neighbors iff $|k_1-k_2|+|k_3-k_4|=1$.
We suppose that a unique number $y_w$ is assigned to each vertex.
A vertex $w$ is local minimum if $y_w<y_u$ for all the neighbors $u$ of $w$.
Given such a graph and an assignement of natural numbers at the vertices, we want to find a local minimum of $G$.
Code:
1.w<-(1,1)
2.while there is a neighbor u of w with y_u<y_w
3. let u be the neighbor of w with smallest y_u
4. w<-u
5.end while
6.return w
How many time does the algorithm require in the worst case?
Does it require $\Theta(m^2)$ because it could go through all the vertices? Or am I wrong? (Thinking)