0% found this document useful (0 votes)
8 views21 pages

BFS Algorithm and Visualization Guide

The document outlines the course CS 315: Elective 2 (Intelligent System) at Surigao Del Norte State University for the academic year 2025-2026, focusing on problem-solving through searching algorithms like Breadth-First Search (BFS) and Depth-First Search (DFS). It provides detailed explanations of both algorithms, including their key features, code snippets for implementation, and visualizer classes for demonstration. The document serves as a module for students to learn and apply these fundamental search techniques in computer science.

Uploaded by

nadenoimer2979
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views21 pages

BFS Algorithm and Visualization Guide

The document outlines the course CS 315: Elective 2 (Intelligent System) at Surigao Del Norte State University for the academic year 2025-2026, focusing on problem-solving through searching algorithms like Breadth-First Search (BFS) and Depth-First Search (DFS). It provides detailed explanations of both algorithms, including their key features, code snippets for implementation, and visualizer classes for demonstration. The document serves as a module for students to learn and apply these fundamental search techniques in computer science.

Uploaded by

nadenoimer2979
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Document Code No.

FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 1 of 21
COLLEGE OFCOMPUTING & INFORMATION SCIENCES
First Semester, Academic Year 2025-2026
CS 315: ELECTIVE 2 (INTELLIGENT SYSTEM)
Document Code No. FM-SSCT-ACAD-
002
STUDENT INFORMATION
Revision No. 00

Effective Date 20 September 2018


Page No. 1 of 21

Document Code No. FM-SSCT-ACAD-


002
Revision No. 00

Effective Date 20 September 2018


Page No. 1 of 21

Document Code No. FM-SSCT-ACAD-


002
Revision No. 00

Effective Date 20 September 2018


Page No. 1 of 21

Student Dean Mark L. Remion Activity # 1


College/Program/ CCIS/BSCS 3A1 Module 2. Solving Problems by Uninformed Search
Course/Level/Section Searching (BFS, DFS, UCS, DLS, IDS)

1. BREAD-FIRST SEARCH (BFS)


Breadth-First Search explores all nodes at the current depth before moving to the next level. It uses a queue (FIFO) to keep track of nodes, ensuring that the shortest
path is found in an unweighted graph.
Key Features:

 Guarantees the shortest path if the cost is uniform.


 Uses more memory as it stores all child nodes.

CODE SNIPPET:
import tkinter as tk

from tkinter import ttk, scrolledtext

import threading, time

from collections import deque

def reconstruct_path(parent, start, goal):

if goal not in parent:

return None

path, cur = [], goal

while cur != start:

[Link](cur)

cur = [Link](cur)

if cur is None:

return None

[Link](start)

return list(reversed(path))

def bfs(graph, start, goal):

visited_order, parent = [], {}

q = deque([start])

seen = set([start])

while q:

node = [Link]()

visited_order.append(node)

if node == goal:

return reconstruct_path(parent, start, goal), visited_order

for nbr in [Link](node, []):

if nbr not in seen:

[Link](nbr)
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 2 of 21
parent[nbr] = node

[Link](nbr)
Document Code No. FM-SSCT-ACAD-
return None, visited_order 002
class BFSVisualizer: Revision No. 00
def __init__(self, root):
Effective Date 20 September 2018
[Link] = root Page No. 2 of 21
[Link]("BFS Visualizer")

[Link] = {} Document Code No. FM-SSCT-ACAD-


self.node_positions = {} 002
[Link] = False
Revision No. 00
self.animation_delay = 600
Effective Date 20 September 2018
self.setup_ui()
Page No. 2 of 21
self.build_graph()

[Link]("<Configure>", self.on_canvas_resize) Document Code No. FM-SSCT-ACAD-


def setup_ui(self):
002
frame = [Link]([Link]); [Link](fill="both", expand=True, padx=8, pady=8)
Revision No. 00
left = [Link](frame); [Link](side="left", fill="y")
Effective Date 20 September 2018
[Link](left, text="Start:").pack(anchor="w")
Page No. 2 of 21
self.start_entry = [Link](left); self.start_entry.pack(fill="x");
self.start_entry.insert(0,"A")

[Link](left, text="Goal:").pack(anchor="w")

self.goal_entry = [Link](left); self.goal_entry.pack(fill="x"); self.goal_entry.insert(0,"L")

[Link](left, text="Animation delay (ms):").pack(anchor="w")

self.delay_entry = [Link](left); self.delay_entry.pack(fill="x"); self.delay_entry.insert(0,str(self.animation_delay))

[Link](left, text="Build Tree", command=self.build_graph).pack(fill="x", pady=3)

[Link](left, text="Run BFS", command=self.run_bfs).pack(fill="x")

[Link](left, text="Stop", command=self.stop_animation).pack(fill="x", pady=3)

[Link](left, text="Reset", command=[Link]).pack(fill="x", pady=3)

[Link](left, text="Output:").pack(anchor="w")

[Link] = [Link](left, width=36, height=14); [Link]()

[Link] = [Link](frame, bg="white")

[Link](side="left", fill="both", expand=True)

def reset(self):

self.stop_animation()

[Link]("1.0","end")

self.start_entry.delete(0,"end"); self.start_entry.insert(0,"A")

self.goal_entry.delete(0,"end"); self.goal_entry.insert(0,"L")

self.delay_entry.delete(0,"end"); self.delay_entry.insert(0,str(self.animation_delay))

[Link] = {}

self.node_positions = {}

[Link]("all")

[Link]("end","Reset done.\n")

def build_graph(self):

