Skip to content

adding pre-course solutions#2414

Open
nikhylw wants to merge 1 commit into
super30admin:masterfrom
nikhylw:master
Open

adding pre-course solutions#2414
nikhylw wants to merge 1 commit into
super30admin:masterfrom
nikhylw:master

Conversation

@nikhylw
Copy link
Copy Markdown

@nikhylw nikhylw commented May 11, 2026

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Exercise_1.py (List-based Stack)

  • Strengths: Clean, simple implementation using Python's built-in list. All core operations (isEmpty, push, pop, peek, size) are correctly implemented. Good use of docstrings for time/space complexity.
  • Issues: Minor - The show() method returns the internal list directly, which could allow external modification. Consider returning a copy for better encapsulation.
  • Correctness: ✓ Correct
  • Time Complexity: ✓ O(1) for all operations (amortized for push/pop)

Exercise_2.py (Linked List-based Stack)

  • Strengths: Proper linked list implementation with Node class. Clean interactive menu interface. Good handling of empty stack case in pop.
  • Issues: The pop operation returns None for empty stack but prints "Stack is empty." - this is handled correctly in the main loop, but the method itself doesn't distinguish between an empty stack and a valid None value being popped (if the stack allowed None values). Consider raising an exception instead for better error handling.
  • Correctness: ✓ Correct
  • Time Complexity: ✓ O(1) for both push and pop

Exercise_3.py (Singly Linked List)

  • Strengths: Well-structured with clear docstrings. Proper handling of edge cases (empty list, head removal). Good use of helper method show() for visualization.
  • Issues: The find() method returns the entire node object, which exposes internal implementation details. Consider returning just the data or a boolean indicating found/not found depending on requirements. The remove() method returns True/False but the caller doesn't check the return value in the example.
  • Correctness: ✓ Correct
  • Time Complexity: ✓ O(n) for all operations as documented

General Observations:

  • All three exercises demonstrate solid understanding of fundamental data structures
  • Code is well-commented with time/space complexity analysis
  • Good separation of concerns (data structure class vs. usage example)
  • Edge cases are generally handled appropriately
  • Could benefit from adding type hints for better code documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants