javascript-algorithms icon indicating copy to clipboard operation
javascript-algorithms copied to clipboard

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

Results 281 javascript-algorithms issues
Sort by recently updated
recently updated
newest added

How can I use this lib with npm or yarn?

[{"_id":"62e71647fe17c97ed169c050","body":"@ahaoboy What did you want to import this lib for? The documentation states clearly:\r\n\r\n> Note that this project is meant to be used for learning and researching purposes only and it is not meant to be used for production.\r\n\r\nSo I don't think there is a point in making this package importable\/requirable since it's not supposed to be used as a project dependency. Just clone the repository and have some fun :) ","issue_id":1659297582501,"origin_id":714300102,"user_origin_id":28821170,"create_time":1603352643,"update_time":1603352643,"id":1659311687374,"updated_at":"2022-07-31T23:54:47.374000Z","created_at":"2022-07-31T23:54:47.374000Z"},{"_id":"62e71647fe17c97ed169c053","body":"> @ahaoboy What did you want to import this lib for? The documentation states clearly:\r\n> \r\n> > Note that this project is meant to be used for learning and researching purposes only and it is not meant to be used for production.\r\n> \r\n> So I don't think there is a point in making this package importable\/requirable since it's not supposed to be used as a project dependency. Just clone the repository and have some fun :)\r\n\r\nJust exactly what I wanted to say","issue_id":1659297582501,"origin_id":736885501,"user_origin_id":67328657,"create_time":1606865132,"update_time":1606865132,"id":1659311687378,"updated_at":"2022-07-31T23:54:47.377000Z","created_at":"2022-07-31T23:54:47.377000Z"},{"_id":"62e71647fe17c97ed169c056","body":"> npm \u94fe\u63a5 https:\/\/www.npmjs.com\/package\/javascript-algorithms-and-data-structures\r\n> \r\n> \u6211\u7528\u7eb1\u7ebf\u6dfb\u52a0\u8fd9\u4e2a\u5e93\r\n> \r\n> ```\r\n> yarn add javascript-algorithms-and-data-structures\r\n> ```\r\n> \r\n> \u4f46\u6211\u4e0d\u80fd\u4f7f\u7528\u5bfc\u5165\u6216\u9700\u8981\u8fd9\u4e2a\u5e93\r\n> \r\n> o(\u2565\ufe4f\u2565)o\r\n\r\nThis library may help you. https:\/\/github.com\/ZLY201\/js-sdsl","issue_id":1659297582501,"origin_id":1200371086,"user_origin_id":59038614,"create_time":1659254455,"update_time":1659254455,"id":1659311687381,"updated_at":"2022-07-31T23:54:47.381000Z","created_at":"2022-07-31T23:54:47.381000Z"}] comment

npm link https://www.npmjs.com/package/javascript-algorithms-and-data-structures I add this lib with yarn ``` yarn add javascript-algorithms-and-data-structures ``` But I can't use import or require this lib o(â•Ĩīšâ•Ĩ)o

Fix BUG in graph reverse method & Add needed tests

[{"_id":"659464cab15f7d23a50619ee","body":"Would you please check this PR? @trekhleb ","issue_id":1659297582505,"origin_id":1495460025,"user_origin_id":19665344,"create_time":1680592224,"update_time":1680592224,"id":1704223946945,"updated_at":"2024-01-02T19:32:26.945000Z","created_at":"2024-01-02T19:32:26.945000Z"}] comment

This PR fix the issue in #873. The issue was in the old reverse method, edges reversed one by one and this was making issue for graphs with cycle of...

[BUG] Strongly connected components function breaks when adding edges on opposite directions

[{"_id":"62e71647fe17c97ed169c058","body":"I think this error is for reverse function in graph. Because as written [here](https:\/\/github.com\/trekhleb\/javascript-algorithms\/blob\/master\/src\/data-structures\/graph\/Graph.js#L139), edges reverse one by one and for example if we have both AB and BA edges, on reversing AB, BA will be exist and cause error.\r\n\r\nI'm going to create a PR and fix this issue.","issue_id":1659297582508,"origin_id":1200131167,"user_origin_id":19665344,"create_time":1659176809,"update_time":1659176809,"id":1659311687673,"updated_at":"2022-07-31T23:54:47.673000Z","created_at":"2022-07-31T23:54:47.673000Z"},{"_id":"6370cc54a63f0c535f611012","body":"@trekhleb, Would you please take a look at this?","issue_id":1659297582508,"origin_id":1214286638,"user_origin_id":19665344,"create_time":1660453662,"update_time":1660453662,"id":1668336724836,"updated_at":"2022-11-13T10:52:04.836000Z","created_at":"2022-11-13T10:52:04.836000Z"}] comment

