Skip to content
helghareebPublic

About

No description, website, or topics provided.

Resources

Stars

22 stars

Watchers

4 watching

Forks

Latest commit

 

History

78 Commits

Folders and files

Repository files navigation

DSA27 — Data Structures & Algorithms

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.


Course material

Course documentation Start here — guide, plan, lectures, regulations
Course guide What the course is, how you are assessed, what fails you
Study plan — 15 weeks Every week, and the file that grades it
Coverage matrix Every topic the لائحة declares → module → test
Lecture 01 — Why This Course, and Why Python handout PDF · slides PDF · online quiz and written practice · timed test
Lecture 02 — Complexity, and the Array handout PDF · slides PDF · interactive demo · online quiz and written practice · timed test
Lecture 03 — Recursion handout PDF · slides PDF · interactive demo · online quiz and written practice · timed test
Lecture 04 — Dynamic Arrays handout PDF · slides PDF · interactive demo · online quiz and written practice · timed test
Lecture 05 — Linked Lists handout PDF · slides PDF · interactive demo · online quiz and written practice · timed test
Lecture 06 — Stacks handout PDF · slides PDF · interactive demo · online quiz and written practice · timed test
Lecture 07 — Queues handout PDF · slides PDF · interactive demo · online quiz and written practice · timed test
Lecture 08 — Searching handout PDF · slides PDF · online quiz and written practice
Lecture 09 — Basic Sorting handout PDF · slides PDF · online quiz and written practice
Lecture 10 — Advanced Sorting handout PDF · slides PDF · online quiz and written practice
Lecture 11 — Trees handout PDF · slides PDF · online quiz and written practice
Lecture 12 — Heaps and Priority Queues handout PDF · slides PDF · online quiz and written practice
Lecture 13 — Hash Tables handout PDF · slides PDF · online quiz and written practice
Lecture 14 — Graphs and Graph Searches handout PDF · slides PDF · online quiz and written practice
Lecture 15 — The Principles of Language Translation handout PDF · slides PDF · online quiz and written practice
The students' book All fifteen lectures and the question bank with its answers, in one PDF
Question bank MCQ, essay, trace, complexity, proofs, bugs and code — with answers, and four mock exams
Online quizzes The question bank as interactive quizzes, one page per week: multiple choice with every answer explained, and written questions you mark yourself against the marking points. In English and Arabic
Midterm exam simulator Timed papers drawn fresh from Lectures 1–7: full midterm · exam format · half paper · sprint · explain-level challenge · my weak spots · my mistakes · in Arabic. One lecture at a time: Lecture 1 · Lecture 2 · Lecture 3 · Lecture 4 · Lecture 5 · Lecture 6 · Lecture 7
Recorded lectures, 2019/2020 Earlier recordings of this course (Python, OOP, ADTs, arrays, sets, maps, complexity) to watch or download
Worked solutions Every exercise solved — for after you have tried. pytest --solutions runs the tests on them
Lab manual — weeks 1–15 (PDF) Python: Lab 01 · 02 · 03 — then building the structures: Lab 04 · 05 · 06 · 07 · 08 · 09 · 10 · 11 · 12 · 13 · 14 · 15 · TA notes
Official regulations The bylaws, and what they say about CS201
Links WhatsApp channel, YouTube

Announcements: WhatsApp channel · Video: youtube.com/@0xHGH · Quizzes: helghareeb.github.io/en/quizzes · Recordings: helghareeb.github.io/en/videos


Setup

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.txt

On 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 python opens the Microsoft Store instead of running, turn off the Store aliases under Settings → Apps → Advanced app settings → App execution aliases for python.exe and python3.exe.


Layout

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

How the exercises work

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 failure

They all fail on day one. That is the assignment.


Visualising your own code

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 tree

Step 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 itself

Measure 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"],
)

Notebooks

jupyter lab

Select 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 --install

Debugging your implementations

This 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/.

About

No description, website, or topics provided.

Resources

Stars

22 stars

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages