Skip to content

precourse1#2420

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

precourse1#2420
akarshchandra wants to merge 1 commit into
super30admin:masterfrom
akarshchandra:master

Conversation

@akarshchandra
Copy link
Copy Markdown

precourse1

precourse1
@super30admin
Copy link
Copy Markdown
Owner

Exercise_1.py (List-based Stack):

  • Correctness: The implementation is correct. All stack operations (push, pop, peek, isEmpty, size, show) work as expected.
  • Time Complexity: All operations are O(1) as claimed. The comments incorrectly state O(n) for all operations, which is misleading.
  • Space Complexity: O(n) as expected for storing n elements.
  • Code Quality: Good structure with proper error handling for empty stack. Could improve by adding docstrings for better documentation.
  • Minor issue: The comments at the top incorrectly state "all O(1) show O(n)" which is contradictory and confusing.

Exercise_2.py (Linked List-based Stack):

  • Correctness: The implementation is mostly correct. The push operation correctly inserts at the head (O(1)). The pop operation works but has a minor issue - it prints "Stack Underflow" and returns 0, which could be confused with a valid value of 0. Should raise an exception or return None consistently.
  • Time Complexity: push is O(1), pop is O(1) - correct.
  • Space Complexity: O(n) - correct.
  • Code Quality: The code is functional but could benefit from better error handling (using exceptions instead of print statements). The variable naming "newHead" in pop is misleading since it's not creating a new head, just moving to the next node.

Exercise_3.py (Singly Linked List):

  • Correctness: The implementation is correct. All operations (append, find, remove) work as expected.
  • Time Complexity: append is O(n), find is O(n), remove is O(n) - all correctly documented.
  • Space Complexity: O(n) - correct.
  • Code Quality: Good implementation with clear docstrings. The find method has redundant checks (iterating while iter and checking data again). The remove method correctly handles edge cases (empty list, head removal).

General Observations:

  1. All three exercises demonstrate understanding of fundamental data structures.
  2. Error handling could be improved across all files - using exceptions consistently rather than print statements.
  3. The linked list implementation in Exercise_3 is more robust than Exercise_2.
  4. Consider 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.

3 participants