Skip to content

Conversation

@jose-rafael-marcano
Copy link

xercise_1 : Implement Stack using Array.

Exercise_2 : Implement Stack using Linked List.

Exercise_3 : Implement Singly Linked List.

@super30admin
Copy link
Owner

  1. Correctness:

    • Exercise_1 (Stack using array): The implementation correctly handles push, pop, and peek operations. The isEmpty check is correct. However, the peek() method has a bug - it should return the element at top-1 since top points to the next available position.
    • Exercise_2 (Stack using linked list): The implementation is mostly correct, but the peek() method doesn't handle the empty stack case, which could lead to NullPointerException.
    • Exercise_3 (Linked List): The implementation is correct for insertion and printing operations.
  2. Time Complexity:

    • Exercise_1: All operations (push, pop, peek, isEmpty) are O(1).
    • Exercise_2: All operations are O(1) except for potential memory allocation time.
    • Exercise_3: Insertion is O(n) as it traverses to the end, printList is O(n).
  3. Space Complexity:

    • Exercise_1: O(n) where n is MAX (1000).
    • Exercise_2: O(n) where n is number of elements.
    • Exercise_3: O(n) where n is number of elements.
  4. Code Quality:

    • Generally good structure and readability.
    • Some improvements needed:
      • Missing comments about time/space complexity at the top of each file as requested.
      • In Exercise_1, the peek() method has a bug as mentioned.
      • In Exercise_2, peek() should handle empty stack case.
      • In Exercise_3, the insert method could be made non-static for better object-oriented design.
  5. Efficiency:

    • Exercise_1: Setting popped elements to Integer.MIN_VALUE is unnecessary.
    • Exercise_2: No major inefficiencies.
    • Exercise_3: Could maintain a tail pointer 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