镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Pre course 1 submission - #2443

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

richapatil wants to merge 1 commit into
super30admin:masterfrom
richapatil:master

Conversation

@richapatil

Copy link
Copy Markdown

Pre course 1 submission

@super30admin

Copy link
Copy Markdown
Owner

The student has provided three separate Java implementations: a Stack using an array (Exercise_1.java), a Singly Linked List (LinkedList.java), and a Stack implemented using a Linked List (StackAsLinkedList.java). Each implementation appears to be functionally correct for the standard operations expected.

Strengths:

  1. Correctness: All three implementations correctly handle the core operations (push, pop, peek, isEmpty). Edge cases like stack overflow (in array-based stack) and stack underflow are handled with appropriate messages.
  2. Time Complexity: All operations in the array-based stack and linked-list-based stack are O(1). The linked list insertion is O(n) due to traversal to the end, which is correctly noted.
  3. Space Complexity: The array-based stack uses O(MAX) = O(1000) space, and the linked list implementations use O(n) space proportional to the number of elements.
  4. Code Quality: The code is reasonably well-structured with clear method names. Comments are present to indicate what each method should do. Time and space complexity are noted at the bottom of each file as requested.

Areas for Improvement:

  1. Code Organization: The student has included compiled .class files in the submission, which is unnecessary and clutters the solution. Only source files should be submitted.
  2. Linked List Insertion: The insert method in LinkedList.java traverses to the end of the list every time, making it O(n). For better efficiency, a tail pointer could be maintained to make insertion O(1).
  3. Magic Numbers: The MAX = 1000 is a magic number. While acceptable for this exercise, it could be made configurable or documented why this specific value was chosen.
  4. Error Handling: The pop and peek methods return 0 on underflow, which could mask errors. A better approach might be to throw an exception or use a sentinel value that's clearly documented.
  5. Missing Time/Space Complexity at Top: The problem statement mentions "Kindly include Time and Space complexity at top of each file", but the student has placed them at the bottom. This should be moved to the top.
  6. Dead Code/Comments: In LinkedList.java, there are leftover comments from the template that are now confusing (e.g., "then make the new node as head" appears after the head assignment is done).

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