**Notation:** |

**m, min, power**: integer |

**RE(C)**: the remaining energy of the active node in the cell *C* |

**[i′, j′]**: Address of the next hop cell |

**Input** |

**[i, j]**: Address of the source cell |

**[H, J]**: Address of the CH cell |

**Initialization:** |

min ⟵ large value; |

power ⟵ 0; |

**Begin** |

(1) | [*i*′, *j*′] ⟵ [*i*, *j*]; /∗the first next hop cell will be the source cell∗/ |

(2) | **While** [*i*′, *j*′] is not [*H*, *J*] **do **/∗we stop when the next hop is the CH cell∗/ |

(3) | ADJ ⟵ Adjacent (*i*′, *j*′); /∗we get the list of the adjacent cells of [*i*′, *j*′] from the neighborhood table∗/ |

(4) | **For each** cell *C* in ADJ **do **/∗we search the next hop from the adjacent cells∗/ |

(5) | index_hop ⟵ Level ([*H*, *J*], *C*) /∗we get the hop index of the adjacent cell with the Algorithm 2∗/ |

(6) | **If** index_hop < min **then **/∗we compare the hop index of all adjacent cells∗/ |

(7) | min ⟵ index_hop; |

(8) | power ⟵ RE(*C*); |

(9) | [*i*′, *j*′] ⟵ *C*; |

(10) | **Else if** index_hop = min and RE(*C*) > power **then **/∗ in the case of two adjacent cells with the same hop index we select the cell with the higher value of remaining energy to forward data ∗/ |

(11) | power ⟵ RE(*C*); |

(12) | [*i*′, *j*′] ⟵ *C*; |

(13) | **End if** |

(14) | **End For** |

(15) | forward data to [*i*′, *j*′]; |

(16) | **End While** |

**End** |