Jump-start your best year yet: Become a member and get 25% off the first year Permutations/Combinations Algorithms Cheat Sheets Oleksii Trekhleb · Follow Published in ITNEXT · 3 min read · Jun 29, 2018 584 3 TL;DR This article briefly describes the difference between mathematical permutations and combinations, explains the main idea behind permutations and combinations algorithms and contains links to algorithms implementation in JavaScript. JavaScript code examples may be found in JavaScript Algorithms and Data Structures repository. Read more for further details. What are Combinations and Permutations Let’s say we have a collection or set of something (collection of numbers, letters, fruits, coins etc.) and we need to pick items from a collection to form another collection. For example imagine that you’re picking lottery numbers from the collection of available numbers ({0, 1, 2, 3, 4, 5, 6, 7, 8, 9} → {4, 5, 9}). Or you’re picking the fruits from collections of available fruits to make a fruit salad ({orange, apple, banana, grape} → {apple, banana}). Or you’re trying to guess the lock password and you’re choosing 3 numbers out of {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} set to guess the correct password ({1, 1, 2}, {1, 1, 3}, {1, 1, 4}, …). In all these cases you’re creating one collection out from the other one by following some rules. And these rules define whether your new collection is a permutation or a combination. If the order of the elements in your new collection matters then you’re dealing with permutations (for example in case of lock password the set of {1, 1, 2} is not the same as set of {2, 1, 1}). Otherwise if the order doesn’t matter then you’re making a combination (combination of fruits {apple, Open in app banana} to make a salad — it doesn’t matter if you’ll pick apple or banana Search first). Your new collection may or may not contain duplicates (or repetitions). For example in lock password you’re allowed to use duplicate numbers but when you’re dealing with collection of race winners ({Black, Smith, Brown}) you’re not allowed to make duplicates because it doesn’t make sense to have the same person to be on two winning positions. To illustrate all these differences I’ve created small cheat sheets to make it more easy to remember them. Permutations Concept Cheat Sheet Write Permutations concept cheat sheet Combinations Concept Cheat Sheet Combinations concept cheat sheet Permutations/Combinations Algorithms Cheat Sheet If you would want to implement permutation and combination algorithms you might find the following permutation/combination algorithms cheat sheet useful. Permutation/combination algorithms cheat sheet Combinations and Permutations in JavaScript If you want to see exact implementations of these algorithms in JavaScript you may find follow these links: Combinations in JavaScript Permutations in JavaScript I hope you’ll find these cheat sheets helpful and they will help you to write combinations/permutations algorithms smoothly. Happy coding! Oleksii Trekhleb (@Trekhleb) | Twitter The latest Tweets from Oleksii Trekhleb (@Trekhleb). Lead Software Engineer at @EPAMSYSTEMS. Creating full-stack… twitter.com Programming Algorithms JavaScript Data Science Web Development Written by Oleksii Trekhleb Follow 1.7K Followers · Writer for ITNEXT https://trekhleb.dev More from Oleksii Trekhleb and ITNEXT Oleksii Trekhleb in Towards Data Science Nicolas Fränkel in ITNEXT Binary representation of the floating-point numbers Five Apache projects you probably didn’t know about Have you ever wondered how computers store floating-point numbers like 3.1415 (𝝿) i… In early 2021, I started to work on the Apache APISIX project. I have to admit that I had… 5 min read · Jul 16, 2021 4 min read · Dec 21, 2023 130 2 680 5 Enea Jahollari in ITNEXT Oleksii Trekhleb in ITNEXT A change detection, zone.js, zoneless, local change detection,… Angular is a component-driven framework. And just like every other framework out ther… 18 min read · Dec 21, 2023 637 SOLID Principles Sketches Interactive sketches to illustrate SOLID programming principles with real-world… 3 min read · Oct 4, 2022 10 See all from Oleksii Trekhleb 1.6K 9 See all from ITNEXT Recommended from Medium Yakup Cengiz Ting Comparing std::map and std::unordered_map in C++ When developing applications in C++, choosing the right container to store key-… 8 min read · Jul 28, 2023 3 Graph in DSA Graphs, versatile data structures in the realm of Data Structures and Algorithms (DSA),… 3 min read · Aug 27, 2023 50 Lists General Coding Knowledge Coding & Development 20 stories · 778 saves 11 stories · 372 saves Predictive Modeling w/ Python Stories to Help You Grow as a Software Developer 20 stories · 773 saves 19 stories · 699 saves Shuai Li Rohit Verma Understand Dynamic Programming by Reinvent It Decoding Google’s coding interview A Comprehensive Guide to DP with detailed examples and diagrams. Cracking the Code to Google Interviews · 14 min read · Aug 1, 2023 4 min read · Jan 1 64 265 Khuyen Tran in Towards Data Science Mohammad Shoaib Human-Learn: Rule-Based Learning as an Alternative to… Incorporate Domain Knowledge into Your Model with Rule-Based Learning · 7 min read · Jan 1, 2023 440 4 See more recommendations 6 A* algorithm in short for revision A* algorithm with psudocode and python implementation for revision 4 min read · Sep 20, 2023 1