Skip to content

PreCourse 1 complete#2423

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

PreCourse 1 complete#2423
vishalmgvk wants to merge 1 commit into
super30admin:masterfrom
vishalmgvk:master

Conversation

@vishalmgvk
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Exercise 1: myStack Class

Strengths:

  • Clean, simple implementation using Python's list
  • All basic stack operations (push, pop, peek, isEmpty, size) are correctly implemented
  • Good use of Python's built-in methods for O(1) operations

Issues:

  • Critical Bug: No bounds checking - pop() on an empty stack raises IndexError. Should return None or raise a custom exception.
  • Encapsulation Issue: show() returns the internal list directly, allowing external code to modify the stack's internal state.
  • Missing Documentation: No time/space complexity comments as requested in the problem description.

Exercise 2: Stack with Linked List

Strengths:

  • Correct use of linked list for stack implementation
  • Good O(1) push and pop operations
  • Interactive menu is well-structured

Critical Issues:

  • Design Flaw: Using Node(None) as a sentinel/dummy node is problematic. The check self.stack.data is None cannot distinguish between an empty stack and a stack with a legitimately pushed None value.
  • Bug: If None is pushed as a value, pop() will incorrectly return None and treat it as an empty stack.
  • Inconsistent Design: The dummy node approach is half-implemented and causes confusion.

Exercise 3: SinglyLinkedList

Strengths:

  • Correct implementation of append, find, and remove operations
  • Good handling of head node removal
  • Proper traversal logic

Issues:

  • Dead Code: self.node = ListNode() in __init__ creates a dummy node that is never used.
  • No Feedback: remove() silently does nothing if key is not found - should return boolean or raise exception.
  • Missing Methods: No __len__, __str__, or __repr__ for usability.
  • Inefficiency: No size tracking - len() would require O(n) traversal.

General Recommendations

  1. Add proper error handling for edge cases (empty stack, element not found)
  2. Remove unused code (dummy node in Exercise 3)
  3. Add docstrings with time/space complexity as requested
  4. Consider returning boolean values from remove() operations
  5. Use consistent sentinel node patterns if implementing them

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