Skip to content
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

Singly Linked List implementation using Javascript (Recursive-Approach) #1369

Closed
wants to merge 3 commits into from

Conversation

Suryac72
Copy link

@Suryac72 Suryac72 commented Sep 23, 2023

Open in Gitpod know more

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new JavaScript files are placed inside an existing directory.
  • All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames.
    Example:UserProfile.js is allowed but userprofile.js,Userprofile.js,user-Profile.js,userProfile.js are not
  • All new algorithms have a URL in their comments that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@Suryac72 Suryac72 changed the title Singly Linked List implementation using Javascript Singly Linked List implementation using Javascript (Recursive-Approach) Sep 23, 2023
Copy link
Collaborator

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the benefits of a "recursive approach" here. All loops can trivially be transformed into (tail) recursion, but here that seems to just lead to harder to read, likely less performant (function call overhead) and less memory efficient (due to stack usage, assuming now TCO) code with dirtier interfaces (exposure of "internal" parameters like currentNode; alternative would require cluttering the code even more) here.

I also don't see how this could be merged with our existing linked list in a decent way. Of course we could just add all these methods with a Recursive suffix, but that would be pretty messy. Having a second "recursive linked list" which implements the same "linked list" interface would be a proper solution, but again, for the aforementioned reasons I think this offers no advantages over the existing "iterative" implementation.

This also isn't in a mergeable state right now; it's lacking tests (should use the same tests as the existing linked list), the doc comments are messy, and many functions don't make much sense (for example: why is there both a size field and a lengthRecursive method which traverses the list to find the size?).

All in all, I'm in favor of closing this PR in its current state; the use of recursion here does not seem useful to me.

@raklaptudirm thoughts?

@appgurueu appgurueu added the on hold Being discussed by the maintainers label Sep 23, 2023
@raklaptudirm
Copy link
Member

I agree that adding trivial recursion adds nothing of value to the algorithm. Closing since we seem to have a consensus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold Being discussed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants