We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
I found typo in graphs/greedy_best_first
### What would you like to share?

The dx and dy are reversed!
https://github.com/TheAlgorithms/Python/blob/ce43a8ac4ad14e1639014d374b1137906218cfe3/graphs/greedy_best_first.py#L61-L63

Expected correction
```python
dx = abs(self.pos_x - self.goal_x)
dy = abs(self.pos_y - self.goal_y)
return dx + dy
```

### Additional information

_No response_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `graphs/greedy_best_first.py`
Content:
```
1 """
2 https://en.wikipedia.org/wiki/Best-first_search#Greedy_BFS
3 """
4 
5 from __future__ import annotations
6 
7 Path = list[tuple[int, int]]
8 
9 grid = [
10     [0, 0, 0, 0, 0, 0, 0],
11     [0, 1, 0, 0, 0, 0, 0],  # 0 are free path whereas 1's are obstacles
12     [0, 0, 0, 0, 0, 0, 0],
13     [0, 0, 1, 0, 0, 0, 0],
14     [1, 0, 1, 0, 0, 0, 0],
15     [0, 0, 0, 0, 0, 0, 0],
16     [0, 0, 0, 0, 1, 0, 0],
17 ]
18 
19 delta = ([-1, 0], [0, -1], [1, 0], [0, 1])  # up, left, down, right
20 
21 
22 class Node:
23     """
24     >>> k = Node(0, 0, 4, 5, 0, None)
25     >>> k.calculate_heuristic()
26     9
27     >>> n = Node(1, 4, 3, 4, 2, None)
28     >>> n.calculate_heuristic()
29     2
30     >>> l = [k, n]
31     >>> n == l[0]
32     False
33     >>> l.sort()
34     >>> n == l[0]
35     True
36     """
37 
38     def __init__(
39         self,
40         pos_x: int,
41         pos_y: int,
42         goal_x: int,
43         goal_y: int,
44         g_cost: float,
45         parent: Node | None,
46     ):
47         self.pos_x = pos_x
48         self.pos_y = pos_y
49         self.pos = (pos_y, pos_x)
50         self.goal_x = goal_x
51         self.goal_y = goal_y
52         self.g_cost = g_cost
53         self.parent = parent
54         self.f_cost = self.calculate_heuristic()
55 
56     def calculate_heuristic(self) -> float:
57         """
58         The heuristic here is the Manhattan Distance
59         Could elaborate to offer more than one choice
60         """
61         dy = abs(self.pos_x - self.goal_x)
62         dx = abs(self.pos_y - self.goal_y)
63         return dx + dy
64 
65     def __lt__(self, other) -> bool:
66         return self.f_cost < other.f_cost
67 
68 
69 class GreedyBestFirst:
70     """
71     >>> gbf = GreedyBestFirst((0, 0), (len(grid) - 1, len(grid[0]) - 1))
72     >>> [x.pos for x in gbf.get_successors(gbf.start)]
73     [(1, 0), (0, 1)]
74     >>> (gbf.start.pos_y + delta[3][0], gbf.start.pos_x + delta[3][1])
75     (0, 1)
76     >>> (gbf.start.pos_y + delta[2][0], gbf.start.pos_x + delta[2][1])
77     (1, 0)
78     >>> gbf.retrace_path(gbf.start)
79     [(0, 0)]
80     >>> gbf.search()  # doctest: +NORMALIZE_WHITESPACE
81     [(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (4, 1), (5, 1), (6, 1),
82      (6, 2), (6, 3), (5, 3), (5, 4), (5, 5), (6, 5), (6, 6)]
83     """
84 
85     def __init__(self, start: tuple[int, int], goal: tuple[int, int]):
86         self.start = Node(start[1], start[0], goal[1], goal[0], 0, None)
87         self.target = Node(goal[1], goal[0], goal[1], goal[0], 99999, None)
88 
89         self.open_nodes = [self.start]
90         self.closed_nodes: list[Node] = []
91 
92         self.reached = False
93 
94     def search(self) -> Path | None:
95         """
96         Search for the path,
97         if a path is not found, only the starting position is returned
98         """
99         while self.open_nodes:
100             # Open Nodes are sorted using __lt__
101             self.open_nodes.sort()
102             current_node = self.open_nodes.pop(0)
103 
104             if current_node.pos == self.target.pos:
105                 self.reached = True
106                 return self.retrace_path(current_node)
107 
108             self.closed_nodes.append(current_node)
109             successors = self.get_successors(current_node)
110 
111             for child_node in successors:
112                 if child_node in self.closed_nodes:
113                     continue
114 
115                 if child_node not in self.open_nodes:
116                     self.open_nodes.append(child_node)
117                 else:
118                     # retrieve the best current path
119                     better_node = self.open_nodes.pop(self.open_nodes.index(child_node))
120 
121                     if child_node.g_cost < better_node.g_cost:
122                         self.open_nodes.append(child_node)
123                     else:
124                         self.open_nodes.append(better_node)
125 
126         if not self.reached:
127             return [self.start.pos]
128         return None
129 
130     def get_successors(self, parent: Node) -> list[Node]:
131         """
132         Returns a list of successors (both in the grid and free spaces)
133         """
134         successors = []
135         for action in delta:
136             pos_x = parent.pos_x + action[1]
137             pos_y = parent.pos_y + action[0]
138 
139             if not (0 <= pos_x <= len(grid[0]) - 1 and 0 <= pos_y <= len(grid) - 1):
140                 continue
141 
142             if grid[pos_y][pos_x] != 0:
143                 continue
144 
145             successors.append(
146                 Node(
147                     pos_x,
148                     pos_y,
149                     self.target.pos_y,
150                     self.target.pos_x,
151                     parent.g_cost + 1,
152                     parent,
153                 )
154             )
155         return successors
156 
157     def retrace_path(self, node: Node | None) -> Path:
158         """
159         Retrace the path from parents to parents until start node
160         """
161         current_node = node
162         path = []
163         while current_node is not None:
164             path.append((current_node.pos_y, current_node.pos_x))
165             current_node = current_node.parent
166         path.reverse()
167         return path
168 
169 
170 if __name__ == "__main__":
171     init = (0, 0)
172     goal = (len(grid) - 1, len(grid[0]) - 1)
173     for elem in grid:
174         print(elem)
175 
176     print("------")
177 
178     greedy_bf = GreedyBestFirst(init, goal)
179     path = greedy_bf.search()
180     if path:
181         for pos_x, pos_y in path:
182             grid[pos_x][pos_y] = 2
183 
184         for elem in grid:
185             print(elem)
186
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/graphs/greedy_best_first.py b/graphs/greedy_best_first.py
--- a/graphs/greedy_best_first.py
+++ b/graphs/greedy_best_first.py
@@ -58,8 +58,8 @@
         The heuristic here is the Manhattan Distance
         Could elaborate to offer more than one choice
         """
-        dy = abs(self.pos_x - self.goal_x)
-        dx = abs(self.pos_y - self.goal_y)
+        dx = abs(self.pos_x - self.goal_x)
+        dy = abs(self.pos_y - self.goal_y)
         return dx + dy
 
     def __lt__(self, other) -> bool:

{"golden_diff": "diff --git a/graphs/greedy_best_first.py b/graphs/greedy_best_first.py\n--- a/graphs/greedy_best_first.py\n+++ b/graphs/greedy_best_first.py\n@@ -58,8 +58,8 @@\n         The heuristic here is the Manhattan Distance\n         Could elaborate to offer more than one choice\n         \"\"\"\n-        dy = abs(self.pos_x - self.goal_x)\n-        dx = abs(self.pos_y - self.goal_y)\n+        dx = abs(self.pos_x - self.goal_x)\n+        dy = abs(self.pos_y - self.goal_y)\n         return dx + dy\n \n     def __lt__(self, other) -> bool:\n", "issue": "I found typo in graphs/greedy_best_first\n### What would you like to share?\n\nThe dx and dy are reversed!\r\nhttps://github.com/TheAlgorithms/Python/blob/ce43a8ac4ad14e1639014d374b1137906218cfe3/graphs/greedy_best_first.py#L61-L63\r\n\r\nExpected correction\r\n```python\r\ndx = abs(self.pos_x - self.goal_x)\r\ndy = abs(self.pos_y - self.goal_y)\r\nreturn dx + dy\r\n```\n\n### Additional information\n\n_No response_\n", "before_files": [{"content": "\"\"\"\nhttps://en.wikipedia.org/wiki/Best-first_search#Greedy_BFS\n\"\"\"\n\nfrom __future__ import annotations\n\nPath = list[tuple[int, int]]\n\ngrid = [\n    [0, 0, 0, 0, 0, 0, 0],\n    [0, 1, 0, 0, 0, 0, 0],  # 0 are free path whereas 1's are obstacles\n    [0, 0, 0, 0, 0, 0, 0],\n    [0, 0, 1, 0, 0, 0, 0],\n    [1, 0, 1, 0, 0, 0, 0],\n    [0, 0, 0, 0, 0, 0, 0],\n    [0, 0, 0, 0, 1, 0, 0],\n]\n\ndelta = ([-1, 0], [0, -1], [1, 0], [0, 1])  # up, left, down, right\n\n\nclass Node:\n    \"\"\"\n    >>> k = Node(0, 0, 4, 5, 0, None)\n    >>> k.calculate_heuristic()\n    9\n    >>> n = Node(1, 4, 3, 4, 2, None)\n    >>> n.calculate_heuristic()\n    2\n    >>> l = [k, n]\n    >>> n == l[0]\n    False\n    >>> l.sort()\n    >>> n == l[0]\n    True\n    \"\"\"\n\n    def __init__(\n        self,\n        pos_x: int,\n        pos_y: int,\n        goal_x: int,\n        goal_y: int,\n        g_cost: float,\n        parent: Node | None,\n    ):\n        self.pos_x = pos_x\n        self.pos_y = pos_y\n        self.pos = (pos_y, pos_x)\n        self.goal_x = goal_x\n        self.goal_y = goal_y\n        self.g_cost = g_cost\n        self.parent = parent\n        self.f_cost = self.calculate_heuristic()\n\n    def calculate_heuristic(self) -> float:\n        \"\"\"\n        The heuristic here is the Manhattan Distance\n        Could elaborate to offer more than one choice\n        \"\"\"\n        dy = abs(self.pos_x - self.goal_x)\n        dx = abs(self.pos_y - self.goal_y)\n        return dx + dy\n\n    def __lt__(self, other) -> bool:\n        return self.f_cost < other.f_cost\n\n\nclass GreedyBestFirst:\n    \"\"\"\n    >>> gbf = GreedyBestFirst((0, 0), (len(grid) - 1, len(grid[0]) - 1))\n    >>> [x.pos for x in gbf.get_successors(gbf.start)]\n    [(1, 0), (0, 1)]\n    >>> (gbf.start.pos_y + delta[3][0], gbf.start.pos_x + delta[3][1])\n    (0, 1)\n    >>> (gbf.start.pos_y + delta[2][0], gbf.start.pos_x + delta[2][1])\n    (1, 0)\n    >>> gbf.retrace_path(gbf.start)\n    [(0, 0)]\n    >>> gbf.search()  # doctest: +NORMALIZE_WHITESPACE\n    [(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (4, 1), (5, 1), (6, 1),\n     (6, 2), (6, 3), (5, 3), (5, 4), (5, 5), (6, 5), (6, 6)]\n    \"\"\"\n\n    def __init__(self, start: tuple[int, int], goal: tuple[int, int]):\n        self.start = Node(start[1], start[0], goal[1], goal[0], 0, None)\n        self.target = Node(goal[1], goal[0], goal[1], goal[0], 99999, None)\n\n        self.open_nodes = [self.start]\n        self.closed_nodes: list[Node] = []\n\n        self.reached = False\n\n    def search(self) -> Path | None:\n        \"\"\"\n        Search for the path,\n        if a path is not found, only the starting position is returned\n        \"\"\"\n        while self.open_nodes:\n            # Open Nodes are sorted using __lt__\n            self.open_nodes.sort()\n            current_node = self.open_nodes.pop(0)\n\n            if current_node.pos == self.target.pos:\n                self.reached = True\n                return self.retrace_path(current_node)\n\n            self.closed_nodes.append(current_node)\n            successors = self.get_successors(current_node)\n\n            for child_node in successors:\n                if child_node in self.closed_nodes:\n                    continue\n\n                if child_node not in self.open_nodes:\n                    self.open_nodes.append(child_node)\n                else:\n                    # retrieve the best current path\n                    better_node = self.open_nodes.pop(self.open_nodes.index(child_node))\n\n                    if child_node.g_cost < better_node.g_cost:\n                        self.open_nodes.append(child_node)\n                    else:\n                        self.open_nodes.append(better_node)\n\n        if not self.reached:\n            return [self.start.pos]\n        return None\n\n    def get_successors(self, parent: Node) -> list[Node]:\n        \"\"\"\n        Returns a list of successors (both in the grid and free spaces)\n        \"\"\"\n        successors = []\n        for action in delta:\n            pos_x = parent.pos_x + action[1]\n            pos_y = parent.pos_y + action[0]\n\n            if not (0 <= pos_x <= len(grid[0]) - 1 and 0 <= pos_y <= len(grid) - 1):\n                continue\n\n            if grid[pos_y][pos_x] != 0:\n                continue\n\n            successors.append(\n                Node(\n                    pos_x,\n                    pos_y,\n                    self.target.pos_y,\n                    self.target.pos_x,\n                    parent.g_cost + 1,\n                    parent,\n                )\n            )\n        return successors\n\n    def retrace_path(self, node: Node | None) -> Path:\n        \"\"\"\n        Retrace the path from parents to parents until start node\n        \"\"\"\n        current_node = node\n        path = []\n        while current_node is not None:\n            path.append((current_node.pos_y, current_node.pos_x))\n            current_node = current_node.parent\n        path.reverse()\n        return path\n\n\nif __name__ == \"__main__\":\n    init = (0, 0)\n    goal = (len(grid) - 1, len(grid[0]) - 1)\n    for elem in grid:\n        print(elem)\n\n    print(\"------\")\n\n    greedy_bf = GreedyBestFirst(init, goal)\n    path = greedy_bf.search()\n    if path:\n        for pos_x, pos_y in path:\n            grid[pos_x][pos_y] = 2\n\n        for elem in grid:\n            print(elem)\n", "path": "graphs/greedy_best_first.py"}], "after_files": [{"content": "\"\"\"\nhttps://en.wikipedia.org/wiki/Best-first_search#Greedy_BFS\n\"\"\"\n\nfrom __future__ import annotations\n\nPath = list[tuple[int, int]]\n\ngrid = [\n    [0, 0, 0, 0, 0, 0, 0],\n    [0, 1, 0, 0, 0, 0, 0],  # 0 are free path whereas 1's are obstacles\n    [0, 0, 0, 0, 0, 0, 0],\n    [0, 0, 1, 0, 0, 0, 0],\n    [1, 0, 1, 0, 0, 0, 0],\n    [0, 0, 0, 0, 0, 0, 0],\n    [0, 0, 0, 0, 1, 0, 0],\n]\n\ndelta = ([-1, 0], [0, -1], [1, 0], [0, 1])  # up, left, down, right\n\n\nclass Node:\n    \"\"\"\n    >>> k = Node(0, 0, 4, 5, 0, None)\n    >>> k.calculate_heuristic()\n    9\n    >>> n = Node(1, 4, 3, 4, 2, None)\n    >>> n.calculate_heuristic()\n    2\n    >>> l = [k, n]\n    >>> n == l[0]\n    False\n    >>> l.sort()\n    >>> n == l[0]\n    True\n    \"\"\"\n\n    def __init__(\n        self,\n        pos_x: int,\n        pos_y: int,\n        goal_x: int,\n        goal_y: int,\n        g_cost: float,\n        parent: Node | None,\n    ):\n        self.pos_x = pos_x\n        self.pos_y = pos_y\n        self.pos = (pos_y, pos_x)\n        self.goal_x = goal_x\n        self.goal_y = goal_y\n        self.g_cost = g_cost\n        self.parent = parent\n        self.f_cost = self.calculate_heuristic()\n\n    def calculate_heuristic(self) -> float:\n        \"\"\"\n        The heuristic here is the Manhattan Distance\n        Could elaborate to offer more than one choice\n        \"\"\"\n        dx = abs(self.pos_x - self.goal_x)\n        dy = abs(self.pos_y - self.goal_y)\n        return dx + dy\n\n    def __lt__(self, other) -> bool:\n        return self.f_cost < other.f_cost\n\n\nclass GreedyBestFirst:\n    \"\"\"\n    >>> gbf = GreedyBestFirst((0, 0), (len(grid) - 1, len(grid[0]) - 1))\n    >>> [x.pos for x in gbf.get_successors(gbf.start)]\n    [(1, 0), (0, 1)]\n    >>> (gbf.start.pos_y + delta[3][0], gbf.start.pos_x + delta[3][1])\n    (0, 1)\n    >>> (gbf.start.pos_y + delta[2][0], gbf.start.pos_x + delta[2][1])\n    (1, 0)\n    >>> gbf.retrace_path(gbf.start)\n    [(0, 0)]\n    >>> gbf.search()  # doctest: +NORMALIZE_WHITESPACE\n    [(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (4, 1), (5, 1), (6, 1),\n     (6, 2), (6, 3), (5, 3), (5, 4), (5, 5), (6, 5), (6, 6)]\n    \"\"\"\n\n    def __init__(self, start: tuple[int, int], goal: tuple[int, int]):\n        self.start = Node(start[1], start[0], goal[1], goal[0], 0, None)\n        self.target = Node(goal[1], goal[0], goal[1], goal[0], 99999, None)\n\n        self.open_nodes = [self.start]\n        self.closed_nodes: list[Node] = []\n\n        self.reached = False\n\n    def search(self) -> Path | None:\n        \"\"\"\n        Search for the path,\n        if a path is not found, only the starting position is returned\n        \"\"\"\n        while self.open_nodes:\n            # Open Nodes are sorted using __lt__\n            self.open_nodes.sort()\n            current_node = self.open_nodes.pop(0)\n\n            if current_node.pos == self.target.pos:\n                self.reached = True\n                return self.retrace_path(current_node)\n\n            self.closed_nodes.append(current_node)\n            successors = self.get_successors(current_node)\n\n            for child_node in successors:\n                if child_node in self.closed_nodes:\n                    continue\n\n                if child_node not in self.open_nodes:\n                    self.open_nodes.append(child_node)\n                else:\n                    # retrieve the best current path\n                    better_node = self.open_nodes.pop(self.open_nodes.index(child_node))\n\n                    if child_node.g_cost < better_node.g_cost:\n                        self.open_nodes.append(child_node)\n                    else:\n                        self.open_nodes.append(better_node)\n\n        if not self.reached:\n            return [self.start.pos]\n        return None\n\n    def get_successors(self, parent: Node) -> list[Node]:\n        \"\"\"\n        Returns a list of successors (both in the grid and free spaces)\n        \"\"\"\n        successors = []\n        for action in delta:\n            pos_x = parent.pos_x + action[1]\n            pos_y = parent.pos_y + action[0]\n\n            if not (0 <= pos_x <= len(grid[0]) - 1 and 0 <= pos_y <= len(grid) - 1):\n                continue\n\n            if grid[pos_y][pos_x] != 0:\n                continue\n\n            successors.append(\n                Node(\n                    pos_x,\n                    pos_y,\n                    self.target.pos_y,\n                    self.target.pos_x,\n                    parent.g_cost + 1,\n                    parent,\n                )\n            )\n        return successors\n\n    def retrace_path(self, node: Node | None) -> Path:\n        \"\"\"\n        Retrace the path from parents to parents until start node\n        \"\"\"\n        current_node = node\n        path = []\n        while current_node is not None:\n            path.append((current_node.pos_y, current_node.pos_x))\n            current_node = current_node.parent\n        path.reverse()\n        return path\n\n\nif __name__ == \"__main__\":\n    init = (0, 0)\n    goal = (len(grid) - 1, len(grid[0]) - 1)\n    for elem in grid:\n        print(elem)\n\n    print(\"------\")\n\n    greedy_bf = GreedyBestFirst(init, goal)\n    path = greedy_bf.search()\n    if path:\n        for pos_x, pos_y in path:\n            grid[pos_x][pos_y] = 2\n\n        for elem in grid:\n            print(elem)\n", "path": "graphs/greedy_best_first.py"}]}