{"id":22688213,"url":"https://github.com/emanuelefavero/algorithms","last_synced_at":"2025-07-06T20:07:39.940Z","repository":{"id":69318007,"uuid":"581932611","full_name":"emanuelefavero/algorithms","owner":"emanuelefavero","description":"This repository contains implementations of various algorithms","archived":false,"fork":false,"pushed_at":"2025-06-25T18:28:09.000Z","size":320,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-25T19:29:35.753Z","etag":null,"topics":["algorithms","big-o-notation","binary-search","exercises","mergesort","time-complexity"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emanuelefavero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-12-24T23:24:28.000Z","updated_at":"2025-06-25T18:28:13.000Z","dependencies_parsed_at":"2023-11-07T12:31:25.349Z","dependency_job_id":"7e9c768c-79d1-4985-9c62-4f899da848e7","html_url":"https://github.com/emanuelefavero/algorithms","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/emanuelefavero/algorithms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Falgorithms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Falgorithms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Falgorithms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Falgorithms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emanuelefavero","download_url":"https://codeload.github.com/emanuelefavero/algorithms/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Falgorithms/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263966168,"owners_count":23536814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","big-o-notation","binary-search","exercises","mergesort","time-complexity"],"created_at":"2024-12-10T00:13:30.371Z","updated_at":"2025-07-06T20:07:39.903Z","avatar_url":"https://github.com/emanuelefavero.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Algorithms\n\nThis repository contains implementations of various algorithms\n\n## Go to algorithm detail page\n\nSearch algorithms:\n\n- [Binary Search](./BINARY-SEARCH.md)\n- [Linear Search](./LINEAR-SEARCH.md)\n\nSorting algorithms:\n\n- [Merge Sort](./MERGE-SORT.md)\n- [Bubble Sort](./BUBBLE-SORT.md)\n- [Selection Sort](./SELECTION-SORT.md)\n- [Insertion Sort](./INSERTION-SORT.md)\n- [Quick Sort](./QUICK-SORT.md)\n\n\u003e Note: Quick Sort is generally considered the best sorting algorithm for most cases unless the data is already sorted or almost sorted. In this case, Insertion Sort is a better choice\n\nMemoization and Dynamic Programming:\n\n- [Memoization and Dynamic Programming](./MEMOIZATION-AND-DYNAMIC-PROGRAMMING.md)\n\nBrain Teasers:\n\n- [Brain Teasers](./BRAIN-TEASERS.md)\n\n## What is an algorithm?\n\nAn algorithm is a set of instructions that solves a problem. Like a recipe, an algorithm is a set of steps that must be followed in order to solve a problem.\n\n## Big O Notation\n\n### Time Complexity\n\n**If there are N data elements, how many steps does the algorithm take to complete?**\n\n| Algorithm     | Best    | Average | Worst   |\n| ------------- | ------- | ------- | ------- |\n| Bubble        | n       | n^2     | n^2     |\n| Insertion     | n       | n^2     | n^2     |\n| Selection     | n^2     | n^2     | n^2     |\n| Merge         | n log n | n log n | n log n |\n| Quick         | n log n | n log n | n^2     |\n| Heap          | n log n | n log n | n log n |\n| ------------- | ----    | ------- | -----   |\n| Binary Search | 1       | log n   | log n   |\n| Linear Search | 1       | n       | n       |\n\n\u003e Note: Big O notation is used to describe the time complexity of an algorithm. The notation is used to describe the worst case scenario. For example, the time complexity of the `Bubble` algorithm is `O(n^2)`. This means that the algorithm will take `n^2` (n squared) operations to complete. `n^2` means that the algorithm will take `n` operations for each of `n` elements. For example, if there are 10 elements, the algorithm will take 100 operations to complete.\n\n## Space Complexity\n\n**How much memory does an algorithm use?**\n\n| Algorithm | Worst |\n| --------- | ----- |\n| Bubble    | 1     |\n| Insertion | 1     |\n| Selection | 1     |\n| Merge     | n     |\n| Quick     | logn  |\n| Heap      | 1     |\n\n## Complexity Classes\n\n- **constant `O(1)`** - no matter how many elements, the algorithm will always take the same amount of steps\n- **logarithmic `O(log n)`** - each time the data is doubled, the number of steps only increases by one\n- **linear `O(n)`** - the number of steps is directly proportional to the number of elements\n- **quasilinear `O(n log n)`** - the steps grows linearly with the input size multiplied by the logarithm of the input size\n- **quadratic `O(n^2)`** - the number of steps is proportional to the square of the number of elements\n- **cubic `O(n^3)`** - the number of steps is proportional to the cube of the number of elements\n- **factorial `O(n!)`** - the number of steps is proportional to the factorial of the number of elements (e.g. `O(3!)` = `O(3 * 2 * 1)` = `O(6)`)\n\n## Logarithms\n\n- **logarithm** - the inverse of exponentiation\n\nExample: `log2(8) = 3` because _how many times do you have to multiply 2 by itself to get a result of 8? 3_\n\nOr: _How many times do we need to halve 8 until we end up with 1? 3_\n\n### O(log n) explained\n\n`O(log n)` is a shorthand for `O(log2 n)`\n\nIf we keep dividing the number of elements by 2, we will eventually end up with 1. This is exactly what happens with `binary search`.\n`O(log N)` means _the algorithm takes as many steps as it takes to keep halving the data elements until we remain with 1 element_\n\n\u003e O(log N) algorithm takes just one additional step each time the data is doubled\n\n---\n\n## Run Typescript files locally\n\n- Install `nodemon` and `ts-node` globally\n\n```bash\nnpm install -g nodemon ts-node\n```\n\n- Run the file\n\n```bash\nnodemon file-name.ts\n```\n\n## Big O\n\nVisit the [Big O Cheat-sheet](https://www.bigocheatsheet.com/) to quickly check the time and space complexity of common algorithms and data structures.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femanuelefavero%2Falgorithms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femanuelefavero%2Falgorithms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femanuelefavero%2Falgorithms/lists"}