Added a program to remove duplicates from an unsorted singlely liked …#46
Added a program to remove duplicates from an unsorted singlely liked …#46aditya9061 wants to merge 3 commits intotechqueria:masterfrom
Conversation
|
This pull request introduces 2 alerts when merging f18575e into 90396a3 - view on LGTM.com new alerts:
|
lhchavez
left a comment
There was a problem hiding this comment.
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.
what is the runtime/space complexity of this function?
There was a problem hiding this comment.
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.
is there a way to make it faster?
There was a problem hiding this comment.
Maybe by using recursion it can be made faster
There was a problem hiding this comment.
what would the space/time complexity be with recursion?
There was a problem hiding this comment.
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.
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.
Sure I will make the changes soon
There was a problem hiding this comment.
that change has been merged now!
| @@ -0,0 +1,71 @@ | |||
| class Node { | |||
There was a problem hiding this comment.
i forgot to notice this before, but can you add your solution to a file called aditya9061.js?
…list.