Computing strongly connected components fails when adding edges in opposite direction. Minimal example: ```js const vertexA = new GraphVertex('A'); const vertexB = new GraphVertex('B'); const vertexC = new GraphVertex('C'); const...

Implement new Data Structure: SkipList

[{"_id":"62e71647fe17c97ed169c05a","body":"Sure, I'm gonna take a crack at this!","issue_id":1659297582512,"origin_id":1045578763,"user_origin_id":84274405,"create_time":1645237454,"update_time":1645237454,"id":1659311687989,"updated_at":"2022-07-31T23:54:47.989000Z","created_at":"2022-07-31T23:54:47.989000Z"},{"_id":"62e71647fe17c97ed169c05d","body":"I want to take this i can fix \r\n","issue_id":1659297582512,"origin_id":1193314948,"user_origin_id":109905830,"create_time":1658668001,"update_time":1658668001,"id":1659311687994,"updated_at":"2022-07-31T23:54:47.993000Z","created_at":"2022-07-31T23:54:47.993000Z"},{"_id":"62e71647fe17c97ed169c05f","body":"i still want to do this eventually but I haven't had time yet, so i guess you can go for it","issue_id":1659297582512,"origin_id":1193351809,"user_origin_id":84274405,"create_time":1658680042,"update_time":1658680042,"id":1659311687997,"updated_at":"2022-07-31T23:54:47.996000Z","created_at":"2022-07-31T23:54:47.996000Z"},{"_id":"65945863b15f7d23a506174a","body":"class Node {\r\n constructor(value, level) {\r\n this.value = value;\r\n this.next = new Array(level + 1);\r\n this.prev = new Array(level + 1);\r\n }\r\n}\r\n\r\nclass SkipList {\r\n constructor() {\r\n this.head = new Node(-Infinity, 16);\r\n this.level = 0;\r\n }\r\n\r\n randomLevel() {\r\n let level = 0;\r\n while (Math.random() < 0.5 && level < 16) {\r\n level++;\r\n }\r\n return level;\r\n }\r\n\r\n insert(value) {\r\n let update = new Array(this.head.next.length);\r\n let node = this.head;\r\n\r\n for (let i = this.level; i >= 0; i--) {\r\n while (node.next[i] && node.next[i].value < value) {\r\n node = node.next[i];\r\n }\r\n update[i] = node;\r\n }\r\n\r\n let newLevel = this.randomLevel();\r\n if (newLevel > this.level) {\r\n for (let i = this.level + 1; i <= newLevel; i++) {\r\n update[i] = this.head;\r\n }\r\n this.level = newLevel;\r\n }\r\n\r\n let newNode = new Node(value, newLevel);\r\n for (let i = 0; i <= newLevel; i++) {\r\n newNode.next[i] = update[i].next[i];\r\n newNode.prev[i] = update[i];\r\n update[i].next[i] = newNode;\r\n }\r\n }\r\n\r\n delete(value) {\r\n let update = new Array(this.head.next.length);\r\n let node = this.head;\r\n\r\n for (let i = this.level; i >= 0; i--) {\r\n while (node.next[i] && node.next[i].value < value) {\r\n node = node.next[i];\r\n }\r\n update[i] = node;\r\n }\r\n\r\n node = node.next[0];\r\n if (node.value === value) {\r\n for (let i = 0; i <= this.level; i++) {\r\n if (update[i].next[i] !== node) {\r\n break;\r\n }\r\n update[i].next[i] = node.next[i];\r\n }\r\n while (this.level > 0 && this.head.next[this.level] === null) {\r\n this.level--;\r\n }\r\n }\r\n }\r\n\r\n find(value) {\r\n let node = this.head;\r\n\r\n for (let i = this.level; i >= 0; i--) {\r\n while (node.next[i] && node.next[i].value < value) {\r\n node = node.next[i];\r\n }\r\n }\r\n\r\n node = node.next[0];\r\n return node && node.value === value ? node.value : null;\r\n }\r\n}\r\n\r\nThis code provides the basic functionality for a skip list data structure, including the ability to insert, delete, and find values within the list.","issue_id":1659297582512,"origin_id":1427439990,"user_origin_id":113844348,"create_time":1676271485,"update_time":1676271485,"id":1704220771842,"updated_at":"2024-01-02T18:39:31.842000Z","created_at":"2024-01-02T18:39:31.842000Z"}] comment

https://en.wikipedia.org/wiki/Skip_list I learned about this data structure in my distributed systems class. Could we add it to the project?

Fixed bugs in pseudocode for deletion and reverse traversal.

while running program there is some glitches

[{"_id":"62e71648fe17c97ed169c060","body":"For example?","issue_id":1659297582532,"origin_id":1182123911,"user_origin_id":7661457,"create_time":1657648416,"update_time":1657648416,"id":1659311688289,"updated_at":"2022-07-31T23:54:48.288000Z","created_at":"2022-07-31T23:54:48.288000Z"}] comment

Wanna learn

[{"_id":"62e71648fe17c97ed169c062","body":"> Teach\r\n\r\nwhat do you want to learn?","issue_id":1659297582535,"origin_id":1159631859,"user_origin_id":74663874,"create_time":1655621515,"update_time":1655621515,"id":1659311688604,"updated_at":"2022-07-31T23:54:48.603000Z","created_at":"2022-07-31T23:54:48.603000Z"},{"_id":"62e71648fe17c97ed169c063","body":"Forming a sentence, for starters.","issue_id":1659297582535,"origin_id":1159678597,"user_origin_id":7661457,"create_time":1655633574,"update_time":1655633574,"id":1659311688606,"updated_at":"2022-07-31T23:54:48.606000Z","created_at":"2022-07-31T23:54:48.606000Z"},{"_id":"62e71648fe17c97ed169c064","body":"Javascript ","issue_id":1659297582535,"origin_id":1181425951,"user_origin_id":10137,"create_time":1657611645,"update_time":1657611645,"id":1659311688608,"updated_at":"2024-01-02T19:57:53.285000Z","created_at":"2022-07-31T23:54:48.608000Z"}] comment

Teach