Skip to content

Completed PreCourse-1 exercises in Python - #2429

Open
allurkarsneha wants to merge 1 commit into
super30admin:masterfrom
allurkarsneha:sneha-precourse-solutions
Open

Completed PreCourse-1 exercises in Python#2429
allurkarsneha wants to merge 1 commit into
super30admin:masterfrom
allurkarsneha:sneha-precourse-solutions

Conversation

@allurkarsneha

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Exercise_1.py (Array-based Stack):

  • Correctness: The implementation is correct with all core operations (isEmpty, push, pop, peek, size, show) working as expected.
  • Time Complexity: The stated complexities are accurate. Push is O(1) amortized due to Python list's dynamic array behavior.
  • Space Complexity: O(n) is correct.
  • Code Quality: Good, clean implementation. Minor improvement: could use elif instead of separate if/else blocks for consistency.

Exercise_2.py (Linked List-based Stack):

  • Correctness: The implementation is correct with proper head insertion for push and head removal for pop.
  • Time Complexity: O(1) for both operations is correct.
  • Space Complexity: O(n) is correct.
  • Code Quality: Good structure. The interactive menu is well-implemented. Consider adding type hints for better readability.

Exercise_3.py (Singly Linked List):

  • Correctness: The implementation is correct. All operations (append, find, remove) work properly, including edge cases like removing head, middle, and tail nodes.
  • Time Complexity: All stated O(n) complexities are accurate.
  • Space Complexity: O(n) for storage and O(1) for operations is correct.
  • Code Quality: Well-documented with clear docstrings. Good variable naming. The test cases are comprehensive and demonstrate proper handling of edge cases.

General Observations:

  • All three exercises demonstrate solid understanding of data structures (stack using array, stack using linked list, singly linked list).
  • Time and Space complexity analysis is included as requested.
  • Code is well-structured with clear separation of concerns.
  • Edge cases are handled appropriately (e.g., pop/peek on empty stack, remove from empty list).

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