-
Notifications
You must be signed in to change notification settings - Fork 95
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
base: master
Are you sure you want to change the base?
Conversation
This pull request introduces 2 alerts when merging f18575e into 90396a3 - view on LGTM.com new alerts:
|
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.
Can you run a formatter on your code? https://prettier.io does a pretty good job (hehehe) at it.
} | ||
|
||
//Function to remove dupliicate nodes from the singlely linkedlist. | ||
removeDuplicates() { |
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.
what is the runtime/space complexity of this function?
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.
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).
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.
is there a way to make it faster?
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.
Maybe by using recursion it can be made faster
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.
what would the space/time complexity be with recursion?
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.
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.
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(); |
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 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(), '...');
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.
Sure I will make the changes soon
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.
that change has been merged now!
@@ -0,0 +1,71 @@ | |||
class Node { |
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 forgot to notice this before, but can you add your solution to a file called aditya9061.js
?
…list.