Skip to content

Conversation

@sree0018
Copy link

No description provided.

@sree0018
Copy link
Author

Having Some doubts Space Complexity In the Implementation Of Linked List.

@super30admin
Copy link
Owner

  1. Correctness:

    • Stack implementation (Exercise_1.java) correctly handles push, pop, peek operations with stack overflow/underflow checks.
    • LinkedList implementation correctly handles insertion and printing of nodes.
    • StackAsLinkedList implementation correctly handles stack operations using linked list nodes.
  2. Time Complexity:

    • Stack operations (push, pop, peek) are O(1) as claimed.
    • LinkedList insertion is O(n) as claimed since it traverses to the end.
    • StackAsLinkedList operations are O(1) as claimed.
  3. Space Complexity:

    • All implementations correctly claim O(1) space complexity for operations (except LinkedList insertion which uses O(n) space overall for n elements).
  4. Code Quality:

    • Good use of comments explaining time/space complexity.
    • Consistent indentation and formatting.
    • Could improve by:
      • Adding more comments explaining the logic in methods.
      • Using more descriptive variable names (e.g., 'a' in Stack could be 'stackArray').
      • Adding null checks in LinkedList printList method.
      • Making Node classes private where appropriate.
  5. Efficiency:

    • All implementations are efficient for their respective data structures.
    • One optimization could be to maintain a tail pointer in LinkedList to make insertions O(1).

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