From 47509541a65a7b350efde753223fd512b83ad21d Mon Sep 17 00:00:00 2001 From: Aryan <82381989+akumm2k@users.noreply.github.com> Date: Mon, 15 Dec 2025 12:05:18 +0100 Subject: [PATCH] Update search code --- teaching/mentoring-winter-25/Scoping-and-Graphs.md | 9 ++++----- teaching/mentoring-winter-25/graph.py | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/teaching/mentoring-winter-25/Scoping-and-Graphs.md b/teaching/mentoring-winter-25/Scoping-and-Graphs.md index e9be667..631e7f0 100644 --- a/teaching/mentoring-winter-25/Scoping-and-Graphs.md +++ b/teaching/mentoring-winter-25/Scoping-and-Graphs.md @@ -259,12 +259,11 @@ def traverse( frontier = deque([start]) visited_order = [] + get_neighbor = ( + frontier.pop if search_type == "DFS" else frontier.popleft + ) while frontier: - curr = ( - frontier.pop() - if search_type == "DFS" - else frontier.popleft() - ) + curr = get_neighbor() if curr not in explored: visited_order.append(curr) explored.add(curr) diff --git a/teaching/mentoring-winter-25/graph.py b/teaching/mentoring-winter-25/graph.py index 8a6146e..90b8d19 100644 --- a/teaching/mentoring-winter-25/graph.py +++ b/teaching/mentoring-winter-25/graph.py @@ -33,12 +33,11 @@ def traverse( frontier = deque([start]) visited_order = [] + get_neighbor = ( + frontier.pop if search_type == "DFS" else frontier.popleft + ) while frontier: - curr = ( - frontier.pop() - if search_type == "DFS" - else frontier.popleft() - ) + curr = get_neighbor() if curr not in explored: visited_order.append(curr) explored.add(curr)