Skip to content

Conversation

@krishnavarun7
Copy link

Created stack using array, linked-list and created linked list

@super30admin
Copy link
Owner

  1. Correctness:

    • Exercise_1.py: The stack implementation using a list is correct and handles basic operations (push, pop, peek, size, show) properly. The isEmpty check before pop and peek is good practice.
    • Exercise_2.py: The stack implementation using a linked list is correct. It handles push and pop operations correctly, including edge cases like popping from an empty stack.
    • Exercise_3.py: The singly linked list implementation is correct for append, find, and remove operations. The remove method handles edge cases like removing the head node or a non-existent key.
  2. Time Complexity:

    • Exercise_1.py: All operations are O(1) except show() which is O(n) as it returns the entire stack.
    • Exercise_2.py: push and pop operations are O(1).
    • Exercise_3.py: append, find, and remove operations are O(n) as expected for a singly linked list.
  3. Space Complexity:

    • All implementations have O(n) space complexity where n is the number of elements, which is optimal for these data structures.
  4. Code Quality:

    • The code is generally well-structured and readable.
    • Some improvements could be made:
      • Add docstrings for all methods to explain their purpose and return values.
      • In Exercise_1.py, the show() method could be renamed to something more descriptive like get_stack().
      • In Exercise_3.py, the print_list method could be added to the docstring to explain its purpose.
      • Consider adding type hints for better code clarity.
  5. Efficiency:

    • The implementations are efficient for their respective data structures.
    • One potential optimization in Exercise_3.py is to maintain a tail pointer to make append operations O(1) instead of O(n).

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