The system is a multi-branch library management system that manages:
- Branch Management
- Book Inventory
- Member Management
- Borrow/Return Management
- Reporting
Constraints from assignment:
- No database
- No UI
- In-memory data structures only
- Must demonstrate algorithms + ADT usage
- Must include complexity analysis
The system will be implemented using Python 3.11+ with clean modular architecture.
+----------------------+
| LibrarySystem |
| (Main Controller) |
+----------+-----------+
|
-------------------------------------------
| | | | |
BranchManager BookManager MemberMgr BorrowMgr ReportMgr
| | | |
| | | |
Graph HashMap HashMap Queue
(branches) (books) (members) (requests)
We must also calculate shortest route between branches.
Best structure:
Graph (Adjacency List)
Reason:
Libraries form a network of locations.
Example
Branch A --- Branch B
| |
Branch C --- Branch D
Adjacency list structure:
{
A: [B,C],
B: [A,D],
C: [A,D],
D: [B,C]
}
Why adjacency list?
| Reason | Explanation |
|---|---|
| Memory efficiency | O(V + E) |
| Faster traversal | BFS / DFS |
| Easy shortest path | BFS for unweighted graph |
Algorithm used:
Breadth First Search (BFS)
Time complexity:
O(V + E)
Books must support:
- add
- delete
- update
- search
- sort
- quantity tracking
Best structure:
Hash Map (Dictionary)
Example:
books = {
"9780131103627": BookObject
}
Why Hash Map?
| Reason | Complexity |
|---|---|
| search | O(1) |
| update | O(1) |
| delete | O(1) |
Books stored per branch:
branch_books = {
branch_id : { book_id : Book }
}
Members searched by:
- NRC_ID
- Passport
- Member ID
Structure:
Hash Map
Example:
members = {
member_id : MemberObject
}
Why?
Fast lookup when borrowing books.
Complexity:
Search = O(1)
Scenario:
Book quantity = 1
Member A requests
Member B requests
Structure:
Queue
Example
waitlist = deque()
Reason:
First come first serve.
Complexity
enqueue O(1)
dequeue O(1)
Structure:
Array List (Python List)
Why?
Sequential record storage.
Example
borrow_history = []
class Branch:
def __init__(self, branch_id, name, location):
self.branch_id = branch_id
self.name = name
self.location = location
self.inventory = {}class Book:
def __init__(self, book_id, title, author, year, quantity):
self.book_id = book_id
self.title = title
self.author = author
self.year = year
self.quantity = quantityclass Member:
def __init__(self, member_id, name, nrc, phone, address):
self.member_id = member_id
self.name = name
self.nrc = nrc
self.phone = phone
self.address = address
self.borrowed_books = []Use DFS or BFS
Example BFS search across branches.
Pseudo code:
function search_book(title):
queue = all_branches
while queue not empty:
branch = queue.pop()
if book exists in branch:
return branch
return NOT_FOUND
Complexity
O(V + E)
Use BFS
Pseudo code
function shortest_path(start, target):
queue = [(start, path)]
while queue not empty:
node, path = queue.pop()
if node == target:
return path
for neighbor in graph[node]:
add to queue
Complexity
O(V + E)
Algorithms required in assignment.
Use:
Insertion Sort
Quick Sort
Merge Sort
Good for small datasets.
Complexity:
| Case | Complexity |
|---|---|
| Best | O(n) |
| Average | O(n²) |
| Worst | O(n²) |
Pseudo code:
for i from 1 to n:
key = A[i]
j = i-1
while j >= 0 and A[j] > key:
shift A[j]
j--
insert key
Divide and conquer.
Average
O(n log n)
Worst
O(n²)
Stable sorting algorithm.
Complexity
O(n log n)
Space
O(n)
Pseudo code
function borrow(member_id, book_id):
member = find_member()
branch = find_book_branch()
if book.quantity == 0:
add to waitlist
return "added to queue"
decrease quantity
record borrow_date
due_date = today + 14 days
function return_book(member, book):
increase book quantity
remove from borrowed list
if waitlist not empty:
next_member gets book
Example rule
fine_per_day = 500 MMK
Algorithm
days_overdue = return_date - due_date
fine = days_overdue * daily_rate
Example
3 days overdue
fine = 3 * 500 = 1500 MMK
Examples:
raise BookNotFoundError
raise MemberNotFoundError
raise BookUnavailableError
raise DuplicateMemberError
Case
Book stock = 1
Member A borrows
Member B requests
System behavior
Member B added to queue
Queue structure
waitlist = [MemberB, MemberC]
Reports required:
for member in members:
show borrowed books
Complexity
O(n)
if today > due_date
sum(member.fines)
Used to measure algorithm performance when input size increases.
Three main notations:
Big O -> Worst case
Omega -> Best case
Theta -> Average case
Example
Searching in:
Array
O(n)
Hash table
O(1)
How fast algorithm runs.
Example
Merge Sort = O(n log n)
Memory usage.
Example
Merge Sort = O(n)
Example:
Hash table vs Array
| Structure | Advantage | Disadvantage |
|---|---|---|
| HashMap | fast search | more memory |
| Array | simple | slow search |
Tradeoff:
Speed vs Memory
Example ADT:
Stack
Queue
Graph
Benefits:
ADT can use different internal structures.
Example
Queue → Array or Linked List
Implementation can change without affecting system.
Same ADT usable in multiple systems.
Member Request
|
Check Book
|
Stock Available?
/ \
Yes No
| |
Borrow Add to Queue
|
Set Due Date
library_lms/
README.md
main.py
models/
book.py
member.py
branch.py
managers/
branch_manager.py
book_manager.py
member_manager.py
borrow_manager.py
report_manager.py
algorithms/
bfs_search.py
sorting.py
utils/
errors.py
fine_calculator.py
tests/
test_library.py
LibrarySystem
|
---------------------------------------
| | | |
BranchMgr BookMgr MemberMgr BorrowMgr
| |
Graph HashMap
|
BFS Shortest Path
Test cases:
| Case | Expected |
|---|---|
| borrow book available | success |
| borrow book no stock | queue |
| return book | stock increase |
| overdue book | fine calculated |
| search book | correct branch |
Show step by step:
- Add branches
- Add books
- Add members
- Borrow book
- Borrow same book again
- Show queue
- Return book
- Next member gets book
- Show overdue fine
If you want, I can also show you how to make this assignment look like a “distinction / world-class” submission by adding:
- system design diagrams
- proper algorithm flowcharts
- Big-O comparison tables
- clean Python implementation (~700 lines)
- professional README like a real GitHub project
That would make your assignment look far above normal HND level.