-
Notifications
You must be signed in to change notification settings - Fork 0
Feedback #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feedback
Are you sure you want to change the base?
Feedback #1
Conversation
for (int i = 0; i < index; i++) { // O(n) | ||
item = item.next; // O(1) | ||
} | ||
return item.data; // O(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, great implementations of these operations, but consider an edge case we're not actively testing for: what happens if index
exceeds the bounds of the linked list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i fixed that with the commit
LinkedList reversedList = new LinkedList(); // O(1) | ||
LinkedList.Node item = list.head; // O(1) | ||
|
||
for (int i = 0; i < list.length(); i++) { // O(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While at first blush, this seemingly looks like an O(n)
implementation, what is the time complexity of list.length()
? In relation to this for loop's iterations, how often would length()
be calculated and what would the resulting complexity be? What do you think about improving our efficiency here for larger list lengths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed it so that length is set to variable before
item = item.next; // O(1) | ||
} | ||
return reversedList; // O(1) | ||
} // Algorithmic Complexity = O(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of prepend()
!
Bonus Credit: Curious to get your thoughts on if you see an implementation that allows you to reverse the list in place (i.e. consume no added memory), but perhaps manipulates the original list. The API is not precise enough to indicate what the semantic behaviour should strictly be, but you made the safe assumption given the a list is specified with a return value suggesting that this should not be a destructive operation. Though, as an exercise, do you want to give an in-place implementation a shot just within the Github comments here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done i think? I commited
|
||
assertEquals(2, list.head.data); | ||
assertEquals(3, list.head.next.data); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 🥇
I appreciate you adding more tests!
item = item.next; // O(1) | ||
} | ||
if (item.next.next == null) { // O(1) | ||
item.next = null; // O(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the item.next.next == null
condition; could you explain it to me? Is this intended to serve as a final statement for the case index == 0
and would this strictly be applicable in cases where the list is longer than three elements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want to remove the last thing on a linked list there is no item.next.next so you just set the last thing on the linked list to be null and so it becomes the tail. Otherwise if the index is in the middle area, then i will skip over one link and delete that one. That is my thought process Im not sure if it is right
…n its own list not make a new one
👋! GitHub Classroom created this pull request as a place for your teacher to leave feedback on your work. It will update automatically. Don’t close or merge this pull request, unless you’re instructed to do so by your teacher.
In this pull request, your teacher can leave comments and feedback on your code. Click the Subscribe button to be notified if that happens.
Click the Files changed or Commits tab to see all of the changes pushed to the default branch since the assignment started. Your teacher can see this too.
Notes for teachers
Use this PR to leave feedback. Here are some tips:
For more information about this pull request, read “Leaving assignment feedback in GitHub”.
Subscribed: @ryanknj5