[Link] = {

"A": ["B","C","D"],

"B": ["E","F"],

"C": [],

"D": ["G","H"],

"E": ["I","J"],

"F": [],

"G": ["K","L"],

"H": [],

"I": [], "J": [], "K": [], "L": []

self.compute_positions()
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 3 of 21
self.draw_graph()

[Link]("end","Tree built.\n"); [Link]("end")


Document Code No. FM-SSCT-ACAD-
def compute_positions(self): 002
width = [Link].winfo_width() or 600 Revision No. 00
height = [Link].winfo_height() or 400
Effective Date 20 September 2018
levels = [] Page No. 3 of 21
def dfs_level(node, depth):

if len(levels) <= depth: Document Code No. FM-SSCT-ACAD-


[Link]([]) 002
if node not in levels[depth]:
Revision No. 00
levels[depth].append(node)
Effective Date 20 September 2018
for c in [Link](node, []):
Page No. 3 of 21
dfs_level(c, depth+1)

dfs_level("A", 0) Document Code No. FM-SSCT-ACAD-


positions = {}
002
v_spacing = max(80, height // (len(levels) + 1))
Revision No. 00
for i, level in enumerate(levels):
Effective Date 20 September 2018
count = len(level)
Page No. 3 of 21
h_spacing = max(80, width // (count + 1))

y = v_spacing * (i+1)

for j, node in enumerate(level):

x = h_spacing * (j+1)

positions[node] = (x,y)

self.node_positions = positions

def draw_graph(self, highlight=None, visit_path=None, final_path=None, label=None):

[Link]("all")

for u, nbrs in [Link]():

x1,y1 = self.node_positions.get(u,(0,0))

for v in nbrs:

x2,y2 = self.node_positions.get(v,(0,0))

[Link].create_line(x1,y1,x2,y2, arrow=[Link])

if visit_path and not final_path:

self.draw_path(visit_path, "orange")

if final_path:

self.draw_path(final_path, "purple")

for n,(x,y) in self.node_positions.items():

color = "lightblue"

if visit_path and n in visit_path and not final_path:

color = "orange"

if highlight and n in highlight:

color = "red"

if final_path and n in final_path:

color = "purple"

[Link].create_oval(x-20,y-20,x+20,y+20, fill=color)

[Link].create_text(x,y, text=n)

if label:

[Link].create_text(10,10, anchor="nw", text=label, font=("Arial",12,"bold"))

def draw_path(self, path, color):

if len(path) < 2: return

pts = []

for n in path:

x,y = self.node_positions[n]

[Link]([x,y])

[Link].create_line(pts, fill=color, width=3)


Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 4 of 21
def run_bfs(self):

if [Link]: return
Document Code No. FM-SSCT-ACAD-
self.animation_delay = int(self.delay_entry.get() or self.animation_delay) 002
start = self.start_entry.get().strip(); goal = self.goal_entry.get().strip() Revision No. 00
t = [Link](target=self._animate_bfs, args=(start,goal), daemon=True)
Effective Date 20 September 2018
[Link]() Page No. 4 of 21
def _animate_bfs(self, start, goal):

[Link] = True Document Code No. FM-SSCT-ACAD-


[Link]("end", f"Running BFS from {start} to {goal}\n"); [Link]("end") 002
path, visited = bfs([Link], start, goal)
Revision No. 00
highlight = set()
Effective Date 20 September 2018
visit_path = []
Page No. 4 of 21
visited_str = ""

for node in visited: Document Code No. FM-SSCT-ACAD-


if not [Link]: break
002
[Link](node); visit_path.append(node)
Revision No. 00
self.draw_graph(highlight=highlight, visit_path=visit_path)
Effective Date 20 September 2018
[Link]("end", f"Visited: {node}\n"); [Link]("end")
Page No. 4 of 21
visited_str += node + " > "

[Link](self.animation_delay/1000.0)

if path:

self.draw_graph(final_path=path)

[Link]("end", f"Path Found: {visited_str}\nPath: {' -> '.join(path)}\n")

else:

[Link]("end", "No path found.\n")

[Link] = False

def stop_animation(self):

[Link] = False

def on_canvas_resize(self, event):

if not [Link]: return

self.compute_positions()

self.draw_graph()

if __name__ == "__main__":

root = [Link]()

[Link]("1000x650")

app = BFSVisualizer(root)

[Link]()

OUTPUT:

2. DEPTH-FIRST SEARCH (DFS)

Depth-First Search (DFS) explores as far as possible along each path before backtracking. It uses a stack (LIFO) and is more memory-efficient than Breadth-
First Search (BFS) but does not guarantee the shortest path.

Key Features:

 Efficient for deep exploration.


 Can get stuck in infinite loops if cycles exist.
CODE SNIPPET:
import tkinter as tk
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 5 of 21
from tkinter import ttk, scrolledtext

import threading, time


Document Code No. FM-SSCT-ACAD-
def reconstruct_path(parent, start, goal): 002
if goal not in parent: Revision No. 00
return None
Effective Date 20 September 2018
path, cur = [], goal Page No. 5 of 21
while cur != start:

[Link](cur) Document Code No. FM-SSCT-ACAD-


cur = [Link](cur) 002
if cur is None:
Revision No. 00
return None
Effective Date 20 September 2018
[Link](start)
Page No. 5 of 21
return list(reversed(path))

def dfs(graph, start, goal): Document Code No. FM-SSCT-ACAD-


visited_order, parent, stack = [], {}, [start]
002
seen = set()
Revision No. 00
while stack:
Effective Date 20 September 2018
node = [Link]()
Page No. 5 of 21
if node in seen:

continue

[Link](node)

visited_order.append(node)

if node == goal:

return reconstruct_path(parent, start, goal), visited_order

for nbr in reversed([Link](node, [])):

if nbr not in seen:

parent[nbr] = node

[Link](nbr)

return None, visited_order

class DFSVisualizer:

def __init__(self, root):

[Link] = root

[Link]("DFS Visualizer")

[Link] = {}

self.node_positions = {}

[Link] = False

self.animation_delay = 600

self.setup_ui()

self.build_graph()

[Link]("<Configure>", self.on_canvas_resize)

def setup_ui(self):

frame = [Link]([Link]); [Link](fill="both", expand=True, padx=8, pady=8)

left = [Link](frame); [Link](side="left", fill="y")

[Link](left, text="Start:").pack(anchor="w")

self.start_entry = [Link](left); self.start_entry.pack(fill="x"); self.start_entry.insert(0,"A")

[Link](left, text="Goal:").pack(anchor="w")

self.goal_entry = [Link](left); self.goal_entry.pack(fill="x"); self.goal_entry.insert(0,"L")

[Link](left, text="Animation delay (ms):").pack(anchor="w")

self.delay_entry = [Link](left); self.delay_entry.pack(fill="x"); self.delay_entry.insert(0,str(self.animation_delay))

[Link](left, text="Build Tree", command=self.build_graph).pack(fill="x", pady=3)

[Link](left, text="Run DFS", command=self.run_dfs).pack(fill="x")

[Link](left, text="Stop", command=self.stop_animation).pack(fill="x", pady=3)

[Link](left, text="Reset", command=[Link]).pack(fill="x", pady=3)

[Link](left, text="Output:").pack(anchor="w")
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 6 of 21
[Link] = [Link](left, width=36, height=14); [Link]()

[Link] = [Link](frame, bg="white")


Document Code No. FM-SSCT-ACAD-
[Link](side="left", fill="both", expand=True) 002
def reset(self): Revision No. 00
self.stop_animation()
Effective Date 20 September 2018
[Link]("1.0","end") Page No. 6 of 21
self.start_entry.delete(0,"end"); self.start_entry.insert(0,"A")

self.goal_entry.delete(0,"end"); self.goal_entry.insert(0,"L") Document Code No. FM-SSCT-ACAD-


self.delay_entry.delete(0,"end"); self.delay_entry.insert(0,str(self.animation_delay)) 002
[Link] = {}
Revision No. 00
self.node_positions = {}
Effective Date 20 September 2018
[Link]("all")
Page No. 6 of 21
[Link]("end","Reset done.\n")

def build_graph(self): Document Code No. FM-SSCT-ACAD-


[Link] = {
002
"A": ["B","C","D"],
Revision No. 00
"B": ["E","F"],
Effective Date 20 September 2018
"C": [],
Page No. 6 of 21
"D": ["G","H"],

"E": ["I","J"],

"F": [],

"G": ["K","L"],

"H": [],

"I": [], "J": [], "K": [], "L": []

self.compute_positions()

self.draw_graph()

[Link]("end","Tree built.\n"); [Link]("end")

def compute_positions(self):

width = [Link].winfo_width() or 600

height = [Link].winfo_height() or 400

levels = []

def dfs_level(node, depth):

if len(levels) <= depth:

[Link]([])

if node not in levels[depth]:

levels[depth].append(node)

for c in [Link](node, []):

dfs_level(c, depth+1)

dfs_level("A", 0)

positions = {}

v_spacing = max(80, height // (len(levels) + 1))

for i, level in enumerate(levels):

count = len(level)

h_spacing = max(80, width // (count + 1))

y = v_spacing * (i+1)

for j, node in enumerate(level):

x = h_spacing * (j+1)

positions[node] = (x,y)

self.node_positions = positions

def draw_graph(self, highlight=None, visit_path=None, final_path=None, label=None):

[Link]("all")

for u, nbrs in [Link]():

x1,y1 = self.node_positions.get(u,(0,0))
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 7 of 21
for v in nbrs:

x2,y2 = self.node_positions.get(v,(0,0))
Document Code No. FM-SSCT-ACAD-
[Link].create_line(x1,y1,x2,y2, arrow=[Link]) 002
if visit_path and not final_path: Revision No. 00
self.draw_path(visit_path, "orange")
Effective Date 20 September 2018
if final_path: Page No. 7 of 21
self.draw_path(final_path, "purple")

for n,(x,y) in self.node_positions.items(): Document Code No. FM-SSCT-ACAD-


color = "lightblue" 002
if visit_path and n in visit_path and not final_path:
Revision No. 00
color = "orange"
Effective Date 20 September 2018
if highlight and n in highlight:
Page No. 7 of 21
color = "red"

if final_path and n in final_path: Document Code No. FM-SSCT-ACAD-


color = "purple"
002
[Link].create_oval(x-20,y-20,x+20,y+20, fill=color)
Revision No. 00
[Link].create_text(x,y, text=n)
Effective Date 20 September 2018
if label:
Page No. 7 of 21
[Link].create_text(10,10, anchor="nw", text=label, font=("Arial",12,"bold"))

def draw_path(self, path, color):

if len(path) < 2: return

pts = []

for n in path:

x,y = self.node_positions[n]

[Link]([x,y])

[Link].create_line(pts, fill=color, width=3)

def run_dfs(self):

if [Link]: return

self.animation_delay = int(self.delay_entry.get() or self.animation_delay)

start = self.start_entry.get().strip(); goal = self.goal_entry.get().strip()

t = [Link](target=self._animate_dfs, args=(start,goal), daemon=True)

[Link]()

def _animate_dfs(self, start, goal):

[Link] = True

[Link]("end", f"Running DFS from {start} to {goal}\n"); [Link]("end")

path, visited = dfs([Link], start, goal)

highlight = set()

visit_path = []

visited_str = ""

for node in visited:

if not [Link]: break

[Link](node); visit_path.append(node)

self.draw_graph(highlight=highlight, visit_path=visit_path)

[Link]("end", f"Visited: {node}\n"); [Link]("end")

visited_str += node + " > "

[Link](self.animation_delay/1000.0)

if path:

self.draw_graph(final_path=path)

[Link]("end", f"Path Found: {visited_str}\nPath: {' -> '.join(path)}\n")

else:

[Link]("end", "No path found.\n")

[Link] = False

def stop_animation(self):

[Link] = False
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 8 of 21
def on_canvas_resize(self, event):

if not [Link]: return


Document Code No. FM-SSCT-ACAD-
self.compute_positions() 002
self.draw_graph() Revision No. 00
if __name__ == "__main__":
Effective Date 20 September 2018
root = [Link]() Page No. 8 of 21
[Link]("1000x650")

app = DFSVisualizer(root) Document Code No. FM-SSCT-ACAD-


[Link]() 002
OUTPUT:
Revision No. 00

Effective Date 20 September 2018


Page No. 8 of 21

Document Code No. FM-SSCT-ACAD-


002
Revision No. 00

Effective Date 20 September 2018


Page No. 8 of 21

3. UNIFORM-COST SEARCH (UCS)

Uniform-Cost Search (UCS) extends Breadth-First Search (BFS) by considering path costs, always expanding the least-cost node first. It guarantees finding
the optimal path when all costs are non-negative.

Key Features:

 Finds the least-cost path.


 Slower than Breadth-First Search (BFS) in uniform cost cases.

CODE SNIPPET:
import tkinter as tk

from tkinter import ttk, scrolledtext

import threading, time

import heapq, random

def reconstruct_path(parent, start, goal):

if goal not in parent:

return None

path, cur = [], goal

while cur != start:

[Link](cur)

cur = [Link](cur)

if cur is None:

return None

[Link](start)

return list(reversed(path))

def ucs(weighted_graph, start, goal):

visited_order, parent = [], {}

pq = [(0, start)]

cost_so_far = {start: 0}

seen = set()

while pq:

d, node = [Link](pq)
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 9 of 21
if node in seen:

continue
Document Code No. FM-SSCT-ACAD-
[Link](node) 002
visited_order.append(node) Revision No. 00
if node == goal:
Effective Date 20 September 2018
return reconstruct_path(parent, start, goal), visited_order, d Page No. 9 of 21
for nbr, w in weighted_graph.get(node, []):

new_cost = d + w Document Code No. FM-SSCT-ACAD-


if nbr not in cost_so_far or new_cost < cost_so_far[nbr]: 002
cost_so_far[nbr] = new_cost
Revision No. 00
parent[nbr] = node
Effective Date 20 September 2018
[Link](pq, (new_cost, nbr))
Page No. 9 of 21
return None, visited_order, float("inf")

class UCSVisualizer: Document Code No. FM-SSCT-ACAD-


def __init__(self, root):
002
[Link] = root
Revision No. 00
[Link]("UCS Visualizer")
Effective Date 20 September 2018
[Link] = {}
Page No. 9 of 21
self.weighted_map = {}

self.node_positions = {}

[Link] = False

self.animation_delay = 600

self.setup_ui()

self.build_graph()

[Link]("<Configure>", self.on_canvas_resize)

def setup_ui(self):

frame = [Link]([Link]); [Link](fill="both", expand=True, padx=8, pady=8)

left = [Link](frame); [Link](side="left", fill="y")

[Link](left, text="Start:").pack(anchor="w")

self.start_entry = [Link](left); self.start_entry.pack(fill="x"); self.start_entry.insert(0,"A")

[Link](left, text="Goal:").pack(anchor="w")

self.goal_entry = [Link](left); self.goal_entry.pack(fill="x"); self.goal_entry.insert(0,"L")

[Link](left, text="Animation delay (ms):").pack(anchor="w")

self.delay_entry = [Link](left); self.delay_entry.pack(fill="x"); self.delay_entry.insert(0,str(self.animation_delay))

[Link](left, text="Build Tree", command=self.build_graph).pack(fill="x", pady=3)

[Link](left, text="Randomize Weights & Run UCS", command=self.run_ucs).pack(fill="x")

[Link](left, text="Stop", command=self.stop_animation).pack(fill="x", pady=3)

[Link](left, text="Reset", command=[Link]).pack(fill="x", pady=3)

[Link](left, text="Output:").pack(anchor="w")

[Link] = [Link](left, width=36, height=14); [Link]()

[Link] = [Link](frame, bg="white")

[Link](side="left", fill="both", expand=True)

def reset(self):

self.stop_animation()

[Link]("1.0","end")

self.start_entry.delete(0,"end"); self.start_entry.insert(0,"A")

self.goal_entry.delete(0,"end"); self.goal_entry.insert(0,"L")

self.delay_entry.delete(0,"end"); self.delay_entry.insert(0,str(self.animation_delay))

[Link] = {}

self.weighted_map = {}

self.node_positions = {}

[Link]("all")

[Link]("end","Reset done.\n")

def build_graph(self):
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 10 of 21
[Link] = {

"A": ["B","C","D"],
Document Code No. FM-SSCT-ACAD-
"B": ["E","F"], 002
"C": [], Revision No. 00
"D": ["G","H"],
Effective Date 20 September 2018
"E": ["I","J"], Page No. 10 of 21
"F": [],

"G": ["K","L"], Document Code No. FM-SSCT-ACAD-


"H": [], 002
"I": [], "J": [], "K": [], "L": []
Revision No. 00
}
Effective Date 20 September 2018
self.compute_positions()
Page No. 10 of 21
self.draw_graph()

[Link]("end","Tree built.\n"); [Link]("end") Document Code No. FM-SSCT-ACAD-


def compute_positions(self):
002
width = [Link].winfo_width() or 600
Revision No. 00
height = [Link].winfo_height() or 400
Effective Date 20 September 2018
levels = []
Page No. 10 of 21
def dfs_level(node, depth):

if len(levels) <= depth:

[Link]([])

if node not in levels[depth]:

levels[depth].append(node)

for c in [Link](node, []):

dfs_level(c, depth+1)

dfs_level("A", 0)

positions = {}

v_spacing = max(80, height // (len(levels) + 1))

for i, level in enumerate(levels):

count = len(level)

h_spacing = max(80, width // (count + 1))

y = v_spacing * (i+1)

for j, node in enumerate(level):

x = h_spacing * (j+1)

positions[node] = (x,y)

self.node_positions = positions

def draw_graph(self, highlight=None, visit_path=None, final_path=None, label=None):

[Link]("all")

for u, nbrs in [Link]():

x1,y1 = self.node_positions.get(u,(0,0))

for v in nbrs:

x2,y2 = self.node_positions.get(v,(0,0))

[Link].create_line(x1,y1,x2,y2, arrow=[Link])

if visit_path and not final_path:

self.draw_path(visit_path, "orange")

if final_path:

self.draw_path(final_path, "purple")

for n,(x,y) in self.node_positions.items():

color = "lightblue"

if visit_path and n in visit_path and not final_path:

color = "orange"

if highlight and n in highlight:

color = "red"

if final_path and n in final_path:


Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 11 of 21
color = "purple"

[Link].create_oval(x-20,y-20,x+20,y+20, fill=color)
Document Code No. FM-SSCT-ACAD-
[Link].create_text(x,y, text=n) 002
if label: Revision No. 00
[Link].create_text(10,10, anchor="nw", text=label, font=("Arial",12,"bold"))
Effective Date 20 September 2018
if self.weighted_map: Page No. 11 of 21
self.draw_edge_weights()

def draw_path(self, path, color): Document Code No. FM-SSCT-ACAD-


if len(path) < 2: return 002
pts = []
Revision No. 00
for n in path:
Effective Date 20 September 2018
x,y = self.node_positions[n]
Page No. 11 of 21
[Link]([x,y])

[Link].create_line(pts, fill=color, width=3) Document Code No. FM-SSCT-ACAD-


def draw_edge_weights(self):
002
for u, nbrs in self.weighted_map.items():
Revision No. 00
x1,y1 = self.node_positions.get(u,(0,0))
Effective Date 20 September 2018
for v,w in nbrs:
Page No. 11 of 21
x2,y2 = self.node_positions.get(v,(0,0))

mx,my = (x1+x2)//2, (y1+y2)//2

[Link].create_text(mx,my, text=str(w), fill="blue", font=("Arial",10,"bold"))

def run_ucs(self):

if [Link]: return

self.animation_delay = int(self.delay_entry.get() or self.animation_delay)

# generate random weights

self.weighted_map = {}

for u, nbrs in [Link]():

self.weighted_map[u] = []

for v in nbrs:

w = [Link](1,10)

self.weighted_map[u].append((v,w))

[Link]("end","Random weights:\n")

for u,nbrs in self.weighted_map.items():

for v,w in nbrs:

[Link]("end", f"{u} -> {v} : {w}\n")

[Link]("end")

self.draw_graph()

start = self.start_entry.get().strip(); goal = self.goal_entry.get().strip()

t = [Link](target=self._animate_ucs, args=(start,goal), daemon=True)

[Link]()

def _animate_ucs(self, start, goal):

[Link] = True

[Link]("end", f"Running UCS from {start} to {goal}\n"); [Link]("end")

path, visited, cost = ucs(self.weighted_map, start, goal)

highlight = set()

visit_path = []

visited_str = ""

for node in visited:

if not [Link]: break

[Link](node); visit_path.append(node)

# UCS doesn't show a path while animating — show visited highlight only

self.draw_graph(highlight=highlight)

[Link]("end", f"Visited: {node}\n"); [Link]("end")

visited_str += node + " > "


Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 12 of 21
[Link](self.animation_delay/1000.0)

if path:
Document Code No. FM-SSCT-ACAD-
self.draw_graph(final_path=path) 002
[Link]("end", f"Total cost: {cost}\n") Revision No. 00
[Link]("end", f"Visit path: {visited_str}\n")
Effective Date 20 September 2018
[Link]("end", f"Path found: {' -> '.join(path)}\n") Page No. 12 of 21
else:

[Link]("end", "No path found.\n") Document Code No. FM-SSCT-ACAD-


[Link] = False 002
def stop_animation(self):
Revision No. 00
[Link] = False
Effective Date 20 September 2018
def on_canvas_resize(self, event):
Page No. 12 of 21
if not [Link]: return

self.compute_positions() Document Code No. FM-SSCT-ACAD-


self.draw_graph()
002
if __name__ == "__main__":
Revision No. 00
root = [Link]()
Effective Date 20 September 2018
[Link]("1000x650")
Page No. 12 of 21
app = UCSVisualizer(root)

[Link]()

OUTPUT:

4. DEPTH-LIMITED SEARCH (DLS)


Depth Limited Search (DLS) is a variation of Depth First Search (DFS) that limits the depth of exploration to prevent infinite loops in large or infinite search spaces.
Key Features:

 Useful when the goal depth is known.


 Cannot find solutions beyond the depth limit.
CODE SNIPPET:
import tkinter as tk

from tkinter import ttk, scrolledtext

import threading, time

def reconstruct_path(parent, start, goal):

if goal not in parent:

return None

path, cur = [], goal

while cur != start:

[Link](cur)

cur = [Link](cur)

if cur is None:

return None

[Link](start)

return list(reversed(path))

def dls(graph, start, goal, limit):

visited_order, parent = [], {start: None}

found = [False]

def dfs_limited(node, depth):

visited_order.append(node)

if node == goal:

found[0] = True

return True
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 13 of 21
if depth == 0:

return False
Document Code No. FM-SSCT-ACAD-
for nbr in [Link](node, []): 002
if nbr not in parent: Revision No. 00
parent[nbr] = node
Effective Date 20 September 2018
if dfs_limited(nbr, depth - 1): Page No. 13 of 21
return True

return False Document Code No. FM-SSCT-ACAD-


dfs_limited(start, limit) 002
if found[0]:
Revision No. 00
return reconstruct_path(parent, start, goal), visited_order
Effective Date 20 September 2018
return None, visited_order
Page No. 13 of 21
class DLSVisualizer:

def __init__(self, root): Document Code No. FM-SSCT-ACAD-


[Link] = root
002
[Link]("DLS (Depth-Limited Search) Visualizer")
Revision No. 00
[Link] = {}
Effective Date 20 September 2018
self.node_positions = {}
Page No. 13 of 21
[Link] = False

self.animation_delay = 600

self.setup_ui()

self.build_graph()

[Link]("<Configure>", self.on_canvas_resize)

def setup_ui(self):

frame = [Link]([Link]); [Link](fill="both", expand=True, padx=8, pady=8)

left = [Link](frame); [Link](side="left", fill="y")

[Link](left, text="Start:").pack(anchor="w")

self.start_entry = [Link](left); self.start_entry.pack(fill="x"); self.start_entry.insert(0,"A")

[Link](left, text="Goal:").pack(anchor="w")

self.goal_entry = [Link](left); self.goal_entry.pack(fill="x"); self.goal_entry.insert(0,"L")

[Link](left, text="Depth limit:").pack(anchor="w")

self.depth_entry = [Link](left); self.depth_entry.pack(fill="x"); self.depth_entry.insert(0,"3")

[Link](left, text="Animation delay (ms):").pack(anchor="w")

self.delay_entry = [Link](left); self.delay_entry.pack(fill="x"); self.delay_entry.insert(0,str(self.animation_delay))

[Link](left, text="Build Tree", command=self.build_graph).pack(fill="x", pady=3)

[Link](left, text="Run DLS", command=self.run_dls).pack(fill="x")

[Link](left, text="Stop", command=self.stop_animation).pack(fill="x", pady=3)

[Link](left, text="Reset", command=[Link]).pack(fill="x", pady=3)

[Link](left, text="Output:").pack(anchor="w")

[Link] = [Link](left, width=36, height=14); [Link]()

[Link] = [Link](frame, bg="white")

[Link](side="left", fill="both", expand=True)

def reset(self):

self.stop_animation()

[Link]("1.0","end")

self.start_entry.delete(0,"end"); self.start_entry.insert(0,"A")

self.goal_entry.delete(0,"end"); self.goal_entry.insert(0,"L")

self.depth_entry.delete(0,"end"); self.depth_entry.insert(0,"3")

self.delay_entry.delete(0,"end"); self.delay_entry.insert(0,str(self.animation_delay))

[Link] = {}

self.node_positions = {}

[Link]("all")

[Link]("end","Reset done.\n")

def build_graph(self):
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 14 of 21
[Link] = {

"A": ["B","C","D"],
Document Code No. FM-SSCT-ACAD-
"B": ["E","F"], 002
"C": [], Revision No. 00
"D": ["G","H"],
Effective Date 20 September 2018
"E": ["I","J"], Page No. 14 of 21
"F": [],

"G": ["K","L"], Document Code No. FM-SSCT-ACAD-


"H": [], 002
"I": [], "J": [], "K": [], "L": []
Revision No. 00
}
Effective Date 20 September 2018
self.compute_positions()
Page No. 14 of 21
self.draw_graph()

[Link]("end","Tree built.\n"); [Link]("end") Document Code No. FM-SSCT-ACAD-


def compute_positions(self):
002
width = [Link].winfo_width() or 600
Revision No. 00
height = [Link].winfo_height() or 400
Effective Date 20 September 2018
levels = []
Page No. 14 of 21
def dfs_level(node, depth):

if len(levels) <= depth:

[Link]([])

if node not in levels[depth]:

levels[depth].append(node)

for c in [Link](node, []):

dfs_level(c, depth+1)

dfs_level("A", 0)

positions = {}

v_spacing = max(80, height // (len(levels) + 1))

for i, level in enumerate(levels):

count = len(level)

h_spacing = max(80, width // (count + 1))

y = v_spacing * (i+1)

for j, node in enumerate(level):

x = h_spacing * (j+1)

positions[node] = (x,y)

self.node_positions = positions

def draw_graph(self, highlight=None, visit_path=None, final_path=None, label=None):

[Link]("all")

for u, nbrs in [Link]():

x1,y1 = self.node_positions.get(u,(0,0))

for v in nbrs:

x2,y2 = self.node_positions.get(v,(0,0))

[Link].create_line(x1,y1,x2,y2, arrow=[Link])

if visit_path and not final_path:

self.draw_path(visit_path, "orange")

if final_path:

self.draw_path(final_path, "purple")

for n,(x,y) in self.node_positions.items():

color = "lightblue"

if visit_path and n in visit_path and not final_path:

color = "orange"

if highlight and n in highlight:

color = "red"

if final_path and n in final_path:


Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 15 of 21
color = "purple"

[Link].create_oval(x-20,y-20,x+20,y+20, fill=color)
Document Code No. FM-SSCT-ACAD-
[Link].create_text(x,y, text=n) 002
if label: Revision No. 00
[Link].create_text(10,10, anchor="nw", text=label, font=("Arial",12,"bold"))
Effective Date 20 September 2018
def draw_path(self, path, color): Page No. 15 of 21
if len(path) < 2: return

pts = [] Document Code No. FM-SSCT-ACAD-


for n in path: 002
x,y = self.node_positions[n]
Revision No. 00
[Link]([x,y])
Effective Date 20 September 2018
[Link].create_line(pts, fill=color, width=3)
Page No. 15 of 21
def run_dls(self):

if [Link]: return Document Code No. FM-SSCT-ACAD-


self.animation_delay = int(self.delay_entry.get() or self.animation_delay)
002
depth_limit = int(self.depth_entry.get() or 3)
Revision No. 00
start = self.start_entry.get().strip(); goal = self.goal_entry.get().strip()
Effective Date 20 September 2018
t = [Link](target=self._animate_dls, args=(start,goal,depth_limit), daemon=True)
Page No. 15 of 21
[Link]()

def _animate_dls(self, start, goal, depth_limit):

[Link] = True

[Link]("end", f"Running DLS from {start} to {goal} (limit={depth_limit})\n"); [Link]("end")

path, visited = dls([Link], start, goal, depth_limit)

highlight = set()

visit_path = []

visited_str = ""

for node in visited:

if not [Link]: break

[Link](node); visit_path.append(node)

self.draw_graph(highlight=highlight, visit_path=visit_path)

[Link]("end", f"Visited: {node}\n"); [Link]("end")

visited_str += node + " > "

[Link](self.animation_delay/1000.0)

if path:

self.draw_graph(final_path=path)

[Link]("end", f"Path Found: {visited_str}\nPath: {' -> '.join(path)}\n")

else:

[Link]("end", "No path found within depth limit.\n")

[Link] = False

def stop_animation(self):

[Link] = False

def on_canvas_resize(self, event):

if not [Link]: return

self.compute_positions()

self.draw_graph()

if __name__ == "__main__":

root = [Link]()

[Link]("1000x650")

app = DLSVisualizer(root)

[Link]()

OUTPUT:
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 16 of 21

Document Code No. FM-SSCT-ACAD-


002
Revision No. 00

Effective Date 20 September 2018


Page No. 16 of 21

Document Code No. FM-SSCT-ACAD-


002
Revision No. 00

Effective Date 20 September 2018


Page No. 16 of 21

Document Code No. FM-SSCT-ACAD-


002
Revision No. 00

Effective Date 20 September 2018


Page No. 16 of 21

5. ITERATIVE DEEPENING SEARCH (IDS)

Iterative Deepening Search (IDS) combines Breadth-First Search (BFS) and Depth First Search (DFS) by running Depth First Search (DFS) with increasing depth limits
until a solution is found.
Key Features:

 Ensures completeness and optimality like Breadth-First Search (BFS).


 Uses less memory than Breadth-First Search (BFS).
CODE SNIPPET:
import tkinter as tk

from tkinter import ttk, scrolledtext

import threading, time

def reconstruct_path(parent, start, goal):

if goal not in parent:

return None

path, cur = [], goal

while cur != start:

[Link](cur)

cur = [Link](cur)

if cur is None:

return None

[Link](start)

return list(reversed(path))

def dls(graph, start, goal, limit):

visited_order, parent = [], {start: None}

found = [False]

def dfs_limited(node, depth):

visited_order.append(node)

if node == goal:

found[0] = True

return True

if depth == 0:

return False

for nbr in [Link](node, []):

if nbr not in parent:

parent[nbr] = node

if dfs_limited(nbr, depth - 1):

return True
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 17 of 21
return False

dfs_limited(start, limit)
Document Code No. FM-SSCT-ACAD-
if found[0]: 002
return reconstruct_path(parent, start, goal), visited_order Revision No. 00
return None, visited_order
Effective Date 20 September 2018
def ids(graph, start, goal, max_depth=20): Page No. 17 of 21
combined = []

iterations = [] Document Code No. FM-SSCT-ACAD-


for depth in range(max_depth + 1): 002
path, visited = dls(graph, start, goal, depth)
Revision No. 00
[Link](visited)
Effective Date 20 September 2018
for n in visited:
Page No. 17 of 21
if n not in combined:

[Link](n) Document Code No. FM-SSCT-ACAD-


if path:
002
return path, combined, iterations, depth
Revision No. 00
return None, combined, iterations, None
Effective Date 20 September 2018
class IDSVisualizer:
Page No. 17 of 21
def __init__(self, root):

[Link] = root

[Link]("IDS Visualizer")

[Link] = {}

self.node_positions = {}

[Link] = False

self.animation_delay = 600

self.setup_ui()

self.build_graph()

[Link]("<Configure>", self.on_canvas_resize)

def setup_ui(self):

frame = [Link]([Link]); [Link](fill="both", expand=True, padx=8, pady=8)

left = [Link](frame); [Link](side="left", fill="y")

[Link](left, text="Start:").pack(anchor="w")

self.start_entry = [Link](left); self.start_entry.pack(fill="x"); self.start_entry.insert(0,"A")

[Link](left, text="Goal:").pack(anchor="w")

self.goal_entry = [Link](left); self.goal_entry.pack(fill="x"); self.goal_entry.insert(0,"L")

[Link](left, text="Max depth (IDS):").pack(anchor="w")

self.depth_entry = [Link](left); self.depth_entry.pack(fill="x"); self.depth_entry.insert(0,"4")

[Link](left, text="Animation delay (ms):").pack(anchor="w")

self.delay_entry = [Link](left); self.delay_entry.pack(fill="x"); self.delay_entry.insert(0,str(self.animation_delay))

[Link](left, text="Build Tree", command=self.build_graph).pack(fill="x", pady=3)

[Link](left, text="Run IDS", command=self.run_ids).pack(fill="x")

[Link](left, text="Stop", command=self.stop_animation).pack(fill="x", pady=3)

[Link](left, text="Reset", command=[Link]).pack(fill="x", pady=3)

[Link](left, text="Output:").pack(anchor="w")

[Link] = [Link](left, width=36, height=14); [Link]()

[Link] = [Link](frame, bg="white")

[Link](side="left", fill="both", expand=True)

def reset(self):

self.stop_animation()

[Link]("1.0","end")

self.start_entry.delete(0,"end"); self.start_entry.insert(0,"A")

self.goal_entry.delete(0,"end"); self.goal_entry.insert(0,"L")

self.depth_entry.delete(0,"end"); self.depth_entry.insert(0,"4")

self.delay_entry.delete(0,"end"); self.delay_entry.insert(0,str(self.animation_delay))
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 18 of 21
[Link] = {}

self.node_positions = {}
Document Code No. FM-SSCT-ACAD-
[Link]("all") 002
[Link]("end","Reset done.\n") Revision No. 00
def build_graph(self):
Effective Date 20 September 2018
[Link] = { Page No. 18 of 21
"A": ["B","C","D"],

"B": ["E","F"], Document Code No. FM-SSCT-ACAD-


"C": [], 002
"D": ["G","H"],
Revision No. 00
"E": ["I","J"],
Effective Date 20 September 2018
"F": [],
Page No. 18 of 21
"G": ["K","L"],

"H": [], Document Code No. FM-SSCT-ACAD-


"I": [], "J": [], "K": [], "L": []
002
}
Revision No. 00
self.compute_positions()
Effective Date 20 September 2018
self.draw_graph()
Page No. 18 of 21
[Link]("end","Tree built.\n"); [Link]("end")

def compute_positions(self):

width = [Link].winfo_width() or 600

height = [Link].winfo_height() or 400

levels = []

def dfs_level(node, depth):

if len(levels) <= depth:

[Link]([])

if node not in levels[depth]:

levels[depth].append(node)

for c in [Link](node, []):

dfs_level(c, depth+1)

dfs_level("A", 0)

positions = {}

v_spacing = max(80, height // (len(levels) + 1))

for i, level in enumerate(levels):

count = len(level)

h_spacing = max(80, width // (count + 1))

y = v_spacing * (i+1)

for j, node in enumerate(level):

x = h_spacing * (j+1)

positions[node] = (x,y)

self.node_positions = positions

def draw_graph(self, highlight=None, visit_path=None, final_path=None, label=None):

[Link]("all")

for u, nbrs in [Link]():

x1,y1 = self.node_positions.get(u,(0,0))

for v in nbrs:

x2,y2 = self.node_positions.get(v,(0,0))

[Link].create_line(x1,y1,x2,y2, arrow=[Link])

if visit_path and not final_path:

self.draw_path(visit_path, "orange")

if final_path:

self.draw_path(final_path, "purple")

for n,(x,y) in self.node_positions.items():

color = "lightblue"
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 19 of 21
if visit_path and n in visit_path and not final_path:

color = "orange"
Document Code No. FM-SSCT-ACAD-
if highlight and n in highlight: 002
color = "red" Revision No. 00
if final_path and n in final_path:
Effective Date 20 September 2018
color = "purple" Page No. 19 of 21
[Link].create_oval(x-20,y-20,x+20,y+20, fill=color)

[Link].create_text(x,y, text=n) Document Code No. FM-SSCT-ACAD-


if label: 002
[Link].create_text(10,10, anchor="nw", text=label, font=("Arial",12,"bold"))
Revision No. 00
def draw_path(self, path, color):
Effective Date 20 September 2018
if len(path) < 2: return
Page No. 19 of 21
pts = []

for n in path: Document Code No. FM-SSCT-ACAD-


x,y = self.node_positions[n]
002
[Link]([x,y])
Revision No. 00
[Link].create_line(pts, fill=color, width=3)
Effective Date 20 September 2018
def run_ids(self):
Page No. 19 of 21
if [Link]: return

self.animation_delay = int(self.delay_entry.get() or self.animation_delay)

max_depth = int(self.depth_entry.get() or 4)

start = self.start_entry.get().strip(); goal = self.goal_entry.get().strip()

t = [Link](target=self._animate_ids, args=(start,goal,max_depth), daemon=True)

[Link]()

def _animate_ids(self, start, goal, max_depth):

[Link] = True

[Link]("end", f"Running IDS from {start} to {goal} (max_depth={max_depth})\n"); [Link]("end")

path, combined, iterations, depth_found = ids([Link], start, goal, max_depth)

combined_so_far = []

found = False

for d, iter_vis in enumerate(iterations):

if not [Link]: break

[Link]("end", f"\n--- IDS Iteration: depth={d} ---\n"); [Link]("end")

iter_visit_path = []

for node in iter_vis:

if not [Link]: break

iter_visit_path.append(node)

if node not in combined_so_far:

combined_so_far.append(node)

highlight = set([node])

self.draw_graph(highlight=highlight, visit_path=iter_visit_path, label=f"IDS depth={d}")

[Link]("end", f"Visited (d={d}): {node}\n"); [Link]("end")

[Link](self.animation_delay/1000.0)

[Link](0.25)

if path and d == depth_found:

found = True

break

if path:

self.draw_graph(final_path=path)

[Link]("end", f"\nPath found at depth {depth_found}: {' -> '.join(path)}\n")

else:

self.draw_graph()

[Link]("end", "No path found within max depth.\n")

[Link]("end")
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 20 of 21
[Link] = False

def stop_animation(self):
Document Code No. FM-SSCT-ACAD-
[Link] = False 002
def on_canvas_resize(self, event): Revision No. 00
if not [Link]: return
Effective Date 20 September 2018
self.compute_positions() Page No. 20 of 21
self.draw_graph()

if __name__ == "__main__": Document Code No. FM-SSCT-ACAD-


root = [Link]() 002
[Link]("1000x650")
Revision No. 00
app = IDSVisualizer(root)
Effective Date 20 September 2018
[Link]()
Page No. 20 of 21

Document Code No. FM-SSCT-ACAD-


OUTPUT: 002
Revision No. 00

Effective Date 20 September 2018


Page No. 20 of 21

COLLEGE OF ENGINEERING & INFORMATION TECHNOLOGY


First Semester, Academic Year 2025-2026
CS 315: ELECTIVE 2 (INTELLIGENT SYSTEM)

Rubric – Laboratory Simulation on Search Algorithms


Total Points: 100

4 - Excellent 3 - Proficient 2 - Developing 1 - Needs Improvement


Criteria Weight Rating
(100) (85) (70) (55)

Accuracy of Algorithm Algorithm works perfectly for all test Minor errors in Multiple errors, incomplete Major errors, does not
Implementation 40% cases and meets all requirements implementation
functional
but overall results, or partial functionality function as intended
Efficiency of Code 30% Code is highly optimized, minimal Acceptable efficiency, minor Code runs but is inefficient, Code is very slow or
complexity, runs fast optimizations possible redundant processes poorly structured.
Clarity of Documentation 20% Well-organized, clear, and detailed Documentation is clear but Documentation is incomplete No documentation or very
documentation with examples lacks minor details or somewhat unclear unclear
Timely Submission 10% Submitted on or before the deadline 1–2 days late 3–4 days late More than 4 days late or
not submitted
TOTAL
Remarks:

Prepared by:

MONALEE A. DELA CERNA, DIT


Faculty, CCIS
Document Code No. FM-SSCT-ACAD-
Repulic of the Philippines
002
SURIGAO DEL NORTE STATE UNIVERSITY
Revision No. 00
Narciso Street, Surigao City 8400, Philippines
Effective Date 20 September 2018
“For Nation’s Greatr
Page No. 21 of 21

Document Code No. FM-SSCT-ACAD-


002
Revision No. 00

Effective Date 20 September 2018


Page No. 21 of 21

Document Code No. FM-SSCT-ACAD-


002
Revision No. 00

Effective Date 20 September 2018


Page No. 21 of 21

Document Code No. FM-SSCT-ACAD-


002
Revision No. 00

Effective Date 20 September 2018


Page No. 21 of 21

You might also like