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

Added a program to remove duplicates from an unsorted singlely liked … #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

aditya9061
Copy link

…list.

@lgtm-com
Copy link

lgtm-com bot commented Oct 11, 2019

This pull request introduces 2 alerts when merging f18575e into 90396a3 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable
  • 1 for Deleting non-property

Copy link
Contributor

@lhchavez lhchavez left a comment

Choose a reason for hiding this comment

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

Can you run a formatter on your code? https://prettier.io does a pretty good job (hehehe) at it.

JavaScript/chapter02/2.1 - Remove Dups/solution.js Outdated Show resolved Hide resolved
JavaScript/chapter02/2.1 - Remove Dups/solution.js Outdated Show resolved Hide resolved
}

//Function to remove dupliicate nodes from the singlely linkedlist.
removeDuplicates() {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the runtime/space complexity of this function?

Copy link
Author

Choose a reason for hiding this comment

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

The time complexity for removeDuplicates function is O(n²) and space complexity is O(1).
And time complexity for printList is O(n) and space complexity is O(1).

Copy link
Contributor

Choose a reason for hiding this comment

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

is there a way to make it faster?

Copy link
Author

Choose a reason for hiding this comment

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

Maybe by using recursion it can be made faster

Copy link
Contributor

Choose a reason for hiding this comment

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

what would the space/time complexity be with recursion?

Copy link
Author

Choose a reason for hiding this comment

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

O(n)

Copy link
Contributor

Choose a reason for hiding this comment

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

can you expand on that? usually with recursive algorithms, analysis becomes complicated because of the fact that computation across method calls need to be accounted for.

}
}
//main function.
var list1 = new LinkedList();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm trying to make it easier to know if your code is correct, so I added support for mocha in #47

Can you change the code so that it follows the pattern found in https://github.com/techqueria/data-structures-and-algorithms/blob/aa70628efaf99a825115cea3c1008a4ef4276816/JavaScript/chapter01/1.1%20-%20Is%20Unique/solution.js ? you might need to change printList() in favor of toString() so that you can use assert.equal(list.toString(), '...');

Copy link
Author

Choose a reason for hiding this comment

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

Sure I will make the changes soon

Copy link
Contributor

Choose a reason for hiding this comment

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

that change has been merged now!

@@ -0,0 +1,71 @@
class Node {
Copy link
Contributor

Choose a reason for hiding this comment

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

i forgot to notice this before, but can you add your solution to a file called aditya9061.js?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants