CS2101 (AI) · IS122 (Bioinformatics, Software Engineering) Faculty of Computers and Information Sciences, Mansoura University
Course repository. We implement the structures ourselves rather than reach for Python's built-ins — the point is to build the thing, not to call it.
The storage rule. Every structure in dsa/ keeps its data only in the course
Array (dsa/array.py: fixed size, O(1) indexing, nothing else), in node
objects, or in another structure you built — never in a Python list, dict or
set. Lists are for passing data in and out, not for storing it. Why:
Lecture 02.
Topics: complexity, recursion, arrays and dynamic arrays, linked lists, stacks, queues, searching, sorting (basic and advanced), trees and traversals, heaps and priority queues, hash maps, graphs and graph searches, and the principles of language translation — the union of what all three program bylaws declare. Dynamic programming is included as enrichment.
Announcements: WhatsApp channel · Video: youtube.com/@0xHGH · Quizzes: helghareeb.github.io/en/quizzes · Recordings: helghareeb.github.io/en/videos
You need Python 3.10 or newer and Graphviz
(the dot binary, not only the pip package).
git clone https://github.com/helghareeb/DSA27.git
cd DSA27
py -3.13 -m venv .venv
.\.venv\Scripts\activate
pip install -r requirements.txtOn macOS or Linux, use python3 -m venv .venv and source .venv/bin/activate.
Check your setup before anything else:
pytest -m "not challenge"All of these must pass. They verify your interpreter, the plotting stack, Graphviz, and the drawing helpers. If one fails, the message tells you exactly what is missing — fix that before blaming your own code.
Windows note: if
pythonopens the Microsoft Store instead of running, turn off the Store aliases under Settings → Apps → Advanced app settings → App execution aliases forpython.exeandpython3.exe.
| Path | What it is |
|---|---|
dsa/ |
The structures and algorithms — you implement these |
tools/ |
Build the PDFs and figures — not needed for the exercises |
viz/ |
Drawing, animation and timing helpers — already written, just use them |
labs/ |
Weeks 1–3 Python lab exercises — you implement these first |
practice/ |
Question-bank coding problems — ungraded, checked by pytest -m practice |
tests/ |
The exercises, as tests. Make them pass. |
notebooks/ |
One notebook per lecture topic |
Every function in dsa/ is a skeleton: the docstring states the contract and
the complexity target, and the body raises NotImplementedError. The tests in
tests/ define exactly what "correct" means.
pytest tests/test_linked_list.py -v # one topic
pytest -m challenge # every exercise
pytest -m lab # only the weeks 1-3 labs
pytest -m practice # only the question-bank problems
pytest -x # stop at the first failureThey all fail on day one. That is the assignment.
The helpers in viz/ take plain Python data, so they work with whatever you
write — they never import dsa/.
Draw a structure:
from viz.draw import draw_array, draw_linked_list, draw_tree, draw_array_as_tree
draw_array([5, 2, 9, 1], highlight=2, done=[0])
draw_linked_list(["a", "b", "c"], highlight=1)
draw_tree([("8", "3"), ("8", "10"), ("3", "1")], highlight={"1"})
draw_array_as_tree([9, 7, 5, 3, 1]) # a heap: the array IS the treeStep through an algorithm. Write your sort as a generator that yields a snapshot, and you get animation and scrubbing for free:
def bubble_sort_steps(values):
values = list(values)
for i in range(len(values)):
for j in range(len(values) - i - 1):
yield values, (j, j + 1) # about to compare these two
if values[j] > values[j + 1]:
values[j], values[j + 1] = values[j + 1], values[j]
yield values, ()from viz.animate import step_slider, animate_bars
from IPython.display import HTML
step_slider(bubble_sort_steps([5, 2, 9, 1, 7])) # slider, you set the pace
HTML(animate_bars(bubble_sort_steps([5, 2, 9, 1])).to_jshtml()) # plays itselfMeasure complexity instead of asserting it:
from viz.complexity import measure, plot_growth
import random
sizes = [1000, 2000, 4000, 8000, 16000]
make = lambda n: (sorted(random.random() for _ in range(n)), 0.5)
plot_growth(
{"linear": measure(lambda a: linear_search(*a), sizes, make),
"binary": measure(lambda a: binary_search(*a), sizes, make)},
reference=["n", "log n"],
)jupyter labSelect the DSA27 (Python 3.13) kernel, or in VS Code pick the interpreter
at .venv\Scripts\python.exe.
Notebook outputs are stripped automatically on commit via nbstripout, so
diffs stay readable and re-running a cell does not create a conflict. Your
outputs stay visible locally — only what gets committed is cleaned. After
cloning, activate it once:
nbstripout --installThis is the most useful habit in the course. Set a breakpoint in the gutter of
dsa/linked_list.py, press F5, and choose pytest: current test file —
then watch node.next change in the Variables panel as you step with F10.
Seeing a pointer move beats any diagram, including the ones in viz/.