Skip to content

Conversation

@sristi-i
Copy link

No description provided.

@sristi-i sristi-i changed the title done precourse-1 completed precourse-1 Nov 11, 2025
@super30admin
Copy link
Owner

  1. Correctness:

    • Exercise_1.java: The stack implementation using an array appears correct, with proper handling of overflow and underflow conditions.
    • LinkedList.java: The linked list implementation correctly handles insertion at the end and printing. However, the isEmpty() check in printList could be more efficient by checking head == null instead of size == 0.
    • StackAsLinkedList.java: The stack implementation using linked list has a logical error in pop() where it doesn't handle the case when there's only one element in the stack (root == top). This would cause a NullPointerException.
  2. Time Complexity:

    • Exercise_1.java: Correctly stated as O(1) for all operations.
    • LinkedList.java: Correctly stated as O(1) for insert (though technically O(n) for insert at end) and O(n) for print.
    • StackAsLinkedList.java: Incorrectly stated as O(n) for pop - should be O(1) if implemented correctly with a singly linked list where we maintain a pointer to the top.
  3. Space Complexity:

    • All implementations correctly state O(n) space complexity.
  4. Code Quality:

    • Generally good structure and readability.
    • Some redundant comments could be removed (like empty method comments).
    • Inconsistent use of this keyword (used in some places but not others).
    • Missing JavaDoc comments for methods.
  5. Efficiency:

    • Exercise_1.java: Good implementation.
    • LinkedList.java: Could optimize isEmpty checks to use head == null instead of checking size.
    • StackAsLinkedList.java: The pop operation is inefficient (O(n)) due to traversal. Could be optimized to O(1) by making it a proper stack implementation where we push and pop from the head.

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