├── Algorithms Analysis ├── Asymptotic Analysis │ └── README.md ├── Cases │ └── README.md └── Time Complexity │ └── README.md ├── Algorithms Design 🌟 ├── Brute Force │ ├── Knapsack │ │ ├── Knapsack_bitmask.cpp │ │ └── README.md │ └── README.md ├── Divide & Conqure │ ├── Binary Search │ │ └── README.md │ ├── Divide String │ │ └── README.md │ ├── Element Equal Index │ │ └── README.md │ ├── Equivalent Strings │ │ └── README.md │ ├── Even Odd Sum │ │ └── README.md │ ├── Fast Power │ │ └── README.md │ ├── Guess The Number │ │ └── README.md │ ├── K Diff Pairs │ │ └── README.md │ ├── Kth Largest Element │ │ └── README.md │ ├── Kth Smallest Element │ │ └── README.md │ ├── Largest Element Position │ │ └── README.md │ ├── Max Difference │ │ └── README.md │ ├── Max Element │ │ └── README.md │ ├── Max Subarray Sum │ │ └── README.md │ ├── Min Max │ │ └── README.md │ ├── README.md │ ├── Sum Array │ │ └── README.md │ └── Unimodal Search │ │ └── README.md ├── Dynamic Programming │ ├── AtCoder Educational DP Contest │ │ ├── A - Frog 1 │ │ │ └── README.md │ │ ├── B - Frog 2 │ │ │ └── README.md │ │ ├── C - Vacation │ │ │ └── README.md │ │ ├── D - Knapsack 1 │ │ │ └── README.md │ │ ├── E - Knapsack 2 │ │ │ └── README.md │ │ ├── F - LCS │ │ │ └── README.md │ │ ├── L - Deque │ │ │ └── README.md │ │ └── README.md │ ├── Build Solution │ │ ├── Knapsack Items │ │ │ └── README.md │ │ ├── Minimum Path Sum │ │ │ └── README.md │ │ └── README.md │ ├── Fibonacci │ │ └── README.md │ ├── Problems │ │ ├── Combination Sum │ │ │ └── README.md │ │ ├── Game │ │ │ └── Optimal Strategy For A Game │ │ │ │ └── README.md │ │ ├── Knapsack Variations │ │ │ ├── 0 - 1 Knapsack │ │ │ │ ├── 0 - 1 Knapsack Problem │ │ │ │ │ └── README.md │ │ │ │ └── Simple Knapsack │ │ │ │ │ └── README.md │ │ │ ├── CP Knapsack │ │ │ │ ├── Cake Please │ │ │ │ │ └── README.md │ │ │ │ └── Half Knapsack │ │ │ │ │ └── README.md │ │ │ ├── Fractional Knapsack │ │ │ │ ├── Fractional Knapsack [Greedy] │ │ │ │ │ └── README.md │ │ │ │ └── README.md │ │ │ ├── README.md │ │ │ └── Unbounded Knapsack │ │ │ │ ├── Knapsack with Duplicate Items │ │ │ │ └── README.md │ │ │ │ └── README.md │ │ ├── Longest Common Subsequence [LCS] │ │ │ └── README.md │ │ ├── Longest Increasing Subsequence [LIS] │ │ │ └── README.md │ │ ├── Maximum profit from sale of juice │ │ │ └── README.md │ │ ├── Min #Elements Equal Sum │ │ │ └── README.md │ │ ├── Minimum Path Sum ✨ │ │ │ └── README.md │ │ ├── Princess Farida │ │ │ └── README.md │ │ ├── Shortest Path Visiting All Nodes │ │ │ └── README.md │ │ ├── Special Matrix │ │ │ └── README.md │ │ ├── Stairs │ │ │ ├── 1 2 3 Stairs │ │ │ │ └── README.md │ │ │ └── Count ways to N'th Stair (Order does not matter) │ │ │ │ └── README.md │ │ ├── Subset Sum Problem │ │ │ └── README.md │ │ ├── Subset Sum [FCIS] │ │ │ ├── README.md │ │ │ ├── Sum to Number.zip │ │ │ └── Sum to Number │ │ │ │ ├── Sum to Number.docx │ │ │ │ ├── Sum to Number.pdf │ │ │ │ └── [TEMPLATE] │ │ │ │ ├── .vs │ │ │ │ └── SumToNumber │ │ │ │ │ ├── FileContentIndex │ │ │ │ │ ├── ea83827b-c0c8-4a6f-a930-12fd15be6b8d.vsidx │ │ │ │ │ └── read.lock │ │ │ │ │ └── v17 │ │ │ │ │ └── .suo │ │ │ │ ├── SumToNumber.sln │ │ │ │ ├── SumToNumber.suo │ │ │ │ ├── SumToNumber.v11.suo │ │ │ │ └── SumToNumber │ │ │ │ ├── App.config │ │ │ │ ├── Helpers │ │ │ │ ├── HardniessLevel.cs │ │ │ │ ├── IProblem.cs │ │ │ │ └── ProblemBase.cs │ │ │ │ ├── Program.cs │ │ │ │ ├── Properties │ │ │ │ └── AssemblyInfo.cs │ │ │ │ ├── S2NProblem.cs │ │ │ │ ├── SumToNumber.cs │ │ │ │ ├── SumToNumber.csproj │ │ │ │ ├── bin │ │ │ │ └── Debug │ │ │ │ │ ├── SumToNumber.exe │ │ │ │ │ ├── SumToNumber.exe.config │ │ │ │ │ ├── SumToNumber.pdb │ │ │ │ │ ├── SumToNumber.vshost.exe │ │ │ │ │ ├── SumToNumber.vshost.exe.config │ │ │ │ │ ├── SumToNumber.vshost.exe.manifest │ │ │ │ │ ├── SumToNumber_Easy.txt │ │ │ │ │ └── SumToNumber_Hard.txt │ │ │ │ └── obj │ │ │ │ └── Debug │ │ │ │ ├── .NETFramework,Version=v4.8.AssemblyAttributes.cs │ │ │ │ ├── AliBabaAssembleTeam.csproj.FileListAbsolute.txt │ │ │ │ ├── AliBabaAssembleTeam.csprojResolveAssemblyReference.cache │ │ │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ │ │ │ ├── FindExtraElement.csproj.FileListAbsolute.txt │ │ │ │ ├── FindExtraElement.exe │ │ │ │ ├── FindExtraElement.pdb │ │ │ │ ├── IntegerMultiplication.csproj.FileListAbsolute.txt │ │ │ │ ├── IntegerMultiplication.csprojResolveAssemblyReference.cache │ │ │ │ ├── IntegerMultiplication.exe │ │ │ │ ├── IntegerMultiplication.pdb │ │ │ │ ├── MatrixMultiplication.csproj.FileListAbsolute.txt │ │ │ │ ├── MatrixMultiplication.csprojResolveAssemblyReference.cache │ │ │ │ ├── MatrixMultiplication.exe │ │ │ │ ├── MatrixMultiplication.pdb │ │ │ │ ├── ModOfPower.csproj.FileListAbsolute.txt │ │ │ │ ├── ModOfPower.csprojResolveAssemblyReference.cache │ │ │ │ ├── ModOfPower.exe │ │ │ │ ├── ModOfPower.pdb │ │ │ │ ├── PresentBaskets.csproj.FileListAbsolute.txt │ │ │ │ ├── PresentBaskets.csprojResolveAssemblyReference.cache │ │ │ │ ├── PresentBaskets.exe │ │ │ │ ├── PresentBaskets.pdb │ │ │ │ ├── SchoolQuizII.csproj.FileListAbsolute.txt │ │ │ │ ├── SchoolQuizII.csprojResolveAssemblyReference.cache │ │ │ │ ├── SchoolQuizII.exe │ │ │ │ ├── SchoolQuizII.pdb │ │ │ │ ├── SchoolQuizIII.csproj.FileListAbsolute.txt │ │ │ │ ├── StatsOfChart.csproj.FileListAbsolute.txt │ │ │ │ ├── StatsOfChart.csprojResolveAssemblyReference.cache │ │ │ │ ├── StatsOfChart.exe │ │ │ │ ├── StatsOfChart.pdb │ │ │ │ ├── SumToNumber.csproj.AssemblyReference.cache │ │ │ │ ├── SumToNumber.csproj.FileListAbsolute.txt │ │ │ │ ├── SumToNumber.csprojResolveAssemblyReference.cache │ │ │ │ ├── SumToNumber.exe │ │ │ │ ├── SumToNumber.pdb │ │ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ │ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ │ │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs │ │ └── Unique Paths II │ │ │ └── README.md │ └── README.md ├── Graph │ ├── Problems │ │ ├── All Paths From Source to Target │ │ │ └── README.md │ │ ├── Check Connection Between 2 Nodes │ │ │ └── README.md │ │ ├── Check Graph Connectivity │ │ │ └── README.md │ │ ├── Connect The Graph │ │ │ └── README.md │ │ ├── Connected Component Number │ │ │ └── README.md │ │ ├── Find whether path exist │ │ │ └── README.md │ │ ├── Fire Again │ │ │ └── README.md │ │ ├── Ice Cave │ │ │ └── README.md │ │ ├── Minimum Number of Vertices to Reach All Nodes │ │ │ └── README.md │ │ ├── Party │ │ │ └── README.md │ │ ├── Round Trip II │ │ │ └── README.md │ │ ├── Rumor │ │ │ └── README.md │ │ ├── Shortest Path From Entry Node To All Nodes │ │ │ └── README.md │ │ └── Transform A To B │ │ │ └── README.md │ ├── README.md │ ├── Topics │ │ ├── A-Graph Representation │ │ │ └── README.md │ │ ├── B-Graph Traversal │ │ │ ├── BFS │ │ │ │ ├── Path & Level Of Each Node │ │ │ │ │ └── README.md │ │ │ │ └── README.md │ │ │ ├── DFS │ │ │ │ ├── Count Nodes │ │ │ │ │ └── README.md │ │ │ │ └── README.md │ │ │ ├── Directed & Unconnected Graph Traverse │ │ │ │ └── README.md │ │ │ ├── README.md │ │ │ ├── Traversing in a 2D Grid │ │ │ │ └── README.md │ │ │ └── Update Visited Array │ │ │ │ └── README.md │ │ ├── C-Traversing in a 2D Grid │ │ │ └── README.md │ │ ├── D-Graph Connectivity │ │ │ ├── README.md │ │ │ └── Strongly Connected Components │ │ │ │ └── README.md │ │ ├── E-Edge Classification │ │ │ └── README.md │ │ ├── F-Cycle Detection │ │ │ ├── Directed Graph Cycle Detection │ │ │ │ └── README.md │ │ │ ├── README.md │ │ │ └── Undirected Graph Cycle Detection │ │ │ │ └── README.md │ │ ├── G-Shortest Paths │ │ │ └── README.md │ │ └── H-Topoligical Sort [Dependencies] │ │ │ └── README.md │ └── acmASCIS Material │ │ ├── Graph Algorithms [acmASCIS].docx │ │ └── README.md ├── Greedy │ ├── Fractional Knapsack │ │ └── README.md │ ├── Maximum Subarray Sum │ │ └── README.md │ ├── README.md │ └── Scheduling Activities │ │ └── README.md └── README.md ├── Backtracking ├── 23 out of 5 │ └── README.md ├── 2D Grid │ ├── Basic Number of Paths │ │ └── README.md │ ├── Count Number of Valid Paths from A to B in Grid │ │ └── README.md │ ├── Describe All Valid Paths From A to B │ │ └── README.md │ └── Generate all Paths from A to B in Grid │ │ └── README.md ├── All Paths From Source to Target │ └── README.md ├── Apple Division │ └── README.md ├── CD │ └── README.md ├── Combination Sum │ └── README.md ├── Palindrome Partitioning │ └── README.md ├── Partition to K Equal Sum Subsets │ └── README.md ├── Permutations │ └── README.md ├── README.md ├── Subsets │ └── README.md ├── Target Sum │ └── README.md ├── Tavas and SaDDas │ ├── README.md │ └── Tavas and SaDDas.png └── Transforme A To B │ └── README.md ├── Bit Manipulation ├── README.md └── Subsets │ └── README.md ├── README.md ├── Recursion ├── Problems │ ├── All K Subarrays │ │ └── README.md │ ├── All K Substrings │ │ └── README.md │ ├── Generate Parentheses │ │ └── README.md │ ├── Knapsack │ │ └── README.md │ ├── Power Set │ │ └── README.md │ ├── Power Sum │ │ └── README.md │ ├── README.md │ └── binary strings │ │ └── README.md ├── README.md └── Recursion Components │ └── README.md ├── Sorting Algorithms ├── Bubble Sort │ └── README.md ├── Insertion Sort │ └── README.md ├── Merge Sort │ └── README.md ├── Quick Sort │ └── README.md ├── README.md ├── Selection Sort │ └── README.md ├── Sorting Wars │ └── README.md └── Sorting_Algorithms [ALL IN ONE] │ ├── .vs │ └── Sorting_Algorithms │ │ ├── FileContentIndex │ │ ├── 4048ebce-37cd-4845-a0c1-6720acfe5a5b.vsidx │ │ ├── 81f26b47-1e00-47d1-b4e1-7b5aa39c3d10.vsidx │ │ └── read.lock │ │ └── v17 │ │ ├── .suo │ │ ├── Browse.VC.db │ │ └── ipch │ │ └── AutoPCH │ │ ├── 2dc6f71f2d75eb9b │ │ └── SORTING_ALGORITHMS.ipch │ │ └── 32a4344b4eec7333 │ │ └── SORTING_ALGORITHMS.ipch │ ├── Sorting_Algorithms.sln │ ├── Sorting_Algorithms │ ├── Sorting_Algorithms.cpp │ ├── Sorting_Algorithms.vcxproj │ ├── Sorting_Algorithms.vcxproj.filters │ ├── Sorting_Algorithms.vcxproj.user │ └── x64 │ │ └── Debug │ │ ├── Sorting_.ec3f3595.tlog │ │ ├── CL.command.1.tlog │ │ ├── CL.read.1.tlog │ │ ├── CL.write.1.tlog │ │ ├── Sorting_Algorithms.lastbuildstate │ │ ├── link.command.1.tlog │ │ ├── link.read.1.tlog │ │ └── link.write.1.tlog │ │ ├── Sorting_Algorithms.exe.recipe │ │ ├── Sorting_Algorithms.ilk │ │ ├── Sorting_Algorithms.log │ │ ├── Sorting_Algorithms.obj │ │ ├── vc143.idb │ │ └── vc143.pdb │ └── x64 │ └── Debug │ ├── Sorting_Algorithms.exe │ └── Sorting_Algorithms.pdb └── z-Others └── FCIS Quizzes ├── Lec 1 └── README.md ├── Lec 2 └── README.md ├── Lec 3 └── README.md └── Lec 4 └── README.md /Algorithms Analysis/Asymptotic Analysis/README.md: -------------------------------------------------------------------------------- 1 | # Asymptotic Analysis 2 | - `Asymptotic Analysis: study the time complexity of algorithm at large input size` 3 | - Expressed by :
4 | 5 | ❱ Upper bound: O() [OVER ESTIMATE]
6 | ❱ Lower bound: Ω() [UNDER ESTIMATE]
7 | ❱ Exact bound: Θ()
8 | 9 | - We alwayes try to get the exact, but some times the calculation of exact may be impossible so we can use upper and lower bound 10 | 11 | # Terminologies 12 | - Best, Worst, Expected are `True Cases` for the Algorithm 13 | - To express any case, we must calculate the `Exact` Complexity, if i can't then calculate `Upper` and `Lower` Complexity 14 | - Expected, Worst, Best cases may be equal. Check this code 15 | ```cs 16 | for(int i = 0 ; i * i < n; i++) { sum += i; } 17 | ``` 18 | `Complexity is Θ(Sqrt(n)) for all cases` 19 | 20 | # Big O() formal definition 21 | - It is function F(n) that its upper bound is O(g(n)) `g(n) above f(n) graphically` when `g(n) >= f(n)` 22 | - May be g(n) be smaller than F(n) but when we multiply g(n) with constant `c` it became greater 23 | - These constraints are valid when `n >= n0` 24 | - `n0`, `c` are positive constants 25 | 26 | ![image](https://user-images.githubusercontent.com/99830416/221245227-d9315216-f9be-485f-97c6-7f743c5788be.png) 27 | 28 | # O(), Ω(), Θ() 29 | 30 | ## O() Upper bound 31 | #### `f(n) <= cg(n)` 32 | - Constant c 33 | - for all n >= n0 34 | 35 | ## Ω() Lower bound 36 | #### `f(n) >= cg(n)` for:
37 | - Constant c 38 | - for all n >= n0 39 | 40 | ## Θ() Exact 41 | #### `f(n) >= c1g(n)` `f(n) <= c2g(n)` 42 | #### `c1g(n) <= f(n) <= c2g(n)` 43 | - Constant c1 small, c2 big 44 | - for all n >= n0 45 | -------------------------------------------------------------------------------- /Algorithms Analysis/Cases/README.md: -------------------------------------------------------------------------------- 1 | # Cases 2 | 3 | ## Worst Case 4 | - situation (input size) leads the algorithm to perform as its worst time. 5 | 6 | ## Best Case 7 | - situation (input size) leads the algorithm to perform as its best time. 8 | 9 | ## Average (Expected) Case 10 | - the expected time of algorithm when it runs over random (unexpected input) 11 | - it can contain the best and worst case 12 | - hard to calculate 13 | 14 | ## Example 15 | `Linear search for item in array` 16 | - Best case : this item found at the index 0 O(1) 17 | - Worst case : this item found at the last index O(N) 18 | - Expected case : any index in the array O(N) 19 | -------------------------------------------------------------------------------- /Algorithms Analysis/Time Complexity/README.md: -------------------------------------------------------------------------------- 1 | # Time Analysis 2 | 3 | ## `1- Running Time T(N)` 4 | - Calculate the number of steps that the algorithm takes as a function in input size 5 | - Each operation in the code has a cost 6 | - Examples : 7 | 8 | ```cpp 9 | count = count + 1 // Cost1 = 2 10 | sum = sum + count // Cost2 = 2 11 | // Total Cost = 2 + 2 = 4 steps 12 | T(N) = 4 13 | ``` 14 | ```cpp 15 | i = 1; // cost = 1 16 | sum = 0; // cost = 1 17 | while(i <= n) // cost = n + 1 18 | { 19 | i = i + 1; // cost = 2n 20 | sum = sum + 1; // cost = 2n 21 | } 22 | // Total Cost = 1 + 1 + n + 1 + 2n + 2n = 5N + 3 steps 23 | T(N) = 5N + 3 24 | ``` 25 | - Relation between the time and input size is **Linear**. When input size increases the total number of operations increases 26 | 27 | ## `2- Order/Complexity O()` 28 | - **Max** factor in the running time without any constants 29 | - Examples 30 | 31 | ```cpp 32 | i = 1; // cost = 1 33 | sum = 0; // cost = 1 34 | while(i <= n) // cost = n + 1 35 | { 36 | i = i + 1; // cost = 2n 37 | sum = sum + 1; // cost = 2n 38 | } 39 | // Total Cost = 1 + 1 + n + 1 + 2n + 2n = (5N + 3) steps 40 | // T(N) = 5N + 3 41 | // O(N) 42 | ``` 43 | ``` 44 | T(N) = 10^8 -> O(1) 45 | T(N) = log(N^1000) -> O(log(N)) 46 | ``` 47 | 48 | ##### `Large input then Order notation O() is accurate But Small input then Running time T(n) is accurate` 49 | 50 | 51 | ## `3- How to calculate O()` 52 | `Alwayes assume worst` 53 | - Statements : O(1) 54 | - Function call : O(function excution) 55 | - If/Switch statements : O(if body) + O(cond.) 56 | - Loops : number of iterations * O(Body) 57 | - Examples : 58 | 59 | ```cpp 60 | for i = 1 to n : 61 | for j = i to n : 62 | return True 63 | return False 64 | ``` 65 | `estimate : O(N^2) but actually it takes less than this complexity, so its Over estimate` 66 | 67 | `accurate : sum from 1 to n-1 is N^2 / 2 - N/2 so the accurate complexity is also N^2` 68 | 69 | ## `4- Complexity classes` 70 | ![Screenshot 2023-02-13 204307](https://user-images.githubusercontent.com/99830416/218546450-6cf00c52-6e42-42a2-9082-9655e48f4cf0.png) 71 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Brute Force/Knapsack/Knapsack_bitmask.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define fastIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) 4 | #define el cout << "\n" 5 | //********************* 6 | int getBit(int n, int index) { 7 | return ((n >> index) & 1); 8 | } 9 | void you_can_do_it() { 10 | int n, w; 11 | cin >> n >> w; 12 | vector>v(n); // weight, value 13 | for (int i = 0; i < n; i++) { 14 | cin >> v[i].first >> v[i].second; 15 | } 16 | // bitmask from 0 to (2^n)-1 17 | int mx = 0; 18 | for (int i = 0; i < 1 << n; i++) { 19 | int curval = 0, curweight = 0; 20 | for (int j = 0; j < n; j++) { 21 | if (getBit(i, j)) { 22 | curweight += v[j].first; 23 | if (curweight <= w) curval += v[j].second; 24 | } 25 | } 26 | mx = max(mx, curval); 27 | } 28 | cout << mx; 29 | el; 30 | } 31 | //********************* 32 | int main() { 33 | //files(); 34 | fastIO; 35 | int t = 1; 36 | //cin >> t; 37 | for (int i = 1; i <= t; i++) { 38 | you_can_do_it(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Brute Force/Knapsack/README.md: -------------------------------------------------------------------------------- 1 | # [Knapsack](https://codeforces.com/group/gA8A93jony/contest/270592/problem/J) 2 | ![image](https://user-images.githubusercontent.com/99830416/222934773-aedbceee-f0ca-48a9-8eb2-711e736f28ce.png) 3 | 4 | ### `TAKE OR LEAVE` approache 5 | 6 | # Complexity 7 | ### `O(2^n)` 8 | 9 | # Solution [bitmask] 10 | ```cpp 11 | #include 12 | using namespace std; 13 | #define fastIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) 14 | #define el cout << "\n" 15 | //********************* 16 | int getBit(int n, int index) { 17 | return ((n >> index) & 1); 18 | } 19 | void you_can_do_it() { 20 | int n, w; 21 | cin >> n >> w; 22 | vector>v(n); // weight, value 23 | for (int i = 0; i < n; i++) { 24 | cin >> v[i].first >> v[i].second; 25 | } 26 | // bitmask from 0 to (2^n)-1 27 | int mx = 0; 28 | for (int i = 0; i < 1 << n; i++) { 29 | int curval = 0, curweight = 0; 30 | for (int j = 0; j < n; j++) { 31 | if (getBit(i, j)) { 32 | curweight += v[j].first; 33 | if (curweight <= w) curval += v[j].second; 34 | } 35 | } 36 | mx = max(mx, curval); 37 | } 38 | cout << mx; 39 | el; 40 | } 41 | //********************* 42 | int main() { 43 | //files(); 44 | fastIO; 45 | int t = 1; 46 | //cin >> t; 47 | for (int i = 1; i <= t; i++) { 48 | you_can_do_it(); 49 | } 50 | } 51 | ``` 52 | 53 | # Solution [recursive] 54 | 55 | ```cpp 56 | int n, w; 57 | vector>v; 58 | int mx = 0; 59 | void solve(int index, int curval, int remain_weight) { 60 | if (index == n) { if (remain_weight >= 0) mx = max(mx, curval); return; } 61 | if (remain_weight - v[index].first >= 0) 62 | solve(index + 1, curval + v[index].second, remain_weight-v[index].first); 63 | solve(index + 1, curval, remain_weight); 64 | } 65 | int main() { 66 | cin >> n >> w; 67 | for (int i = 0; i < n; i++) { 68 | int w, val; 69 | cin >> w >> val; 70 | v.push_back({ w, val }); 71 | } 72 | solve(0, 0, w); 73 | cout << mx ; 74 | } 75 | ``` 76 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Brute Force/README.md: -------------------------------------------------------------------------------- 1 | # Brute Force 2 | `Straightforward way to solve a problem, based on the definition of the problem itself; often involves checking all possibilities` 3 | 4 | - Easy to implement 5 | - Good for small inputs 6 | - `Inefficient for large input` 7 | 8 | # Examples 9 | - [Knapsack](https://codeforces.com/group/gA8A93jony/contest/270592/problem/J) 10 | - Maximum subarray sum 11 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Binary Search/README.md: -------------------------------------------------------------------------------- 1 | # Binary search 2 | ![R](https://user-images.githubusercontent.com/99830416/227246259-6e5115aa-a1ba-48c4-8e40-fdc86bd7b1ba.gif) 3 | # Algorithm 4 | **1- Divide step: Compare the value i search for with the middle, divide array into 2 subarryes, and go to the propper subarray**
5 | **2- Conqure: solve the sub-array with the same manner**
6 | **3- Combine: Trivial [no building cubes]**
7 | 8 | # Code 9 | ```cpp 10 | bool binarySearch(vectorv, int start, int end, int val) { 11 | if (start > end) { return false; } 12 | int mid = (start + end) / 2; 13 | if (v[mid] == val) { return true; } 14 | else if (v[mid] > val) { return binarySearch(v, start, mid - 1, val); } 15 | else if (v[mid] < val) { return binarySearch(v, mid + 1, end, val); } 16 | } 17 | int main() { 18 | int n, val; cin >> n >> val; 19 | vectorv(n); 20 | for (auto& it : v) { cin >> it; } 21 | if (binarySearch(v, 0, n - 1, val)) { cout << "Found"; } 22 | else { cout << "Not found"; } 23 | } 24 | ``` 25 | 26 | # Complexity 27 | - **T(n) = T(Divide & Combine) + T(Conquer)** 28 | - **T(n) = Θ(1) + T(n/2)** 29 | - **solve using `Master method` (Case #2) `Log(n)`** 30 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Divide String/README.md: -------------------------------------------------------------------------------- 1 | # Divide String 2 | Given string of length n (power of 2) devide string into 2 equal sub-string and print them then repeat until the size = 0 3 | 4 | ## Example 5 | ``` 6 | aabb 7 | / \ 8 | aa bb 9 | / \ / \ 10 | a a b b 11 | 12 | ``` 13 | - Output `a` `a` `aa` `b` `b` `bb` 14 | ## Code 15 | ```cpp 16 | void solve(string s, int start, int end){ 17 | if (start == end) { return; } 18 | int mid = (start + end) / 2; 19 | solve(s, start, mid); 20 | solve(s, mid + 1, end); 21 | cout << s.substr(start, mid - start + 1); el; 22 | cout << s.substr(mid + 1, end - mid); el; 23 | } 24 | int main() { 25 | string s; cin >> s; 26 | solve(s, 0, s.size() - 1); 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Element Equal Index/README.md: -------------------------------------------------------------------------------- 1 | # Element Equal Index 2 | 3 | ## Problem statement 4 | Suppose you are given an increasing sequence of n distinct integers in an array 5 | A[1..n]. Design an efficient algorithm to determine whether there exists an index i 6 | such that A[i] = i. 7 | 8 | ## Test cases 9 | - n = 4
10 | 1 2 3 4
11 | out: YES
12 | 13 | - n = 3
14 | -1 0 3
15 | out: YES 16 | 17 | - n = 3
18 | 2 3 4
19 | out: NO 20 | 21 | ## Idea Of Algorithm 22 | 23 | The algorithm starts from the middle of the array A and check if we have found a match (i.e. A[mid] = mid). 24 | If not, we check to see if what we've got is greater or lesser than the required value. 25 | If it is greater (i.e. A[mid] > mid), then we can confidently ignore all the values greater than and including the midpoint. 26 | If it is smaller (i.e. A[mid] < mid), then we can ignore all the values smaller than and including the midpoint. 27 | This goes on until we either and a match or when the low point is greater than 28 | 29 | 30 | ## Code 31 | ```cpp 32 | bool solve(vectorv, int start, int end) { 33 | if (start > end) { return false; } 34 | int mid = (start + end) / 2; 35 | if (v[mid] == mid + 1) { return 1; } 36 | if (v[mid] > mid + 1) { return(v, start, mid - 1); } 37 | else { return(v, mid + 1, end); } 38 | } 39 | int main() { 40 | int n; cin >> n; 41 | vectorv(n); 42 | for (auto& it : v) { cin >> it; } 43 | cout << (solve(v, 0, n - 1) ? "YES" : "NO"); 44 | } 45 | ``` 46 | - `Divide` Check the middle against A[mid] 47 | - `Conquer` Solve the sub-array recursively 48 | - `Combine` Trivial `Limitation` 49 | ## Complexity 50 | - T(n) = T(n/2) + O(1) 51 | - Solve using Master `O(Log(n))` 52 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Equivalent Strings/README.md: -------------------------------------------------------------------------------- 1 | # [Equivalent Strings | Codeforces](https://codeforces.com/contest/559/problem/B) 2 | 3 | # Approach 4 | - Get the smallest Equivalent string for 2 strings if they are equal so they are `Equivalent` strings. 5 | - How to get the smallest Equivalent string for the current string?
6 | `1- Divide string to 2 equal size string (it can be done only if the string size is even)`
7 | `2- Conquer each sub-string in the same manner till the string size became odd`
8 | `3- Now we have 2 branches with odd size string how to combine?`
9 | `4- return min(a+b, b+a)`
10 | `That will return the smalles Equivalent string of my string` 11 | 12 | - 13 | 14 | # Code 15 | ```cpp 16 | string solve(string s) { 17 | if (s.size() & 1) { return s; } //base case 18 | string a = solve(s.substr(0, s.size() / 2)); 19 | string b = solve(s.substr(s.size() / 2)); 20 | return (min(a + b, b + a)); 21 | } 22 | int main() { 23 | string a, b; 24 | cin >> a >> b; 25 | solve(a) == solve(b) ? yes : no; 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Even Odd Sum/README.md: -------------------------------------------------------------------------------- 1 | # Even Odd Sum 2 | Given an array with a set of integer numbers, you have to determine if the sum of all the numbers is odd (return true) or even (return false) 3 | 4 | ## Approach 5 | - Even + Even -> return Even (False) 6 | - Odd + Odd -> return Even (False) 7 | - Even + Odd -> return Odd (True) 8 | 9 | 10 | ## Code 11 | ```cpp 12 | bool solve(vectorv, int start, int end) { 13 | if (start == end) { 14 | return v[start] % 2; 15 | } 16 | int mid = (start + end) / 2; 17 | bool br1 = solve(v, start, mid); 18 | bool br2 = solve(v, mid + 1, end); 19 | return (br1 != br2); 20 | } 21 | int main() { 22 | int n; cin >> n; 23 | vectorv(n); 24 | for (auto& it : v) { cin >> it; } 25 | cout << (solve(v, 0, n-1)? "Odd sum":"Even Sum"); 26 | } 27 | ``` 28 | `Why to solve D&C` to avoid overflow when sumup all elements 29 | 30 | ## Complexity 31 | - T(n) = 2T(n/2) + O(1) 32 | - Solve using Master `O(n)` 33 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Fast Power/README.md: -------------------------------------------------------------------------------- 1 | # Fast Power 2 | 3 | ## Problem statement 4 | Given a number n and base b, get n power b 5 | 6 | ## Brute-Force (Naïve) approach 7 | - Identify ans = 1, loop from 1 to b and multiply ans with n 8 | - Complexity: O(n) `Can we de better?` 9 | 10 | ## Divide & Conquer approach 11 | ### `Approach` 12 | 13 | - In case of even power: nb = nb/2 * nb/2 14 | - In case of odd power: nb = nb/2 * nb/2 * n 15 | - So we can try to solve only one of nb/2 and multiply the result by its self [even power] or its self * base [odd power] 16 | 17 | 18 | ### `Base case` 19 | - The power reach 1 so return n 20 | 21 | ### `Transition` 22 | - Get the answer of n power power/2 23 | 24 | ## Code 25 | ```cpp 26 | int fastPower(int n, int base) { 27 | if (base == 0) { return 1; } 28 | if (base == 1) { return n; } 29 | int val = fastPower(n, base / 2); 30 | if (!(base & 1)) { return val * val;} 31 | else { return val * val * n; } 32 | } 33 | int main() { 34 | int n, base; cin >> n >> base; 35 | cout << fastPower(n, base); 36 | } 37 | ```` 38 | - `Divide` Trivial (Divide N over 2). 39 | - `Conquer` Recursively solve 1 part only with N/2. 40 | - `Combine` Mul. the solution of sub-problem by its self (and by base in case of odd power) 41 | 42 | ## Complexity 43 | - T(N) = T(N/2) + O(1) 44 | - Solve using Master `O(Log(n))` 45 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Guess The Number/README.md: -------------------------------------------------------------------------------- 1 | # Guess The Number 2 | ### [Guess Number Higher or Lower | LeetCode](https://leetcode.com/problems/guess-number-higher-or-lower/) 3 | 4 | ## Problem Statement 5 | Your friend guesses an integer between A and B: You can ask questions like is the 6 | number less than 100? He will give YES NO answers. How many questions can your 7 | friend force you to ask, if you are a smart person? `If b2a 😆` 8 | 9 | 10 | ## Code 11 | ```cpp 12 | int solve(int start, int end, int val, int steps) { 13 | // it will not reach this case 14 | if (start > end) { return -1; } 15 | int mid = (start + end) / 2; 16 | if (mid == val) { return steps; } 17 | if (mid > val) { return solve(start, mid - 1, val, steps + 1); } 18 | else { return solve(mid+1, end, val, steps + 1); } 19 | } 20 | void do_it() { 21 | int a, b, secret_num; 22 | cin >> a >> b >> secret_num; 23 | cout << solve(a, b, secret_num, 1); 24 | } 25 | 26 | ``` 27 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/K Diff Pairs/README.md: -------------------------------------------------------------------------------- 1 | # K-diff Pairs in an Array 2 | 3 | ### [K-diff Pairs in an Array](https://leetcode.com/problems/k-diff-pairs-in-an-array/) 4 | 5 | ## Approach 6 | If we sort the array so we make sure that all values indices greater than the current index are greater than the value of the current value
7 | So we search for X such : `X - Arr[i] = K` `X = K + Arr[i]`. Now we can search for value X in the remaining array from index (i + 1) till end 8 | 9 | ## Code 10 | ```cpp 11 | int solve(vector& v, int start, int end, int val) { 12 | if (start > end) { return 0; } 13 | int mid = (start + end) / 2; 14 | if (v[mid] == val) { return 1; } 15 | else if (v[mid] > val) { return solve(v, start, mid - 1, val); } 16 | else if (v[mid] < val) { return solve(v, mid + 1, end, val); } 17 | } 18 | void do_it() { 19 | int n, k; cin >> n >> k; 20 | vectorv(n); 21 | for (auto& it : v) { cin >> it; } 22 | sort(v.begin(), v.end()); 23 | int cnt = 0; 24 | unordered_mapmp; 25 | for (int i = 0; i < n; i++) { 26 | if (!mp[v[i]]) cnt += solve(v, i + 1, n - 1, v[i] + k), mp[v[i]] = 1; 27 | } 28 | cout << cnt; 29 | } 30 | ``` 31 | - `Divide` Devide the arr into 2 sub-arrayes 32 | - `Conqure` Solve each sub in the same manner 33 | - `Combine` Trivial `Limitation approach` 34 | 35 | 36 | 37 | ## Complexity 38 | - `O(N.Log(N))` 39 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Kth Largest Element/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Divide & Conqure/Kth Largest Element/README.md -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Kth Smallest Element/README.md: -------------------------------------------------------------------------------- 1 | # [Kth Smallest Element | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/kth-smallest-element5635/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 2 | 3 | # Approach 4 | 5 | ### `Divide` 6 | **Select a **Pivot** and place it in its proper place (all array element that are smaller than it must be in its left and greter element must be in its right** 7 | 8 | ### `Conquer` 9 | **Compare the K with the pivot index** 10 | 11 | - If K < PivotIdx then recursively saarch in the left part for K index 12 | - Else if K > PivotIdx then recursively saarch in the right part for K - PivotIdx index 13 | 14 | 15 | ### `Combine` 16 | - Trivial. 17 | 18 | # Code 19 | ### `Partition` 20 | ```cpp 21 | int partition(vector&v, int start, int end) { 22 | int pivot = v[start]; 23 | int leftptr = start + 1, rightptr = end; 24 | while (true) { 25 | if (leftptr > rightptr) { break; } 26 | while (leftptr <= rightptr and v[leftptr] <= pivot) { leftptr++; } 27 | while (leftptr <= rightptr and v[rightptr] > pivot) { rightptr--; } 28 | if (leftptr <= rightptr) { swap(v[leftptr], v[rightptr]); } 29 | } 30 | int pivotIdx = rightptr; 31 | swap(v[start], v[rightptr]); 32 | return pivotIdx; 33 | } 34 | ``` 35 | ### `Find Kth smallest element` 36 | ```cpp 37 | int partition(vector&v, int start, int end) { 38 | int pivot = v[start]; 39 | int leftptr = start + 1, rightptr = end; 40 | while (true) { 41 | if (leftptr > rightptr) { break; } 42 | while (leftptr <= rightptr and v[leftptr] <= pivot) { leftptr++; } 43 | while (leftptr <= rightptr and v[rightptr] > pivot) { rightptr--; } 44 | if (leftptr <= rightptr) { swap(v[leftptr], v[rightptr]); } 45 | } 46 | int pivotIdx = rightptr; 47 | swap(v[start], v[rightptr]); 48 | return pivotIdx; 49 | } 50 | int SelectKthSmallest(vector&v, int start, int end, int k) { 51 | if (start == end) { return v[start]; } 52 | int q = partition(v, start, end); 53 | int PivotIndexInCurArr = q - start + 1; 54 | if (k == PivotIndexInCurArr) { return v[q]; } 55 | else if (k < PivotIndexInCurArr) { return SelectKthSmallest(v, start, q - 1, k); } 56 | else { return SelectKthSmallest(v, q + 1, end, k- PivotIndexInCurArr); } 57 | } 58 | ``` 59 | 60 | # Splitting and Complexity 61 | ### `General Complexity Form` 62 | - T(N) = T(L) or T(N - L) + O(N) 63 | 64 | ### `Best Splitting` 65 | - Divide array into 2 equal sub-arrays 66 | - T(N) = T(N/2) + O(n). Solve using Master `O(n)` 67 | 68 | ### `Worst Splitting` 69 | - When selecting Pivot and place it in its proper position it will be in the first or last index 70 | - So each time the array will be divided into n-1 elements 71 | - T(N) = T(N-1) + O(N). Solve using Master `O(n^2)` 72 | - *How to a void this case? Refere to Quick Sort algorithm* 73 | 74 | ### `In between` 75 | - T(N) = T(N/P) + O(n). Using Master `O(n)` 76 | 77 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Largest Element Position/README.md: -------------------------------------------------------------------------------- 1 | # Largest Element Position 2 | 3 | # Code 4 | ```cpp 5 | int maxPos(vectorv, int start, int end) { 6 | if (start == end) { return start; } 7 | int mid = (start + end) / 2; 8 | int left_max_pos = maxPos(v, start, mid); 9 | int right_max_pos = maxPos(v, mid + 1, end); 10 | return (v[left_max_pos] > v[right_max_pos]) ? left_max_pos : right_max_pos; 11 | } 12 | int main() { 13 | int n; cin >> n; 14 | vectorv(n); 15 | for (auto& it : v) { cin >> it; } 16 | cout << maxPos(v, 0, n - 1); 17 | } 18 | ``` 19 | 20 | # Complexity 21 | - T(n) = 2T(n/2) + O(1) 22 | - Solve using Master `O(n)` 23 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Max Difference/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Divide & Conqure/Max Difference/README.md -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Max Element/README.md: -------------------------------------------------------------------------------- 1 | # Max Element 2 | Get the max element in the array 3 | 4 | ## Code 5 | ```cpp 6 | int getMax(vectorv, int start, int end) { 7 | if (start == end) { return v[start]; } 8 | int mid = (start + end) / 2; 9 | int lef_max = getMax(v, start, mid); 10 | int right_max = getMax(v, mid + 1, end); 11 | return max(lef_max, right_max); 12 | } 13 | int main() { 14 | int n; cin >> n; 15 | vectorv(n); 16 | for (auto& it : v) { cin >> it; } 17 | cout << getMax(v, 0, n - 1); 18 | } 19 | ``` 20 | - `Divide` Divide the array into 2 halves (calc mid) 21 | - `Conquer` Solve each half in the same manner 22 | - `Conmbine` Return max of each branch 23 | 24 | ## Complexity 25 | - T(n) = 2.T(n/2) + O(1) 26 | - Solve using Master `O(n)` 27 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Max Subarray Sum/README.md: -------------------------------------------------------------------------------- 1 | # Max Sub array sum 2 | 3 | ## [Max Subarray Sum | LeetCode](https://leetcode.com/problems/maximum-subarray/description/) 4 | ## [Maximum Sub Array | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/maximum-sub-array5443/1) 5 | ## [Maximum Subarray Sum | Codeforces](https://codeforces.com/problemset/gymProblem/102961/H) 6 | # `Approach` 7 | ### `Divide` 8 | - Divide array into 2 subarrayes 9 | 10 | ### `Conquer` 11 | - Recursively calculate max. sequence sum in each half 12 | ### `Combine` 13 | - Find maximum subarray sum from left (Ml), right (Mr) & subarray across mid point (Mc) `How to find Mc`
14 | - How to find Mc? 15 | - Find max sum starting from mid point and ending at some point on left of mid
16 | - Find max sum starting from mid+1 & ending with some point on right of mid+1
17 | - Add the two sums together to form Mc
18 | 19 | # `Code` 20 | ```cpp 21 | struct Subarray { 22 | int start; 23 | int end; 24 | int maxSum; 25 | }; 26 | Subarray maxCrossSum(vector&v, int start, int end, int mid) { 27 | int leftSum = INT_MIN, rightSum = INT_MIN; 28 | int leftIndex = -1, rightIndex = -1; 29 | int sum = 0; 30 | for (int i = mid; i >= start; i--) { 31 | sum += v[i]; 32 | if (sum > leftSum) { 33 | leftSum = sum; 34 | leftIndex = i; 35 | } 36 | } 37 | sum = 0; 38 | for (int i = mid + 1; i <= end; i++) { 39 | sum += v[i]; 40 | if (sum > rightSum) { 41 | rightSum = sum; 42 | rightIndex = i; 43 | } 44 | } 45 | return { leftIndex, rightIndex, leftSum + rightSum }; 46 | } 47 | Subarray maxSubArrSum(vector&v, int start, int end) { 48 | if (start == end) { return { start, end, v[start] }; } 49 | int mid = (start + end) / 2; 50 | Subarray leftSub = maxSubArrSum(v, start, mid); 51 | Subarray rightSub = maxSubArrSum(v, mid + 1, end); 52 | Subarray crossSub = maxCrossSum(v, start, end, mid); 53 | if (leftSub.maxSum > rightSub.maxSum and leftSub.maxSum > crossSub.maxSum) { return leftSub; } 54 | else if (rightSub.maxSum > leftSub.maxSum and rightSub.maxSum > crossSub.maxSum) { return rightSub; } 55 | else { return crossSub; } 56 | } 57 | int main() { 58 | int n; cin >> n; 59 | vectorv(n); 60 | for (auto& it : v) { cin >> it; } 61 | Subarray sub = maxSubArrSum(v, 0, n - 1); 62 | cout << sub.start << " " << sub.end; el; 63 | cout << sub.maxSum; 64 | } 65 | ``` 66 | # Complexity 67 | - T(n) = 2.T(n/2) + O(n). Solve using Master `O(n.Log(n)` 68 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Min Max/README.md: -------------------------------------------------------------------------------- 1 | # Min Max 2 | # Problem statement 3 | Given arr with size n get its min and max alements 4 | 5 | ## Brute-Force (Naïve) approach 6 | - Sort the array and get the first and last element 7 | - Time complexity: O(N.Log(N)) `Can we do better?` 8 | 9 | ## Divide and conquer approach 10 | 11 | ### `Approach` 12 | - Get max, min of each branch 13 | ### `Base Case` 14 | - Current branch has 1 or 2 values 15 | ### `Transition` 16 | - Devide array into 2 sub-arrayes 17 | ## Code 18 | ```cpp 19 | pair getMaxMin(vectorv, int start, int end) { 20 | if (start == end) { return { v[start], v[start] }; } 21 | if (start + 1 == end) { return { max(v[start],v[end]), min(v[start],v[end]) }; } 22 | int mid = (start + end) / 2; 23 | pairleft = getMaxMin(v, start, mid); 24 | pairright = getMaxMin(v, mid + 1, end); 25 | return { max(left.first, right.first), min(left.second, right.second) }; 26 | } 27 | int main() { 28 | int n; cin >> n; 29 | vectorv(n); 30 | for (auto& it : v) { cin >> it; } 31 | pairsol = getMaxMin(v, 0, n - 1); 32 | cout << "mx: " << sol.first << "\nmn: " << sol.second; 33 | } 34 | ``` 35 | - `Divide` Divide problem into 2 sub-problems 36 | - `Conquer` Solve each sub-problem using the same manner 37 | - `Combine` Return min max of each branch 38 | 39 | ## Time Complexity 40 | - T(n) = 2.T(n/2) + c 41 | - Solve using Master `O(n)` 42 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/README.md: -------------------------------------------------------------------------------- 1 | # Divide and Conquer 2 | https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/b304847e-83ef-46bf-874e-7d472a126b76 3 | 4 | 5 | 6 | # Algorithm 7 | #### 1- Divide problem into small sub-problem(s) 8 | #### 2- Conqure [recursevly] the sub-problems by solving them in same manner till base case 9 | #### 3- Combine the solutions of sub-problems to get the solution of parent of them till get the base problem answer 10 | ### `It is recursve by nature [Conqure step] solve the same sub-problem using the same manner` 11 | ![image](https://user-images.githubusercontent.com/99830416/227218095-d36b2c70-35ab-4c01-9415-989296fe26fe.png) 12 | 13 | # Complexity 14 | - T(n) = Time of normal code + Time of recursive code 15 | - T(n) = T(Divide & Compine) + T(Conqure) 16 | 17 | # Limitaion VS Simplification 18 | - **`Limitiation`** ignore sub-problem as it doesn't have solution while solving the another part as it has the solution [no combine] 19 | - **`Simplification`** simplify your problem to sub-problems and combine the solution of each sub one to get the base answer [combine or update] `Building cubes` 20 | 21 | # Approach 22 | #### Think about one of those 2 approaches
23 | - Limit the problem `No combine. the solution is alone` e.g `Binary Search` 24 | - Simplify the problem `combine the answer of each sub-problem [Building cubes]` e.g `Fast Power` 25 | 26 | 27 | # How to think? 28 | - Ask: Why to divide and conqure? is it worth? is it will be efficent algo to solve my problem? 29 | - Ask: How to reach my answer? By `Limitation` or `Simplification` 30 | - Determine The Base case and Transition 31 | - **Take your time to think about the problem. Divide and conquer is not easy algorithm which need a lot of practice. Good Luck 🤜** 32 | 33 | # Small motivation 💪💀 34 | 35 | https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/51fa5b79-ceee-4c16-9c98-4f84797d574d 36 | 37 | https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/362a994a-4d1f-456a-bf47-01b5585389e3 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Sum Array/README.md: -------------------------------------------------------------------------------- 1 | # Sum array 2 | Sum all array elements using Divide and Conquer approach 3 | 4 | # Code 5 | ```cpp 6 | int solve(vectorv, int start, int end) { 7 | if (start == end) { return v[start]; } 8 | int mid = (start + end) / 2; 9 | int left_sum = solve(v, start, mid); 10 | int right_sum = solve(v, mid + 1, end); 11 | return left_sum + right_sum; 12 | } 13 | int main() { 14 | int n; cin >> n; 15 | vectorv(n); 16 | for (auto& it : v) { cin >> it; } 17 | cout << solve(v, 0, n - 1); 18 | } 19 | ``` 20 | - `Divide` Divide the array into 2 halves (calc mid) 21 | - `Conquer` Solve each half in the same manner 22 | - `Combine` Sum up the resuslt from left and right branch 23 | # Complexity 24 | - T(n) = 2.T(n/2) + O(1) 25 | - Solve using Master `O(n)` 26 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Divide & Conqure/Unimodal Search/README.md: -------------------------------------------------------------------------------- 1 | # Unimodal Search 2 | ## [Peak Index in a Mountain Array | LeetCode](https://leetcode.com/problems/peak-index-in-a-mountain-array/description/) 3 | ## [Find Peak Element | LeetCode](https://leetcode.com/problems/find-peak-element/description/) 4 | ## Problem Statement 5 | An array A of size n is unimodal if it consists of an increasing sequence, followed by a decreasing sequence
or more precisely, if there is an index m 6 | such 𝑨[𝒎 − 𝟏] < 𝑨[𝒎] > 𝑨[𝒎 + 𝟏] In particular, 𝑨[𝒎] is the maximum element, and it is the unique “locally maximum” element surrounded by smaller elements 7 | (𝑨[𝒎 − 𝟏] 𝒂𝒏𝒅 𝑨[𝒎 + 𝟏]). Your task is to determine that element 𝑨[𝒎] or its index m. 8 | 9 | ![Picture1](https://user-images.githubusercontent.com/99830416/227283504-421ecbb7-b744-41b0-9280-47f7e0decf77.png) 10 | 11 | ## Brute-Force (Naïve) approach 12 | - Iterate over array elements and check if the current element is greater than its Neighbours. 13 | - Time complexity Θ(N) `Can we do better?` 14 | 15 | ## Divide and Conquer approach 16 | ### `Approach` 17 | - If we have en element and it is greater than its prev and next, so this index is the answer, else that element is greater than its next, so i am in the right part, else if the current element is smaller than its next, so i am in the left part 18 | - Binary search methodology 19 | - Ignoring some part and search in another one 20 | - Problem Type: `Limitation` 21 | 22 | ### `Base case` 23 | - The current element is greater than its neighbours. 24 | 25 | ### `Transition` 26 | - if the current element is at the right part so the answer is at its left part so ignore the right part and go left. 27 | - if the current element is at the left part so the answer is at its right part so ignore the left part and go right. 28 | 29 | ## Code 30 | ```cpp 31 | int solve(vector&v, int start, int end) { 32 | if (start == end) { return start; } 33 | int mid = (start + end) / 2; 34 | if (v[mid] > v[mid + 1]) { return solve(v, start, mid); } 35 | else if (v[mid] < v[mid + 1]) { return solve(v, mid + 1 , end); } 36 | } 37 | int main() { 38 | int n; cin >> n; 39 | vectorv(n); // note: the array must be unimodal 40 | for (auto& it : v) { cin >> it; } 41 | cout << solve(v, 0, n - 1); 42 | } 43 | ``` 44 | - `Divide` Check middle element with its adjacent 45 | - `Conqure` Recursively Solve the 1 sub-array in the same manner 46 | - `Combine` Trivial 47 | 48 | ## Complexity 49 | - T(N) = Time(Divide & Combine) + Time(Conqure) 50 | - T(N) = O(1) + T(N/2) 51 | - Solve using master `O(Log(n))` 52 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/AtCoder Educational DP Contest/A - Frog 1/README.md: -------------------------------------------------------------------------------- 1 | # A - Frog 1 2 | [A - Frog 1 | AtCoder](https://atcoder.jp/contests/dp/tasks/dp_a) 3 | 4 | ## Approach 5 | - **We have 2 moves only** `i + 1` **and** `i + 2`. 6 | - **Base case → i reach `n - 1` last tower. So the cost will be 0** 7 | - **Statement → move to i + 1 and i + 2.** 8 | - **invalid path here returns big number as it is minimization problem. in case of maximization problem, the invalid path value will be -1** 9 | 10 | ## Solution 11 | ```cpp 12 | ll solve(int i, int n, vector& v, vector&dp) { 13 | // i make sure that this is only the base case as i move alwayes 1 move and move 2 under check 14 | if (i == n - 1) { return 0; } 15 | 16 | if (dp[i] != -1) { return dp[i]; } // check dp 17 | 18 | ll ans1 = abs(v[i] - v[i + 1]) + solve(i + 1, n, v,dp); 19 | 20 | // set answer big number as if i can't move 2 steps so this path will be unavailable 21 | ll ans2 = 1e5; 22 | if (i + 2 < n) { 23 | ans2 = abs(v[i] - v[i + 2]) + solve(i + 2, n, v,dp); 24 | } 25 | 26 | dp[i] = min(ans1, ans2); 27 | return dp[i]; 28 | } 29 | int main() { 30 | int n; cin >> n; 31 | vectorv(n), dp(n+5,-1); 32 | for (int i = 0; i < n; i++) { cin >> v[i]; } 33 | cout << solve(0, n, v, dp); 34 | } 35 | ``` 36 | 37 | ## Solution [more generic] 38 | ```cpp 39 | ll solve(int i, int n, vector& v, vector&dp) { 40 | if (i == n - 1) { return 0; } 41 | if (i >= n) { return 1e5; } 42 | 43 | if (dp[i] != -1) { return dp[i]; } // check dp 44 | 45 | ll ans1 = abs(v[i] - v[i + 1]) + solve(i + 1, n, v,dp); 46 | 47 | ll ans2 = abs(v[i] - v[i + 2]) + solve(i + 2, n, v, dp); 48 | 49 | dp[i] = min(ans1, ans2); 50 | return dp[i]; 51 | } 52 | void doIt() { 53 | int n; cin >> n; 54 | // store more memory in v. so that i can deal with +2 step 55 | vectorv(n + 2, 0), dp(n + 5, -1); 56 | for (int i = 0; i < n; i++) { cin >> v[i]; } 57 | cout << solve(0, n, v, dp); 58 | } 59 | ``` 60 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/AtCoder Educational DP Contest/B - Frog 2/README.md: -------------------------------------------------------------------------------- 1 | # B - Frog 2 2 | - [B - Frog 2 | AtCoder](https://atcoder.jp/contests/dp/tasks/dp_b) 3 | 4 | 5 | 6 | ## Solution 7 | ```cpp 8 | ll solve(int i, int n, vector& v, int k, vector& dp) { 9 | if (i == n - 1) { return 0; } 10 | if (i >= n) { return 1e5; } // indicate for impossible path. 11 | 12 | if (dp[i] != -1) { return dp[i]; } 13 | 14 | ll ans = 1e9; 15 | for (int j = 1; j <= k; j++) { 16 | ll ans1 = abs(v[i] - v[i + j]) + solve(i + j, n, v, k, dp); 17 | ans = min(ans, ans1); 18 | } 19 | 20 | dp[i] = ans; 21 | return dp[i]; 22 | } 23 | void doIt() { 24 | int n, k; cin >> n >> k; 25 | vectorv(n + k, 0), dp(n + 5, -1); 26 | for (int i = 0; i < n; i++) { cin >> v[i]; } 27 | cout << solve(0, n, v, k, dp); 28 | } 29 | ``` 30 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/AtCoder Educational DP Contest/C - Vacation/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/AtCoder Educational DP Contest/C - Vacation/README.md -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/AtCoder Educational DP Contest/D - Knapsack 1/README.md: -------------------------------------------------------------------------------- 1 | # D - Knapsack 1 2 | ### [D - Knapsack 1 | AtCoder](https://atcoder.jp/contests/dp/tasks/dp_d) 3 | 4 | ## Bruteforce Solution [TL] 5 | ```cpp 6 | ll knapsack(int i, int remain, vector>items) { 7 | if (i == items.size()) { return 0; } 8 | ll take = -1; 9 | if (remain - items[i].first >= 0) 10 | take = items[i].second + knapsack(i + 1, remain - items[i].first, items); 11 | 12 | ll leave = knapsack(i + 1, remain, items); 13 | 14 | ll mx = max(take, leave); 15 | return mx; 16 | } 17 | void doIt() { 18 | int n, maxW; 19 | cin >> n >> maxW; 20 | vector>items(n); 21 | for (int i = 0; i < n; i++) { 22 | cin >> items[i].first >> items[i].second; 23 | } 24 | cout << knapsack(0, maxW, items); 25 | } 26 | ``` 27 | 28 | ## dp Solution 29 | - Here we will use 2d dp that held the index and current free weight 30 | - Passing by reference is important to avoid TLE 31 | ```cpp 32 | ll knapsack(int i, int remain, vector>&items, vector>&dp) { 33 | if (i == items.size()) { return 0; } 34 | 35 | if (dp[i][remain] != -1) { return dp[i][remain]; } 36 | 37 | ll take = -1; 38 | if (remain - items[i].first >= 0) 39 | take = items[i].second + knapsack(i + 1, remain - items[i].first, items,dp); 40 | 41 | ll leave = knapsack(i + 1, remain, items, dp); 42 | 43 | dp[i][remain] = max(take, leave); 44 | return dp[i][remain]; 45 | } 46 | void doIt() { 47 | int n, maxW; 48 | cin >> n >> maxW; 49 | vector>items(n); 50 | vector>dp(n, vector(maxW + 1, -1)); 51 | for (int i = 0; i < n; i++) { 52 | cin >> items[i].first >> items[i].second; 53 | } 54 | cout << knapsack(0, maxW, items, dp); 55 | } 56 | ``` 57 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/AtCoder Educational DP Contest/E - Knapsack 2/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/AtCoder Educational DP Contest/E - Knapsack 2/README.md -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/AtCoder Educational DP Contest/F - LCS/README.md: -------------------------------------------------------------------------------- 1 | # F - LCS 2 | ### [F - LCS | Atcoder](https://atcoder.jp/contests/dp/tasks/dp_f) -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/AtCoder Educational DP Contest/L - Deque/README.md: -------------------------------------------------------------------------------- 1 | # L - Deque 2 | ### [L - Deque | Atcoder](https://atcoder.jp/contests/dp/tasks/dp_l?fbclid=IwAR3h1WM4pVw1jcJQswu_LF3e7ji9dvhHBcCittDlClUz-RzAUw1ywfSgeZI) 3 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/AtCoder Educational DP Contest/README.md: -------------------------------------------------------------------------------- 1 | # Educational DP Contest [AtCoder] 🐎 2 | ![image](https://user-images.githubusercontent.com/99830416/236648282-fa013ae0-e6a1-46bc-bf63-b18da01a9447.png) 3 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Build Solution/Knapsack Items/README.md: -------------------------------------------------------------------------------- 1 | # Knapsack Items 2 | ## [Knapsack Items | Codeforces](https://codeforces.com/gym/389971/problem/B) 3 | 4 | 5 | ## Solution 6 | ```cpp 7 | vectortakenItems; 8 | ll knapsack(int i, int remain, vector>& items, vector>& dp) { 9 | if (i == items.size()) { return 0; } 10 | 11 | if (dp[i][remain] != -1) { return dp[i][remain]; } 12 | 13 | ll take = -1; 14 | if (remain - items[i].first >= 0) 15 | take = items[i].second + knapsack(i + 1, remain - items[i].first, items, dp); 16 | 17 | ll leave = knapsack(i + 1, remain, items, dp); 18 | 19 | dp[i][remain] = max(take, leave); 20 | return dp[i][remain]; 21 | } 22 | void build(int i, int remain, vector>& items, vector>& dp) { 23 | if (i == items.size()) { return; } 24 | 25 | ll dpVal = dp[i][remain]; 26 | 27 | ll take = items[i].second + knapsack(i + 1, remain - items[i].first, items, dp); 28 | if (dpVal == take) { 29 | takenItems.push_back(i); 30 | build(i + 1, remain - items[i].first, items, dp); 31 | } 32 | else { 33 | //ll leave = knapsack(i + 1, remain, items, dp); 34 | build(i + 1, remain, items, dp); 35 | } 36 | } 37 | void doIt() { 38 | int n, maxW; 39 | cin >> n >> maxW; 40 | vector>items(n); 41 | vector>dp(n, vector(maxW + 1, -1)); 42 | for (int i = 0; i < n; i++) { 43 | cin >> items[i].first >> items[i].second; 44 | } 45 | cout << "Max Profit: " << knapsack(0, maxW, items, dp) << "\n"; 46 | build(0, maxW, items, dp); 47 | cout << "Taken items: \n"; 48 | for (auto it : takenItems) { 49 | cout << "item # " << it + 1 << " with Wieght: " << items[it].first << "\n"; 50 | } 51 | cout << "\n"; 52 | takenItems.clear(); 53 | } 54 | ``` 55 | ## Testcases 56 | ### Case 1 57 | ``` 58 | input: 59 | 3 8 60 | 3 30 61 | 4 50 62 | 5 60 63 | 64 | output: 65 | Max Profit: 90 66 | Taken items: 67 | item # 1 with Wieght: 3 68 | item # 3 with Wieght: 5 69 | ``` 70 | 71 | ### Case 2 72 | ``` 73 | input: 74 | 6 15 75 | 6 5 76 | 5 6 77 | 6 4 78 | 6 6 79 | 3 5 80 | 7 2 81 | 82 | output: 83 | Max Profit: 17 84 | Taken items: 85 | item # 2 with Wieght: 5 86 | item # 4 with Wieght: 6 87 | item # 5 with Wieght: 3 88 | ``` 89 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Build Solution/Minimum Path Sum/README.md: -------------------------------------------------------------------------------- 1 | # Minimum Path Sum 2 | ### [Minimum Path Sum | Leetcode](https://leetcode.com/problems/minimum-path-sum/) 3 | ![image](https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/60ea4e0b-2415-4141-a6d2-b905ce358dd6) 4 | 5 | ## Solution 6 | ```cpp 7 | int solve(int i, int j, vector>& v, vector>& dp) { 8 | int n = v.size(), m = v[0].size(); 9 | if (i == n - 1 and j == m - 1) { return dp[i][j] = v[i][j]; } 10 | 11 | if (dp[i][j] != -1) { return dp[i][j]; } 12 | 13 | int a = 1e8, b = 1e8; // indicates that i can't move to this path 14 | // move right 15 | if (j + 1 < m) { 16 | a = solve(i, j + 1, v, dp); 17 | } 18 | // move down 19 | if (i + 1 < n) { 20 | b = solve(i + 1, j, v, dp); 21 | } 22 | 23 | int bestPath = v[i][j] + min(a, b); 24 | dp[i][j] = bestPath; 25 | return bestPath; 26 | } 27 | void build(int i, int j, vector>& v, vector>& dp) { 28 | int n = v.size(), m = v[0].size(); 29 | if (i == n - 1 and j == m - 1) { 30 | cout << "(" << i << "," << j << ")"; 31 | return; 32 | } 33 | 34 | int dpVal = dp[i][j]; 35 | int a = 1e8, b = 1e8; // indicates that i can't move to this path 36 | // move right 37 | if (j + 1 < m) { 38 | a = solve(i, j + 1, v, dp); 39 | } 40 | // move down 41 | if (i + 1 < n) { 42 | b = solve(i + 1, j, v, dp); 43 | } 44 | 45 | int bestPath1 = v[i][j] + a; 46 | int bestPath2 = v[i][j] + b; 47 | 48 | if (dpVal == bestPath1) { 49 | cout << "(" << i << "," << j << ")"; 50 | build(i, j + 1, v, dp); 51 | } 52 | else { 53 | cout << "(" << i << "," << j << ")"; 54 | build(i + 1, j, v, dp); 55 | } 56 | } 57 | void doIt() { 58 | int n, m; 59 | cin >> n >> m; 60 | vector>v(n, vector(m)); 61 | for (int i = 0; i < n; i++) { 62 | for (int j = 0; j < m; j++) { 63 | cin >> v[i][j]; 64 | } 65 | } 66 | vector>dp(n, vector(m, -1)); 67 | cout << solve(0, 0, v, dp) << "\n"; 68 | build(0, 0, v, dp); 69 | } 70 | ``` 71 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Build Solution/README.md: -------------------------------------------------------------------------------- 1 | # Build Solution 2 | 3 | ## [Build Solution Sheet | Codeforces](https://codeforces.com/gym/389971) 4 | - *Sheet is under maintenance*
5 | - *Special thanks to **Omar Mamdouh [[ghandy](https://codeforces.com/profile/ghandy)]** who created this awesome sheet for practicing on building solution* 6 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Fibonacci/README.md: -------------------------------------------------------------------------------- 1 | # Fibonacci 2 | 3 | ## Recursive Solution 4 | 5 | ```cpp 6 | int fib(int n) { 7 | if (n <= 1) { return n; } 8 | return fib(n - 1) + fib(n - 2); 9 | } 10 | int main()) { 11 | int n; cin >> n; 12 | cout << fib(n); 13 | } 14 | ``` 15 | 16 | - **We have overlapped sub-problems** 17 | - **Time Complexity → O(2^n)** 18 | 19 | ## dp solution [Top-Down | Memoization] 20 | 21 | ```cpp 22 | vectordp(100, -1); 23 | int fib(int n) { 24 | if (n <= 1) { 25 | dp[n] = n; 26 | return dp[n]; 27 | } 28 | 29 | if (dp[n] != -1) { return dp[n]; } // retriving the answer 30 | 31 | dp[n] = fib(n - 1) + fib(n - 2); // saving the answer 32 | return dp[n]; 33 | } 34 | void doIt() { 35 | int n; cin >> n; 36 | cout << fib(n); 37 | } 38 | ``` 39 | 40 | - **Enhancement: We define extra storage** `dp` **that will save answer of each sub-problem.
Check if the sub-problem is solved or not. If not → solve it & store the answer. Else if it is solved → retrieve the answer.** 41 | - **Time Complexity → O(n)** 42 | 43 | ## dp solution [Bottom-Up | Tabulation] 44 | ```cpp 45 | int main() { 46 | vectorfib(100); 47 | fib[0] = fib[1] = 1; 48 | for (int i = 2; i < 100; i++) { fib[i] = fib[i - 1] + fib[i - 2]; } 49 | int n; cin >> n; 50 | cout << fib[n] << "\n"; 51 | } 52 | ``` 53 | **Can we enhance this solution? yup, use only the 2 previous variables and avoid using array** 54 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Combination Sum/README.md: -------------------------------------------------------------------------------- 1 | # Combination Sum 2 | ### [Combination Sum | Leetcode](https://leetcode.com/problems/combination-sum/) 3 | 4 | ## Solution [D&C] 5 | ```cpp 6 | vectorpath; 7 | vector>paths; 8 | void solve(int i, int cur, int target, vector& v) { 9 | if (i == v.size()) { return; } 10 | if (cur > target) { return; } 11 | if (cur == target) { 12 | paths.push_back(path); 13 | return; 14 | } 15 | path.push_back(v[i]); 16 | solve(i, cur + v[i], target, v); // keep i as i can take this element again 17 | path.pop_back(); 18 | 19 | solve(i + 1, cur, target, v); 20 | } 21 | vector> combinationSum(vector& candidates, int target) { 22 | solve(0,0,target, candidates); 23 | return paths; 24 | } 25 | ``` 26 | 27 | ## Solution [dp] 28 | ```cpp 29 | 30 | ``` 31 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Game/Optimal Strategy For A Game/README.md: -------------------------------------------------------------------------------- 1 | # Optimal Strategy For A Game 2 | ### [Optimal Strategy For A Game | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/optimal-strategy-for-a-game-1587115620/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/0 - 1 Knapsack/0 - 1 Knapsack Problem/README.md: -------------------------------------------------------------------------------- 1 | # 0 - 1 Knapsack Problem 2 | ### [0 - 1 Knapsack Problem | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/0-1-knapsack-problem0945/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 3 | 4 | ## dp Solution [recursive] 5 | ```cpp 6 | int knapsack(int i, int remain,int weight[], int value[],int n, vector>& dp) { 7 | if (i == n) { return 0; } 8 | 9 | if (dp[i][remain] != -1) { return dp[i][remain]; } 10 | 11 | int take = -1; 12 | if (remain - weight[i] >= 0) 13 | take = value[i] + knapsack(i + 1, remain - weight[i], weight, value, n, dp); 14 | 15 | int leave = knapsack(i + 1, remain, weight, value, n, dp); 16 | 17 | dp[i][remain] = max(take, leave); 18 | return dp[i][remain]; 19 | } 20 | int knapSack(int W, int wt[], int val[], int n) 21 | { 22 | vector>dp(n, vector(W + 1, -1)); 23 | int ans = knapsack(0, W, wt, val, n, dp); 24 | return ans; 25 | } 26 | ``` 27 | 28 | ## dp Solution [Iterative] 29 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/0 - 1 Knapsack/Simple Knapsack/README.md: -------------------------------------------------------------------------------- 1 | # Simple Knapsack 2 | ### [Simple Knapsack](https://codeforces.com/group/gA8A93jony/contest/270592/problem/J) 3 | 4 | ## Bruteforce Solution [recursive] 5 | ```cpp 6 | 7 | 8 | ``` 9 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/CP Knapsack/Cake Please/README.md: -------------------------------------------------------------------------------- 1 | # Cake Please 2 | ### [Cake Please | acmASCIS '23 Recruitment Contest](https://codeforces.com/group/7RRFVBbzR3/contest/404023/problem/B) 3 | 4 | ## Solution 5 | ```cpp 6 | 7 | ``` 8 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/CP Knapsack/Half Knapsack/README.md: -------------------------------------------------------------------------------- 1 | # Half Knapsack 2 | ### [Half Knapsack | Codeforces](https://codeforces.com/contest/1446/problem/A) 3 | 4 | ## Solution 5 | ```cpp 6 | 7 | 8 | ``` 9 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/Fractional Knapsack/Fractional Knapsack [Greedy]/README.md: -------------------------------------------------------------------------------- 1 | # Fractional Knapsack 2 | 3 | ## [Fractional Knapsack | Codeforces](https://codeforces.com/group/Z2G2riS3Yo/contest/428854/problem/C) 4 | *The problem is private in acmASCIS sheet on codeforces. It might not open with you* 5 | ## [Fractional Knapsack | Geeks For Geeks](https://practice.geeksforgeeks.org/problems/fractional-knapsack-1587115620/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 6 | ## Code 7 | ```cpp 8 | int main() { 9 | cout << fixed << setprecision(4); 10 | int n, k; 11 | cin >> n >> k; 12 | double ans = 0; 13 | vectorWeight(n), Cost(n); 14 | vector>gramCost; 15 | for (int i = 0; i < n; i++) { 16 | cin >> Weight[i]; 17 | } 18 | for (int i = 0; i < n; i++) { 19 | cin >> Cost[i]; 20 | } 21 | for (int i = 0; i < n; i++) { 22 | gramCost.push_back({ Cost[i] / Weight[i],Weight[i]}); 23 | } 24 | sort(all(gramCost)); 25 | reverse(all(gramCost)); 26 | for (int i = 0; i < n; i++) { 27 | if (gramCost[i].second <= k) { 28 | ans += (gramCost[i].first* gramCost[i].second); 29 | k -= gramCost[i].second; 30 | } 31 | else { 32 | ans += gramCost[i].first*k; 33 | break; 34 | } 35 | } 36 | cout << ans; 37 | } 38 | ``` 39 | ## Complexity 40 | - O(N.Log(N)) 41 | - `Can we make it better? Think of Kth element technique` 42 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/Fractional Knapsack/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/Fractional Knapsack/README.md -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/README.md: -------------------------------------------------------------------------------- 1 | # Knapsack Variations 2 | ![image](https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/8f9c362a-1520-4947-8b3b-6c9a5a0129cd) 3 | 4 | ## 💰 0 - 1 Knapsack 5 | - **Each item can be either included in the knapsack or not** 6 | - **We have at most one instance of each item in the knapsack** 7 | 8 | ## 💰 Bounded Knapsack 9 | - **Each item can be excluded or included in the knapsck from 1 up to n instances not ∞** 10 | 11 | ## 💰 Unbounded Knapsack 12 | - **Each item can be excluded or included in the knapsack any number of instancecs ∞** 13 | 14 | ## 💰 Fractional Knapsack 15 | - **We can take sub-item** 16 | - **If we take sub-item the value will be reduced also.** 17 | - **For example if we take 1/3 of the item wieght, the value also will be 1/3 of the original value** 18 | - **Solved using Greedy Algorithm** 19 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/Unbounded Knapsack/Knapsack with Duplicate Items/README.md: -------------------------------------------------------------------------------- 1 | # Knapsack with Duplicate Items 2 | ### [Knapsack with Duplicate Items | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/knapsack-with-duplicate-items4201/1) 3 | ### [The Knapsack problem | Codeforces](https://mirror.codeforces.com/gym/101064/problem/L) 4 | 5 | ## Solution 6 | ```cpp 7 | 8 | ``` 9 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/Unbounded Knapsack/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Knapsack Variations/Unbounded Knapsack/README.md -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Longest Common Subsequence [LCS]/README.md: -------------------------------------------------------------------------------- 1 | # Longest Common Subsequence [LCS] 2 | ### [Longest Common Subsequence [LCS] | Atcoder](https://atcoder.jp/contests/dp/tasks/dp_f) 3 | 4 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Longest Increasing Subsequence [LIS]/README.md: -------------------------------------------------------------------------------- 1 | # Longest Increasing Subsequence [LIS] 2 | ### [Longest Increasing Subsequence | Leetcode](https://leetcode.com/problems/longest-increasing-subsequence/) 3 | 4 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Maximum profit from sale of juice/README.md: -------------------------------------------------------------------------------- 1 | # Maximum profit from sale of juice 2 | ### [Maximum profit from sale of juice | GeeksForGeeks](https://www.geeksforgeeks.org/maximum-profit-sale-wines/) 3 | 4 | ## Backtracking Solution 5 | ```cpp 6 | int solve(int start, int end, int year, vector& v) { 7 | if (start == end) { return v[start] * year; } 8 | 9 | int left = (v[start] * year) + solve(start + 1, end, year + 1, v); 10 | int right = (v[end] * year) + solve(start, end - 1, year + 1, v); 11 | 12 | return max(left, right); 13 | } 14 | void doIt() { 15 | int n; cin >> n; 16 | vectorv(n); 17 | for (auto& it : v) { cin >> it; } 18 | cout << solve(0, n - 1, 1, v); 19 | } 20 | ``` 21 | ## dp Solution 22 | ```cpp 23 | int solve(int start, int end, int year, vector& v, vector>&dp) { 24 | if (start == end) { return dp[start][end] = v[start] * year; } 25 | 26 | if (dp[start][end] != -1) { return dp[start][end]; } 27 | 28 | int left = (v[start] * year) + solve(start + 1, end, year + 1, v, dp); 29 | int right = (v[end] * year) + solve(start, end - 1, year + 1, v, dp); 30 | 31 | dp[start][end] = max(left, right); 32 | return dp[start][end]; 33 | } 34 | void doIt() { 35 | int n; cin >> n; 36 | vectorv(n); 37 | vector>dp(n, vector(n, -1)); 38 | for (auto& it : v) { cin >> it; } 39 | cout << solve(0, n - 1, 1, v, dp); 40 | } 41 | ``` 42 | 43 | ## Materials 44 | ### [Maximum profit from sale of juice | Techdose](https://www.youtube.com/watch?v=f4jUEEzjEJw) 45 | 46 | ## Test case 47 | ![image](https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/5a19fd46-8bb6-40c5-9d79-09c3a9f4e5f6) 48 | 49 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Min #Elements Equal Sum/README.md: -------------------------------------------------------------------------------- 1 | # Min #Elements Equal Sum 2 | 3 | ### [Coin Change | Leetcode](https://leetcode.com/problems/coin-change/ "‌") **→ Unlimited Instances** 4 | 5 | ### [Number of Coins | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/number-of-coins1824/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article "‌") **→ 0-1** 6 | 7 | ## Solution 8 | 9 | ```cpp 10 | ‌ 11 | ``` 12 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Minimum Path Sum ✨/README.md: -------------------------------------------------------------------------------- 1 | # Minimum Path Sum ✨ 2 | ### [Minimum Path Sum | Leetcode](https://leetcode.com/problems/minimum-path-sum/) 3 | ![image](https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/60ea4e0b-2415-4141-a6d2-b905ce358dd6) 4 | 5 | 6 | 7 | ## Backtracking Solution 8 | 9 | ```cpp 10 | int solve(int i, int j, vector>&v) { 11 | int n = v.size(), m = v[0].size(); 12 | if (i == n - 1 and j == m - 1) { return v[i][j]; } 13 | 14 | int a = 1e9, b = 1e9; 15 | // move right 16 | if (j + 1 < m) { 17 | a = solve(i, j + 1, v); 18 | } 19 | // move down 20 | if (i + 1 < n) { 21 | b = solve(i + 1, j, v); 22 | } 23 | 24 | int bestPath = v[i][j] + min(a, b); 25 | return bestPath; 26 | } 27 | void doIt() { 28 | int n, m; 29 | cin >> n >> m; 30 | vector>v(n, vector(m)); 31 | for (int i = 0; i < n; i++) { 32 | for (int j = 0; j < m; j++) { 33 | cin >> v[i][j]; 34 | } 35 | } 36 | n = v.size(), m = v[0].size(); 37 | cout << solve(0, 0, v); 38 | } 39 | ``` 40 | 41 | ## dp Solution [Recursive] 42 | ```cpp 43 | int solve(int i, int j, vector>&v, vector>&dp) { 44 | int n = v.size(), m = v[0].size(); 45 | if (i == n - 1 and j == m - 1) { return dp[i][j] = v[i][j]; } 46 | 47 | if (dp[i][j] != -1) { return dp[i][j]; } 48 | 49 | int a = 1e8, b = 1e8; // indicates that i can't move to this path 50 | // move right 51 | if (j + 1 < m) { 52 | a = solve(i, j + 1, v, dp); 53 | } 54 | // move down 55 | if (i + 1 < n) { 56 | b = solve(i + 1, j, v, dp); 57 | } 58 | 59 | int bestPath = v[i][j] + min(a, b); 60 | dp[i][j] = bestPath; 61 | return bestPath; 62 | } 63 | void doIt() { 64 | int n, m; 65 | cin >> n >> m; 66 | vector>v(n, vector(m)); 67 | for (int i = 0; i < n; i++) { 68 | for (int j = 0; j < m; j++) { 69 | cin >> v[i][j]; 70 | } 71 | } 72 | vector>dp(n, vector(m, -1)); 73 | cout << solve(0, 0, v, dp); 74 | } 75 | ``` 76 | 77 | ## dp Solution [Iterative] 78 | ```cpp 79 | void doIt() { 80 | int n, m; 81 | cin >> n >> m; 82 | vector>v(n, vector(m)); 83 | for (int i = 0; i < n; i++) { 84 | for (int j = 0; j < m; j++) { 85 | cin >> v[i][j]; 86 | } 87 | } 88 | vector>dp(n, vector(m, 0)); 89 | dp[0][0] = v[0][0]; 90 | 91 | // fill 1st col 92 | for (int i = 1; i < n; i++) 93 | dp[i][0] = v[i][0] + dp[i - 1][0]; 94 | 95 | // fill 1st row 96 | for (int j = 1; j < m; j++) 97 | dp[0][j] = v[0][j] + dp[0][j - 1]; 98 | 99 | // fill the rest of dp 100 | for (int i = 1; i < n; i++) { 101 | for (int j = 1; j < m; j++) { 102 | dp[i][j] = v[i][j] + min(dp[i][j - 1], dp[i - 1][j]); 103 | } 104 | } 105 | 106 | cout << dp[n - 1][m - 1]; 107 | } 108 | ``` 109 | 110 | ### [Tutorial | Youtube](https://youtu.be/t1shZ8_s6jc) 111 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Princess Farida/README.md: -------------------------------------------------------------------------------- 1 | # Princess Farida 2 | ### [Princess Farida | SPOJ](https://www.spoj.com/problems/FARIDA/) 3 | 4 | ## Recursive solution 5 | ```cpp 6 | int n; 7 | int solve(int i, vector&v) { 8 | if (i >= n) { return 0; } 9 | 10 | int a = solve(i + 1, v); // leave the current monester 11 | int b = v[i] + solve(i + 2, v); // take the current monester and jump 2 steps 12 | 13 | return max(a, b); 14 | } 15 | int main { 16 | cin >> n; 17 | vectordp(1004, -1); 18 | vectorv(n); 19 | for (auto& it : v) { cin >> it; } 20 | ll ans = solve(0, v); 21 | cout << ans << "\n"; 22 | } 23 | ``` 24 | 25 | ## dp Recursive Solution 26 | ```cpp 27 | int n; 28 | ll solve(int i, vector&v, vector&dp) { 29 | if (i >= n) { return 0; } 30 | 31 | if (dp[i] != -1) { return dp[i]; } 32 | 33 | ll a = solve(i + 1, v, dp); // leave the current monester 34 | ll b = v[i] + solve(i + 2, v, dp); // take the current monester and jump 2 steps 35 | 36 | dp[i] = max(a, b); 37 | return dp[i]; 38 | } 39 | int main() { 40 | cin >> n; 41 | vectordp(1004, -1); 42 | vectorv(n); 43 | for (auto& it : v) { cin >> it; } 44 | ll ans = solve(0, v, dp); 45 | cout << ans << "\n"; 46 | } 47 | ``` 48 | 49 | ## dp Iterative Solution 50 | ```cpp 51 | int main() { 52 | int n; 53 | cin >> n; 54 | vectorv(n); 55 | for (auto& it : v) { cin >> it; } 56 | vectordp(n + 2); 57 | dp[n] = 0; 58 | for (int i = n - 1; ~i; i--) { 59 | ll a = dp[i + 1]; 60 | ll b = (i + 2 <= n ? v[i] + dp[i + 2] : v[i]); 61 | dp[i] = max(a, b); 62 | } 63 | ll ans = dp[0]; 64 | cout << ans << "\n"; 65 | } 66 | ``` 67 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Shortest Path Visiting All Nodes/README.md: -------------------------------------------------------------------------------- 1 | # Shortest Path Visiting All Nodes 2 | ## [Shortest Path Visiting All Nodes | Leetcode](https://leetcode.com/problems/shortest-path-visiting-all-nodes/) 3 | 4 | https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/561971e9-d9ed-4383-bba3-af4394ff4462 5 | 6 | ## Approach 7 | 8 | ## Solution 9 | ```cpp 10 | 11 | ``` 12 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Special Matrix/README.md: -------------------------------------------------------------------------------- 1 | # Special Matrix 2 | - [Special Matrix | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/special-matrix4201/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Stairs/1 2 3 Stairs/README.md: -------------------------------------------------------------------------------- 1 | # 1 2 3 Stairs 2 | ![image](https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/4eacf3e1-7989-4e0a-8be5-f8d00e5d7a28) 3 | 4 | ## Recursive Solution 5 | ```cpp 6 | int solve(int n) { 7 | if (n == 0) { return 1; } 8 | if (n < 0) { return 0; } 9 | 10 | int a = solve(n - 1); 11 | int b = solve(n - 2); 12 | int c = solve(n - 3); 13 | 14 | return a + b + c; 15 | } 16 | void doIt() { 17 | int n; 18 | cin >> n; 19 | cout << solve(n); 20 | } 21 | ``` 22 | ## dp Solution 23 | ```cpp 24 | int solve(int n, vector&dp) { 25 | if (n == 0) { return 1; } 26 | if (n < 0) { return 0; } 27 | 28 | if (dp[n] != -1) { return dp[n]; } 29 | 30 | int a = solve(n - 1, dp); 31 | int b = solve(n - 2, dp); 32 | int c = solve(n - 3, dp); 33 | 34 | dp[n] = a + b + c; 35 | return dp[n]; 36 | } 37 | void doIt() { 38 | int n; 39 | cin >> n; 40 | vectordp(n + 1, -1); 41 | cout << solve(n, dp); 42 | } 43 | ``` 44 | ## Iterative Solution 45 | ```cpp 46 | int main() { 47 | int n; 48 | cin >> n; 49 | vectorwayes(n + 1); 50 | wayes[0] = wayes[1] = 1; 51 | wayes[2] = 2; 52 | for (int i = 3; i <= n; i++) { wayes[i] = wayes[i - 1] + wayes[i - 2] + wayes[i - 3]; } 53 | cout << wayes[n]; 54 | } 55 | ``` 56 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Stairs/Count ways to N'th Stair (Order does not matter)/README.md: -------------------------------------------------------------------------------- 1 | # Count ways to N'th Stair (Order does not matter) 2 | ### [Count ways to N'th Stair (Order does not matter) | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/count-ways-to-nth-stairorder-does-not-matter5639/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 3 | 4 | ## Solution 5 | ```cpp 6 | 7 | 8 | ``` 9 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum Problem/README.md: -------------------------------------------------------------------------------- 1 | # Subset Sum Problem 2 | ### [Subset Sum Problem](https://practice.geeksforgeeks.org/problems/subset-sum-problem-1611555638/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 3 | 4 | ## Solution 5 | ```cpp 6 | bool ok = false; 7 | vectorpath; 8 | set>paths; 9 | void solve(int i, int cur, int target, vector& v, vector>&dp) { 10 | if (cur == target) { 11 | ok = true; 12 | paths.insert(path); 13 | return; 14 | } 15 | if (cur > target or i == v.size()) { 16 | return; 17 | } 18 | 19 | if (dp[i][cur]) { return; } 20 | 21 | if (cur + v[i] <= target) { 22 | path.push_back(v[i]); // save the path 23 | solve(i + 1, cur + v[i], target, v, dp); // take 24 | path.pop_back(); // backtrack 25 | } 26 | solve(i + 1, cur, target, v, dp); // leave 27 | 28 | dp[i][cur] = true; 29 | } 30 | void doIt() { 31 | int n, target; 32 | cin >> n >> target; 33 | vectorv(n); 34 | vector>dp(n, vector(target + 1, 0)); 35 | for (auto& it : v) { cin >> it; } 36 | solve(0, 0, target, v, dp); 37 | cout << (ok ? "Yes\n" : "No\n"); 38 | cout << "Paths are:\n"; 39 | for (auto it : paths) { 40 | for (int i = 0; i < it.size(); i++) { 41 | cout << it[i] << " "; 42 | } 43 | cout << "\n"; 44 | } 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/README.md -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number.zip -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/Sum to Number.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/Sum to Number.docx -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/Sum to Number.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/Sum to Number.pdf -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/.vs/SumToNumber/FileContentIndex/ea83827b-c0c8-4a6f-a930-12fd15be6b8d.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/.vs/SumToNumber/FileContentIndex/ea83827b-c0c8-4a6f-a930-12fd15be6b8d.vsidx -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/.vs/SumToNumber/FileContentIndex/read.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/.vs/SumToNumber/FileContentIndex/read.lock -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/.vs/SumToNumber/v17/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/.vs/SumToNumber/v17/.suo -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SumToNumber", "SumToNumber\SumToNumber.csproj", "{6A1119DE-3E7E-47F7-B32C-C8A9B28EA6CD}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {6A1119DE-3E7E-47F7-B32C-C8A9B28EA6CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {6A1119DE-3E7E-47F7-B32C-C8A9B28EA6CD}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {6A1119DE-3E7E-47F7-B32C-C8A9B28EA6CD}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {6A1119DE-3E7E-47F7-B32C-C8A9B28EA6CD}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber.suo -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber.v11.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber.v11.suo -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/Helpers/HardniessLevel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Helpers 8 | { 9 | public enum HardniessLevel 10 | { 11 | Both, 12 | Easy, 13 | Hard 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/Helpers/IProblem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Helpers 8 | { 9 | public interface IProblem 10 | { 11 | /// 12 | /// Try the core implementation on a given hard coded test case 13 | /// 14 | void TryMyCode(); 15 | 16 | /// 17 | /// Try the solution on a given hardniess level 18 | /// 19 | /// Hard, Easy or Both 20 | /// Max timeout interval per case (in ms) 21 | void Run(HardniessLevel level, int timeOutInMillisec); 22 | 23 | /// 24 | /// Generate a file of test cases according to the specified params 25 | /// 26 | /// Easy or Hard 27 | /// Required number of cases 28 | /// specify whether to include the expected time for each case in the file or not 29 | /// factor to be multiplied by the actual time 30 | void GenerateTestCases(HardniessLevel level, int numOfCases, bool includeTimeInFile = false, float timeFactor = 1); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/Program.cs: -------------------------------------------------------------------------------- 1 | using Helpers; 2 | using Problem; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Helpers 11 | { 12 | class Program 13 | { 14 | static int timeOutInMillisec = -1 ; //read the time of each case from the file 15 | static void Main(string[] args) 16 | { 17 | Console.Write("\nEnter your choice: [1] Trial Cases [2] Sample Test Cases [3] Complete Test Cases... [any key for exit] "); 18 | ConsoleKeyInfo cki = Console.ReadKey(); 19 | Console.WriteLine(); 20 | while (cki.Key == ConsoleKey.D1 || cki.Key == ConsoleKey.D2 || cki.Key == ConsoleKey.D3) 21 | { 22 | IProblem problem = null; 23 | 24 | int hardniessLevelSelection = cki.KeyChar - '0'; 25 | 26 | problem = new Problem.Problem(); 27 | 28 | //problem.GenerateTestCases(HardniessLevel.Easy, 5, true, 2f); 29 | //problem.GenerateTestCases(HardniessLevel.Hard, 10, true, 1.5f); 30 | 31 | ExcuteProblem(problem, hardniessLevelSelection, timeOutInMillisec); 32 | Console.WriteLine(); 33 | Console.Write("\nEnter your choice: [1] Trial Cases [2] Sample Test Cases [3] Complete Test Cases... [any key for exit] "); 34 | cki = Console.ReadKey(); 35 | Console.WriteLine(); 36 | } 37 | 38 | } 39 | 40 | 41 | private static void ExcuteProblem(IProblem problem, int hardniessLevelSelection, int timeOutInMillisec) 42 | { 43 | switch (hardniessLevelSelection) 44 | { 45 | case 1: 46 | problem.TryMyCode(); 47 | break; 48 | case 2: 49 | problem.Run(HardniessLevel.Easy, timeOutInMillisec); 50 | break; 51 | case 3: 52 | problem.Run(HardniessLevel.Hard, timeOutInMillisec); 53 | break; 54 | default: 55 | Console.WriteLine("Invalid Input"); 56 | break; 57 | } 58 | 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("FindExtraElement")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("FindExtraElement")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("02239b1a-6544-4900-a277-396bbacd0b25")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/SumToNumber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Problem 8 | { 9 | // ***************************************** 10 | // DON'T CHANGE CLASS OR FUNCTION NAME 11 | // YOU CAN ADD FUNCTIONS IF YOU NEED TO 12 | // ***************************************** 13 | public static class SumToNumber 14 | { 15 | #region YOUR CODE IS HERE 16 | #region FUNCTION#1: Calculate the Value 17 | //Your Code is Here: 18 | //================== 19 | // 20 | /// Fill this function to check whether there's a subsequence numbers in the given array that sum up to the given value 21 | /// 22 | /// array of integers 23 | /// array size 24 | /// value to check against it 25 | /// true if there's subsequence... false otherwise 26 | static public bool SolveValue(int[] items, int N, int B) 27 | { 28 | //REMOVE THIS LINE BEFORE START CODING 29 | throw new NotImplementedException(); 30 | } 31 | #endregion 32 | 33 | #region FUNCTION#2: Construct the Solution 34 | //Your Code is Here: 35 | //================== 36 | // 37 | /// Fill this function to check whether there's a subsequence numbers in the given array that sum up to the given value 38 | /// 39 | /// array of integers 40 | /// array size 41 | /// value to check against it 42 | /// if exists, return the numbers themselves whose sum equals to ‘B’ else, return null 43 | static public int[] ConstructSolution(int[] items, int N, int B) 44 | { 45 | //REMOVE THIS LINE BEFORE START CODING 46 | throw new NotImplementedException(); 47 | } 48 | #endregion 49 | 50 | #endregion 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/SumToNumber.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {6A1119DE-3E7E-47F7-B32C-C8A9B28EA6CD} 8 | Exe 9 | Properties 10 | SumToNumber 11 | SumToNumber 12 | v4.8 13 | 512 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 64 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber.exe -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber.pdb -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber.vshost.exe -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber.vshost.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber.vshost.exe.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber_Easy.txt: -------------------------------------------------------------------------------- 1 |  timeout:2# 2 | timeout:2  timeout:2 3 |  timeout:21 timeout:2 -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber_Hard.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/bin/Debug/SumToNumber_Hard.txt -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/.NETFramework,Version=v4.8.AssemblyAttributes.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using System.Reflection; 4 | [assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] 5 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/AliBabaAssembleTeam.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[U3] Ali Baba assembling a team\[TEMPLATE]\AliBabaAssembleTeam\bin\Debug\AliBabaAssembleTeam.exe.config 2 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[U3] Ali Baba assembling a team\[TEMPLATE]\AliBabaAssembleTeam\obj\Debug\AliBabaAssembleTeam.csprojResolveAssemblyReference.cache 3 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[U3] Ali Baba assembling a team\[TEMPLATE]\AliBabaAssembleTeam\bin\Debug\AliBabaAssembleTeam.exe 4 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[U3] Ali Baba assembling a team\[TEMPLATE]\AliBabaAssembleTeam\bin\Debug\AliBabaAssembleTeam.pdb 5 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[U3] Ali Baba assembling a team\[TEMPLATE]\AliBabaAssembleTeam\obj\Debug\AliBabaAssembleTeam.exe 6 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[U3] Ali Baba assembling a team\[TEMPLATE]\AliBabaAssembleTeam\obj\Debug\AliBabaAssembleTeam.pdb 7 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[R2] Statistical analysis of graph charts\[SOLUTION]\AliBabaAssembleTeam\bin\Debug\AliBabaAssembleTeam.exe.config 8 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[R2] Statistical analysis of graph charts\[SOLUTION]\AliBabaAssembleTeam\obj\Debug\AliBabaAssembleTeam.exe 9 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[R2] Statistical analysis of graph charts\[SOLUTION]\AliBabaAssembleTeam\obj\Debug\AliBabaAssembleTeam.pdb 10 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/AliBabaAssembleTeam.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/AliBabaAssembleTeam.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/FindExtraElement.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/FindExtraElement.exe -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/FindExtraElement.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/FindExtraElement.pdb -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/IntegerMultiplication.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P2] Integer Mult\[SOLUTION]\IntegerMultiplication\bin\Debug\IntegerMultiplication.exe.config 2 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P2] Integer Mult\[SOLUTION]\IntegerMultiplication\obj\Debug\IntegerMultiplication.csprojResolveAssemblyReference.cache 3 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P2] Integer Mult\[SOLUTION]\IntegerMultiplication\bin\Debug\IntegerMultiplication.exe 4 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P2] Integer Mult\[SOLUTION]\IntegerMultiplication\bin\Debug\IntegerMultiplication.pdb 5 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P2] Integer Mult\[SOLUTION]\IntegerMultiplication\obj\Debug\IntegerMultiplication.exe 6 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P2] Integer Mult\[SOLUTION]\IntegerMultiplication\obj\Debug\IntegerMultiplication.pdb 7 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R2] School Quiz II\[SOLUTION]\SchoolQuizII\bin\Debug\IntegerMultiplication.exe.config 8 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R2] School Quiz II\[SOLUTION]\SchoolQuizII\obj\Debug\IntegerMultiplication.exe 9 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R2] School Quiz II\[SOLUTION]\SchoolQuizII\obj\Debug\IntegerMultiplication.pdb 10 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/IntegerMultiplication.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/IntegerMultiplication.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/IntegerMultiplication.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/IntegerMultiplication.exe -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/IntegerMultiplication.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/IntegerMultiplication.pdb -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/MatrixMultiplication.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P1] Matrix Mult\[SOLUTION]\MatrixMultiply\bin\Debug\MatrixMultiplication.exe.config 2 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P1] Matrix Mult\[SOLUTION]\MatrixMultiply\obj\Debug\MatrixMultiplication.csprojResolveAssemblyReference.cache 3 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P1] Matrix Mult\[SOLUTION]\MatrixMultiply\bin\Debug\MatrixMultiplication.exe 4 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P1] Matrix Mult\[SOLUTION]\MatrixMultiply\bin\Debug\MatrixMultiplication.pdb 5 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P1] Matrix Mult\[SOLUTION]\MatrixMultiply\obj\Debug\MatrixMultiplication.exe 6 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P1] Matrix Mult\[SOLUTION]\MatrixMultiply\obj\Debug\MatrixMultiplication.pdb 7 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P2] Integer Mult\[SOLUTION]\IntegerMultiplication\bin\Debug\MatrixMultiplication.exe.config 8 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P2] Integer Mult\[SOLUTION]\IntegerMultiplication\obj\Debug\MatrixMultiplication.exe 9 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P2] Integer Mult\[SOLUTION]\IntegerMultiplication\obj\Debug\MatrixMultiplication.pdb 10 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/MatrixMultiplication.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/MatrixMultiplication.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/MatrixMultiplication.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/MatrixMultiplication.exe -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/MatrixMultiplication.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/MatrixMultiplication.pdb -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/ModOfPower.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[U3] Mod of Power\[TEMPLATE]\ModOfPower\bin\Debug\ModOfPower.exe.config 2 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[U3] Mod of Power\[TEMPLATE]\ModOfPower\obj\Debug\ModOfPower.csprojResolveAssemblyReference.cache 3 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[U3] Mod of Power\[TEMPLATE]\ModOfPower\bin\Debug\ModOfPower.exe 4 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[U3] Mod of Power\[TEMPLATE]\ModOfPower\bin\Debug\ModOfPower.pdb 5 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[U3] Mod of Power\[TEMPLATE]\ModOfPower\obj\Debug\ModOfPower.exe 6 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[U3] Mod of Power\[TEMPLATE]\ModOfPower\obj\Debug\ModOfPower.pdb 7 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[R3] PreparingPresentBaskets\[TEMPLATE]\PresentBaskets\bin\Debug\ModOfPower.exe.config 8 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[R3] PreparingPresentBaskets\[TEMPLATE]\PresentBaskets\obj\Debug\ModOfPower.exe 9 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[R3] PreparingPresentBaskets\[TEMPLATE]\PresentBaskets\obj\Debug\ModOfPower.pdb 10 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/ModOfPower.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/ModOfPower.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/ModOfPower.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/ModOfPower.exe -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/ModOfPower.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/ModOfPower.pdb -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/PresentBaskets.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[R3] PreparingPresentBaskets\[TEMPLATE]\PresentBaskets\bin\Debug\PresentBaskets.exe.config 2 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[R3] PreparingPresentBaskets\[TEMPLATE]\PresentBaskets\obj\Debug\PresentBaskets.csprojResolveAssemblyReference.cache 3 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[R3] PreparingPresentBaskets\[TEMPLATE]\PresentBaskets\bin\Debug\PresentBaskets.exe 4 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[R3] PreparingPresentBaskets\[TEMPLATE]\PresentBaskets\bin\Debug\PresentBaskets.pdb 5 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[R3] PreparingPresentBaskets\[TEMPLATE]\PresentBaskets\obj\Debug\PresentBaskets.exe 6 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[R3] PreparingPresentBaskets\[TEMPLATE]\PresentBaskets\obj\Debug\PresentBaskets.pdb 7 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[U3] Ali Baba assembling a team\[TEMPLATE]\AliBabaAssembleTeam\bin\Debug\PresentBaskets.exe.config 8 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[U3] Ali Baba assembling a team\[TEMPLATE]\AliBabaAssembleTeam\obj\Debug\PresentBaskets.exe 9 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\GREEDY\[U3] Ali Baba assembling a team\[TEMPLATE]\AliBabaAssembleTeam\obj\Debug\PresentBaskets.pdb 10 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/PresentBaskets.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/PresentBaskets.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/PresentBaskets.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/PresentBaskets.exe -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/PresentBaskets.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/PresentBaskets.pdb -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SchoolQuizII.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R2] School Quiz II\[SOLUTION]\SchoolQuizII\bin\Debug\SchoolQuizII.exe.config 2 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R2] School Quiz II\[SOLUTION]\SchoolQuizII\obj\Debug\SchoolQuizII.csprojResolveAssemblyReference.cache 3 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R2] School Quiz II\[SOLUTION]\SchoolQuizII\bin\Debug\SchoolQuizII.exe 4 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R2] School Quiz II\[SOLUTION]\SchoolQuizII\bin\Debug\SchoolQuizII.pdb 5 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R2] School Quiz II\[SOLUTION]\SchoolQuizII\obj\Debug\SchoolQuizII.exe 6 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R2] School Quiz II\[SOLUTION]\SchoolQuizII\obj\Debug\SchoolQuizII.pdb 7 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] School Quiz III\[SOLUTION]\SchoolQuizIII\bin\Debug\SchoolQuizII.exe.config 8 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] School Quiz III\[SOLUTION]\SchoolQuizIII\obj\Debug\SchoolQuizII.exe 9 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] School Quiz III\[SOLUTION]\SchoolQuizIII\obj\Debug\SchoolQuizII.pdb 10 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SchoolQuizII.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SchoolQuizII.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SchoolQuizII.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SchoolQuizII.exe -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SchoolQuizII.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SchoolQuizII.pdb -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SchoolQuizIII.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] School Quiz III\[SOLUTION]\SchoolQuizIII\bin\Debug\SchoolQuizIII.exe.config 2 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[SOLUTION]\SumToNumber\bin\Debug\SchoolQuizIII.exe.config 3 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/StatsOfChart.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[R2] Statistical analysis of graph charts\[SOLUTION]\StatsOfChart\bin\Debug\StatsOfChart.exe.config 2 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[R2] Statistical analysis of graph charts\[SOLUTION]\StatsOfChart\obj\Debug\StatsOfChart.csprojResolveAssemblyReference.cache 3 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[R2] Statistical analysis of graph charts\[SOLUTION]\StatsOfChart\bin\Debug\StatsOfChart.exe 4 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[R2] Statistical analysis of graph charts\[SOLUTION]\StatsOfChart\bin\Debug\StatsOfChart.pdb 5 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[R2] Statistical analysis of graph charts\[SOLUTION]\StatsOfChart\obj\Debug\StatsOfChart.exe 6 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\[R2] Statistical analysis of graph charts\[SOLUTION]\StatsOfChart\obj\Debug\StatsOfChart.pdb 7 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P1] Matrix Mult\[SOLUTION]\MatrixMultiply\bin\Debug\StatsOfChart.exe.config 8 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P1] Matrix Mult\[SOLUTION]\MatrixMultiply\obj\Debug\StatsOfChart.exe 9 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\D&C\BIG PROBLEMS\[P1] Matrix Mult\[SOLUTION]\MatrixMultiply\obj\Debug\StatsOfChart.pdb 10 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/StatsOfChart.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/StatsOfChart.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/StatsOfChart.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/StatsOfChart.exe -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/StatsOfChart.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/StatsOfChart.pdb -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SumToNumber.csproj.AssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SumToNumber.csproj.AssemblyReference.cache -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SumToNumber.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[SOLUTION]\SumToNumber\bin\Debug\SumToNumber.exe.config 2 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[SOLUTION]\SumToNumber\obj\Debug\SumToNumber.csprojResolveAssemblyReference.cache 3 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[SOLUTION]\SumToNumber\bin\Debug\SumToNumber.exe 4 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[SOLUTION]\SumToNumber\bin\Debug\SumToNumber.pdb 5 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[SOLUTION]\SumToNumber\obj\Debug\SumToNumber.exe 6 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[SOLUTION]\SumToNumber\obj\Debug\SumToNumber.pdb 7 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[TEMPLATE]\SumToNumber\bin\Debug\SumToNumber.exe.config 8 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[TEMPLATE]\SumToNumber\obj\Debug\SumToNumber.exe 9 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[TEMPLATE]\SumToNumber\obj\Debug\SumToNumber.pdb 10 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[TEMPLATE]\SumToNumber\bin\Debug\SumToNumber.exe 11 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[TEMPLATE]\SumToNumber\bin\Debug\SumToNumber.pdb 12 | E:\COURSES\Algorithms\[1] [ALL PROBLEMS - CODE]\UNIFIED OUTPUT\DP\[R4] Sum to Number\[TEMPLATE]\SumToNumber\obj\Debug\SumToNumber.csprojResolveAssemblyReference.cache 13 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SumToNumber.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SumToNumber.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SumToNumber.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SumToNumber.exe -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SumToNumber.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/SumToNumber.pdb -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Dynamic Programming/Problems/Subset Sum [FCIS]/Sum to Number/[TEMPLATE]/SumToNumber/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/Problems/Unique Paths II/README.md: -------------------------------------------------------------------------------- 1 | # Unique Paths II 2 | - [Unique Paths II | Leetcode](https://leetcode.com/problems/unique-paths-ii/) 3 | 4 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Dynamic Programming/README.md: -------------------------------------------------------------------------------- 1 | # Dynamic Programming 2 | 3 | 4 | 5 | # What is dp? 6 | 7 | - **Careful brute-force.** 8 | - **dp is an optimization over plain recursion.** 9 | - **Wherever we use recursion solution that has repeated calls for the same inputs, we can optimize it using dp.** 10 | - **It used in problems that have overlapping sub-problems.** 11 | 12 | # How to Apply dp? 13 | 14 | - **Store the answer of each sub-problems to avoid calculating it again.** 15 | - **dp needs Extra storage.** 16 | - `Time Space trade-offs.` 17 | 18 | # Why dp? 19 | 20 | - **Leads to efficient solutions.** 21 | - **Switch exponential complexity to polynomial.** 22 | 23 | # When to Use? 24 | 25 | ## Often used in optimization problems in which: 26 | 27 | - **There can be many solutions.** 28 | - **Need to try them all to get the optimal solution.** 29 | 30 | ## Optimal Substructure 31 | 32 | - **Optimal solution to problem found in its TOW or MORE sub-problems. its divide and conquer identity.** 33 | - **There exist Overlapped sub-problems.** 34 | 35 | 36 | # How to Use? 37 | ![image](https://user-images.githubusercontent.com/99830416/236589154-ee9129fe-0fd6-4026-8725-582b9faa0143.png) 38 | 39 | ## `Bottom-Up` 40 | 41 | - Iterative identity 42 | - Start building the solution from the base case. 43 | - Solve ALL sub-problems and store their solutions. 44 | - Called `building table`. 45 | - `[When?]` need to solve ALL sub-problems. 46 | - Better to use loop to avoid memory overhead. 47 | 48 | ## `Top-Down` 49 | 50 | - Recursive identity 51 | - Same as divide and conquer. Start with the big problem and divide till reach base case. 52 | - Solve & Store only its required sub-problems. 53 | - For each sub-problem, check if you solve this problem before. If you solve it get the answer from your storage 54 | - Called `Memoization` 55 | - `[When?]` no need to solve all sub-problems. 56 | 57 | 58 | # Where to Solve 59 | - [Educational DP Contest | Atcoder](https://atcoder.jp/contests/dp/tasks) 60 | 61 | 62 | # Materials 63 | - [Dynamic Programming Newbie to Expert | Techdose](https://www.youtube.com/playlist?list=PLEJXowNB4kPxBwaXtRO1qFLpCzF75DYrS) 64 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/All Paths From Source to Target/README.md: -------------------------------------------------------------------------------- 1 | # All Paths From Source to Target 2 | ### [All Paths From Source to Target | Leetcode](https://leetcode.com/problems/all-paths-from-source-to-target/) 3 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Check Connection Between 2 Nodes/README.md: -------------------------------------------------------------------------------- 1 | # Check Connection Between 2 Nodes 2 | Check if there is a path between 2 nodes for directed & undirected graph 3 | # Code 4 | ```cpp 5 | bool checkConecction(int node, int target, vector>& graph) { 6 | visited[node] = true; 7 | if (node == target) { 8 | return true; 9 | } 10 | for (int adj_node : graph[node]) { 11 | if (!visited[adj_node]) { 12 | if (checkConecction(adj_node, target, graph)) { 13 | return true; 14 | } 15 | } 16 | } 17 | return false; 18 | } 19 | int main() { 20 | int vertices, edges; cin >> vertices >> edges; 21 | vector>graph(vertices + 1); 22 | for (int i = 0; i < edges; i++) { 23 | int u, v; 24 | cin >> u >> v; 25 | graph[u].push_back(v); 26 | //graph[v].push_back(u); 27 | } 28 | int a, b; cin >> a >> b; 29 | checkConecction(a, b, graph) ? yes : no; 30 | } 31 | ``` 32 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Check Graph Connectivity/README.md: -------------------------------------------------------------------------------- 1 | ## Check Graph Connectivity [Directed & Undirected] 2 | `Graph Contains n nodes which equal to number of vertices` 3 | ```cpp 4 | bool visited[1000]; 5 | int dfs(int node, vector>&graph) { 6 | int visCount = 1; 7 | visited[node] = 1; 8 | for (auto child : graph[node]) { 9 | if (!visited[child]) 10 | visCount += dfs(child, graph); 11 | } 12 | return visCount; 13 | } 14 | int main() { 15 | int vertices, edges; cin >> vertices >> edges; 16 | vector>graph(vertices); 17 | for (int i = 0; i < edges; i++) { 18 | int u, v, c; 19 | cin >> u >> v; 20 | graph[u].push_back(v); 21 | } 22 | int nodes = dfs(anyGraphNode, graph); 23 | if (nodes == vertices) { cout << "Connected Graph"; } 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Connect The Graph/README.md: -------------------------------------------------------------------------------- 1 | # Connect The Graph 2 | - [Connect The Graph | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/connecting-the-graph/1) 3 | 4 | # Approach 5 | 6 | # Solution 7 | ```cpp 8 | 9 | ``` 10 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Connected Component Number/README.md: -------------------------------------------------------------------------------- 1 | # Connected Component Number 2 | # Toutorial 3 | - [Number of Provinces | LeetCode](https://leetcode.com/problems/number-of-provinces/) 4 | - [Number of Provinces | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/number-of-provinces/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 5 | 6 | # Approach 7 | Start dfs from from any point and check the other all points. if the current point is not visited (from other bfs) then it is in another component, so start bfs on this point 8 | 9 | 10 | # Code 11 | ```cpp 12 | bool visited[300]; 13 | void dfs(int node, vector>&graph) { 14 | //cout << node << "\n"; 15 | visited[node] = 1; 16 | for (auto child : graph[node]) { 17 | if (!visited[child]) 18 | dfs(child, graph); 19 | } 20 | } 21 | int main() { 22 | int n; cin >> n; 23 | vector>graph(n); 24 | for (int i = 0; i < n; i++) { 25 | for (int j = 0; j < n; j++) { 26 | int a; cin >> a; 27 | if (a) { 28 | graph[i].push_back(j); 29 | } 30 | } 31 | } 32 | int cnt = 0; 33 | for (int i = 0; i < n; i++) { 34 | if (!visited[i]) { 35 | dfs(i, graph); 36 | cnt++; 37 | } 38 | } 39 | cout << cnt; 40 | } 41 | ``` 42 | 43 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Find whether path exist/README.md: -------------------------------------------------------------------------------- 1 | # Find whether path exist 2 | ### [Find whether path exist | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/find-whether-path-exist5238/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 3 | 4 | 5 | # Solution 6 | ```cpp 7 | int dx[10] = { 1, -1, 0, 0, -1, -1, 1, 1 }; 8 | int dy[10] = { 0, 0, 1, -1, -1, 1, 1, -1 }; 9 | bool visited[505][505]; 10 | bool inMap(pairpoint, int n, int m, int mapBase) { 11 | int i = point.first, j = point.second; 12 | if (mapBase) return (i > 0 and i <= n and j > 0 and j <= m); 13 | else return (i >= 0 and i < n and j >= 0 and j < m); 14 | } 15 | bool bfs(pair entryPoint, pairendPoint, vector>&graph, int n, int m) { 16 | queue>q; 17 | q.push(entryPoint); 18 | pairpoint; 19 | while (q.size()) { 20 | point = q.front(); 21 | if (point == endPoint) { return true; } 22 | visited[point.first][point.second] = 1; 23 | q.pop(); 24 | // traverse 4 connected nodes of the current point [vertical & horizontal] 25 | for (int i = 0; i < 4; i++) { 26 | pair currentPoint = { point.first + dx[i], point.second + dy[i] }; 27 | if (inMap(currentPoint, n, m, 0) and !visited[currentPoint.first][currentPoint.second] and graph[currentPoint.first][currentPoint.second]!=0) { 28 | visited[currentPoint.first][currentPoint.second] = 1; 29 | q.push(currentPoint); 30 | } 31 | } 32 | } 33 | return false; 34 | } 35 | 36 | bool is_Possible(vector>& grid) 37 | { 38 | memset(visited, 0, sizeof(visited)); 39 | int n = grid.size(), m = grid[0].size(); 40 | pair entryPoint, destination; 41 | for (int i = 0; i < n; i++) { 42 | for (int j = 0; j < m; j++) { 43 | if (grid[i][j] == 1) { entryPoint = { i, j }; } 44 | else if (grid[i][j] == 2) { destination = { i,j }; } 45 | } 46 | } 47 | bool found = bfs(entryPoint, destination, grid, n, m); 48 | return found; 49 | } 50 | ``` 51 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Fire Again/README.md: -------------------------------------------------------------------------------- 1 | # Fire Again 2 | ## [Fire Again | Codeforces](https://codeforces.com/problemset/problem/35/C) 3 | ## Code 4 | ```cpp 5 | int dx[] = { 1, -1, 0 ,0 }; 6 | int dy[] = { 0 , 0 , 1, -1 }; 7 | vector>v; 8 | bool burnt[2005][2005]; 9 | bool inMap(pairpr, int n, int m) { 10 | int a = pr.first, b = pr.second; 11 | return (a > 0 and a <= n and b > 0 and b <= m); 12 | } 13 | void bfs(vector>&v, int n, int m) { 14 | queue>q; 15 | for (int i = 0; i < v.size(); i++) { q.push(v[i]); } 16 | pairpoint; 17 | while (q.size()) { 18 | point = q.front(); 19 | burnt[point.first][point.second] = 1; 20 | q.pop(); 21 | // traverse of childs of current point 22 | for (int i = 0; i < 4; i++) { 23 | pairp = { point.first + dx[i], point.second + dy[i] }; 24 | if (inMap(p, n, m) and !burnt[p.first][p.second]) { 25 | burnt[p.first][p.second] = 1; 26 | q.push(p); 27 | } 28 | } 29 | } 30 | cout << point.first << " " << point.second; 31 | } 32 | int main() { 33 | int n, m, k; 34 | cin >> n >> m >> k; 35 | while (k--) { 36 | int a, b; 37 | cin >> a >> b; 38 | // starting points of burn 39 | v.push_back({ a,b }); 40 | burnt[a][b] = 1; 41 | } 42 | bfs(v, n, m); 43 | } 44 | ``` 45 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Ice Cave/README.md: -------------------------------------------------------------------------------- 1 | # Ice Cave 2 | ## [Ice Cave | Codeforces](https://codeforces.com/problemset/problem/540/C) 3 | 4 | ## Solution 5 | ```cpp 6 | 7 | ``` 8 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Minimum Number of Vertices to Reach All Nodes/README.md: -------------------------------------------------------------------------------- 1 | # Minimum Number of Vertices to Reach All Nodes 2 | ### [Minimum Number of Vertices to Reach All Nodes](https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes/) 3 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Party/README.md: -------------------------------------------------------------------------------- 1 | # Party 2 | ## [Party | Codeforces](https://codeforces.com/contest/116/problem/C) 3 | 4 | ## Approach 5 | **Draw some graphs with the problem constraints. We will notice that the answer is the max level number of graph** 6 | 7 | 8 | ## Code 9 | ```cpp 10 | unordered_mapvisited; 11 | int bfs(int node, map>& graph) { 12 | queuenextToVisit; 13 | unordered_maplvl; 14 | nextToVisit.push(node); 15 | lvl[node] = 1; 16 | int mx = 0; 17 | while (nextToVisit.size()) { 18 | int current = nextToVisit.front(); 19 | visited[current] = 1; 20 | nextToVisit.pop(); 21 | mx = max(mx, lvl[current]); 22 | for (auto child : graph[current]) { 23 | if (!visited[child]) 24 | nextToVisit.push(child), visited[child] = 1, lvl[child] = lvl[current] + 1; 25 | } 26 | } 27 | return mx; 28 | } 29 | int main() { 30 | int n; cin >> n; 31 | map>graph; 32 | vectorentry; 33 | for (int i = 1; i <= n; i++) { 34 | int in; cin >> in; 35 | if (in != -1) { 36 | graph[in].push_back(i); 37 | } 38 | else { 39 | entry.push_back(i); 40 | } 41 | } 42 | int mx = -1; 43 | for (auto it : entry) { 44 | mx = max(mx, bfs(it, graph)); 45 | visited.clear(); 46 | } 47 | cout << mx; el; 48 | } 49 | ``` 50 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Round Trip II/README.md: -------------------------------------------------------------------------------- 1 | # Round Trip II 2 | ### [Round Trip II | CSES](https://cses.fi/problemset/task/1678) -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Rumor/README.md: -------------------------------------------------------------------------------- 1 | # Rumor 2 | ## [Rumor | Codeforces](https://codeforces.com/contest/893/problem/C) 3 | 4 | ## Approach 5 | **Get the min cost of nodes for each component** 6 | ## Solution 7 | ```cpp 8 | unordered_mapvisited; 9 | int bfs(int node, map>& graph, vector& cost) { 10 | queuenextToVisit; 11 | nextToVisit.push(node); 12 | int mn = 1e9 + 1; 13 | while (nextToVisit.size()) { 14 | int current = nextToVisit.front(); 15 | mn = min(mn, cost[current]); 16 | visited[current] = 1; 17 | nextToVisit.pop(); 18 | for (auto child : graph[current]) { 19 | if (!visited[child]) 20 | nextToVisit.push(child), visited[child] = 1; 21 | } 22 | } 23 | return mn; 24 | } 25 | int main() { 26 | int n, m; 27 | cin >> n >> m; 28 | vectorv(n + 1); 29 | for (int i = 1; i <= n; i++) { 30 | cin >> v[i]; 31 | } 32 | map>graph; 33 | while (m--) { 34 | int a, b; cin >> a >> b; 35 | graph[a].push_back(b); 36 | graph[b].push_back(a); 37 | } 38 | ll cost = 0; 39 | for (int i = 1; i <= n; i++) { 40 | if (!visited[i]) { cost += bfs(i, graph, v); } 41 | } 42 | cout << cost; 43 | } 44 | ``` 45 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Shortest Path From Entry Node To All Nodes/README.md: -------------------------------------------------------------------------------- 1 | # Shortest Path From Entry Node To All Nodes 2 | ## Problem Description 3 | **Given entry node print the shortest path [edges] visited for each node in the graph. If there is no connection between the entry node and any other one print -1.
4 | Find the problem here. First task at [Shortest paths | CS Academy](https://csacademy.com/lesson/breadth_first_search)** 5 | 6 | ## 💭 Approach 7 | **BFS by nature get the shortest path from entry node to all other nodes** 8 | 9 | # Code 10 | ```cpp 11 | const int GraphMaxSize = 1e5 + 5; 12 | mapvisited; 13 | vectorpath(GraphMaxSize, -1); 14 | void BFS(int node1, vector>& graph) { 15 | queuenextToVisit; 16 | path[node1] = 0; 17 | nextToVisit.push(node1); 18 | while (nextToVisit.size()) { 19 | int current = nextToVisit.front(); 20 | visited[current] = 1; 21 | nextToVisit.pop(); 22 | for (auto child : graph[current]) { 23 | if (!visited[child]) { 24 | nextToVisit.push(child); 25 | visited[child] = 1; 26 | path[child] = path[current] + 1; 27 | } 28 | } 29 | } 30 | } 31 | int main() { 32 | int vertices, edges, entry; cin >> vertices >> edges >> entry; 33 | vector>graph(vertices + 1); 34 | for (int i = 0; i < edges; i++) { 35 | int u, v; 36 | cin >> u >> v; 37 | graph[u].push_back(v); 38 | //graph[v].push_back(u); // for undirected graph 39 | } 40 | BFS(entry, graph); 41 | for (int i = 1; i <= vertices; i++) { 42 | cout << path[i] << " "; 43 | } 44 | } 45 | ``` 46 | 47 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Problems/Transform A To B/README.md: -------------------------------------------------------------------------------- 1 | # Transform A To B 2 | ## [Transform A To B | Codeforces](https://codeforces.com/contest/727/problem/A) 3 | 4 | ## Graph Approach 5 | - Generate your graph using BFS and if you find b, stop generation and traverse all parents of b. 6 | 7 | ## Graph Solution 8 | ```cpp 9 | void bfs(ll a, int b) { 10 | queuenextToVisit; 11 | mapparent; 12 | nextToVisit.push(a); 13 | parent[a] = -1; 14 | bool valid = false; 15 | while (nextToVisit.size()) { 16 | ll current = nextToVisit.front(); 17 | nextToVisit.pop(); 18 | ll val = current * 2; 19 | if (val == b) { valid = true; parent[val] = current; break; } 20 | if (val < b) { nextToVisit.push(val); parent[val] = current; } 21 | val = current * 10 + 1; 22 | if (val == b) { valid = true; parent[val] = current; break; } 23 | if (val < b) { nextToVisit.push(val); parent[val] = current;} 24 | } 25 | if (!valid) { cout << "NO\n"; return; } 26 | vectorpath; 27 | while (b != -1) { 28 | path.push_back(b); 29 | b = parent[b]; 30 | } 31 | reverse(path.begin(), path.end()); 32 | cout << "YES\n" << path.size() << "\n"; 33 | for (auto it : path) { cout << it << " "; } 34 | } 35 | int main() { 36 | ll a, b; cin >> a >> b; 37 | bfs(a, b); 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/README.md: -------------------------------------------------------------------------------- 1 | # Graph 2 | 3 | 4 | https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/f7bc6580-4a00-4db4-bbe6-932c44c94810 5 | 6 | 7 | ### [`Indroduction To Graph Theory | CS Academy`](https://csacademy.com/lesson/introduction_to_graphs/) 8 | 9 | ### [`Graph Visualizer`](https://csacademy.com/app/graph_editor/) 10 | 11 | 12 | # ⚪ Terminolgies 13 | > ![image](https://user-images.githubusercontent.com/99830416/230741172-cd39c380-5637-44d2-999d-ba3cd847cfac.png) 14 | > 15 | > ## General 16 | > - A graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. 17 | > - Vertices: Interconnected objects 18 | > - Edges: Links that connect the vertices   19 | > 20 | > ## Adjacency 21 | > - For each edge {u, v} the vertices u and v are said to be adjacent to one another, denoted `u ~ v`. 22 | > - 1 is adjacent to 3. 23 | > - 1 is not adjacent to 2. 24 | > 25 | > ## Directed & Undirected Graphs 26 | > #### Directed 27 | > - `UnSymmetrical` 28 | > - Edge (u, v) goes from u to v not vice versa. `u ➙ v` 29 | > #### Undirected 30 | > - `Symmetrical` 31 | > - Edge (u,v) = Edge (v,u)
32 | > - No self loops
33 | > 34 | > ## Graph Order 35 | > - Number of vertices |V| 36 | > 37 | > ## Graph Size 38 | > - Number of edges |E| 39 | > - For `Directed Graph` one vertex can have at most v edges = v-1 edges to all vertices and one to its self. So `max number of edges` = |v^2| 40 | > - For `Undirected Graph` First vertex has |v| edges, Second vertex has |v-1|, Third vertex has |v-2| and so on.
So `max number of edges` = (v - 1) * (v) / 2. While order will be O(|V^2|). 41 | > - `note` max graph size is O(|V|^2) for directed graph, O(|V|^2) also for undirected graph 42 | > 43 | > ## Vertex degree 44 | > - Number of `edges` connected to this vertex 45 | > - For directed graph:
46 | > `In degree`: number of edges that enter this vertex. 47 | > `Out degree`: number of edges leaves this vertex 48 | > 49 | > ## Graph Types 50 | > - Connected graph: There is path from any vertex to any another vertex. 51 | > - Disconnected graph: There is at least one vertex that can not reach at least another vertex 52 | > - Weighted graph: Associates weights with either the edges or the vertices 53 | > - Dense graph
54 | > ➙ a graph with large number of edges
55 | > ➙ number of edges `graph size` = V^2
56 | > - Sparse graph: graph with number of edges `graph size` = V 57 | 58 | # ⚪ Complexity 59 | - In term of number of `edges` & `vertices` 60 | - O(vertices + edges) 61 | 62 | # ⚪ Question 63 | - Consider an undirected graph that has V vertices, no parallel edges, and is connected (i.e., “in one piece”). What is the minimum and maximum number of edges that the graph could have, respectively? 64 | `V-1` `(V - 1) * V / 2` 65 | 66 | # ⚪ Common Problems 67 | - **Connectivity**: Can i reach form node A to B ? 68 | - **Generate Connected Components**: Components is nodes that generate connected graph 69 | - **Shotest Path** 70 | - **Min Cost** 71 | 72 | # Resources 73 | ### [Top 50 Graph Coding Problems for Interviews | GeeksForGeeks](https://www.geeksforgeeks.org/top-50-graph-coding-problems-for-interviews/) 74 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/A-Graph Representation/README.md: -------------------------------------------------------------------------------- 1 | # Graph Represenation 2 | # Materials 3 | ### [Graph Represenation | CS Academy](https://csacademy.com/lesson/graph_representation) 4 | 5 | # Input & Basic Output Graph 6 | ```cpp 7 | int vertices, edges; cin >> vertices >> edges; 8 | //each value in vector will contain vector of its connect nodes [node, Cost] 9 | vector>>graph(vertices); 10 | //each edge contains 2 values: u -> v with price c 11 | for (int i = 0; i < edges; i++) { 12 | int u, v, c; 13 | cin >> u >> v >> c; 14 | graph[u].push_back({v, c}); 15 | // graph[v].push_back({ u, c }); // in case of undirected graph 16 | } 17 | 18 | // print the adjacency list 19 | cout << "\n"; 20 | for (int u = 0; u < vertices; u++) { 21 | cout << u << "\n----\n"; 22 | for (auto it : graph[u]) { 23 | cout << "node: " << it.first << " price: " << it.second << "\n"; 24 | } 25 | cout << endl; 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/B-Graph Traversal/BFS/Path & Level Of Each Node/README.md: -------------------------------------------------------------------------------- 1 | # ☢ Path & Level Of Each Node 2 | ```cpp 3 | bool visited[1000]; 4 | unordered_maplvl, parent; 5 | vector getPath(int node) { 6 | vectorpath; 7 | while (node != -1) { 8 | path.push_back(node); 9 | node = parent[node]; 10 | } 11 | reverse(all(path)); 12 | return path; 13 | } 14 | void bfs(int node, vector>& graph) { 15 | queuenextToVisit; 16 | nextToVisit.push(node); 17 | parent[node] = -1; 18 | lvl[node] = 0; 19 | while (nextToVisit.size()) { 20 | int current = nextToVisit.front(); 21 | cout << current << "\n"; 22 | visited[current] = 1; 23 | nextToVisit.pop(); 24 | for (auto child : graph[current]) { 25 | if (!visited[child]) { 26 | nextToVisit.push(child), visited[child] = 1; 27 | lvl[child] = lvl[current] + 1; 28 | parent[child] = current; 29 | } 30 | } 31 | } 32 | } 33 | void doIt() { 34 | int vertices, edges; 35 | cin >> vertices >> edges; 36 | vector>graph(vertices + 1); 37 | for (int i = 0; i < edges; i++) { 38 | int u, v, c; 39 | cin >> u >> v; 40 | graph[u].push_back(v); 41 | graph[v].push_back(u); 42 | } 43 | // note vertices are 1 based 44 | for (int i = 1; i <= vertices; i++) { 45 | if (!visited[i]) { bfs(i, graph); } 46 | } 47 | while (true) { 48 | cout << "Enter node you want to get its path: "; 49 | int node; cin >> node; 50 | cout << "Path: "; 51 | vectorpath = getPath(node); 52 | for (auto it : path) { cout << it << " "; } 53 | cout << "\n"; 54 | } 55 | } 56 | ``` 57 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/B-Graph Traversal/DFS/Count Nodes/README.md: -------------------------------------------------------------------------------- 1 | # Count Nodes 2 | **Count Nodes Starting From Entry Node Using BFS** 3 | ```cpp 4 | bool visited[1000]; 5 | int dfsCountGraphNodes(int node, vector>& graph) { 6 | int ans = 1; 7 | visited[node] = 1; 8 | for (int child : graph[node]) { 9 | if (!visited[child]) 10 | ans += dfsCountGraphNodes(child, graph); 11 | } 12 | return ans; 13 | } 14 | ``` 15 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/B-Graph Traversal/DFS/README.md: -------------------------------------------------------------------------------- 1 | # DFS 2 | **`Depth First Search` Traverse Depth to the bottom node** 3 | # Tutorials 4 | - [DFS Tutorial | CS Academy](https://csacademy.com/lesson/depth_first_search) 5 | ## Traverse 6 | ```cpp 7 | bool visited[1000]; 8 | void dfs(int node, vector>&graph) { 9 | cout << node << "\n"; 10 | visited[node] = 1; 11 | for (auto child : graph[node]) { 12 | if (!visited[child]) 13 | dfs(child, graph); 14 | } 15 | } 16 | ``` 17 | DFS be like 🤣 18 | 19 | https://user-images.githubusercontent.com/99830416/232340446-2ddc9b90-d2ad-45ca-a42a-c6ec793a43ab.mp4 20 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/B-Graph Traversal/Directed & Unconnected Graph Traverse/README.md: -------------------------------------------------------------------------------- 1 | # Directed & Unconnected Graph Traverse 2 | 3 | ![image](https://user-images.githubusercontent.com/99830416/230778759-808206dc-4e44-4616-849b-ab6615cc76d3.png) 4 | 5 | **Here if we traverse this graph from node 0 we will not reach node 1 so how to traverse directed graph and avoid this problem?** 6 | - First pick a node and call the your traversal algorithm (dfs or bfs) with that starting point. 7 | - While there still are some unvisited nodes, pick one of them and call the DFS algorithm again using that particular node as the starting point. 8 | ```cpp 9 | bool visited[1000]; 10 | void dfs(int node, vector>&graph) { 11 | cout << node << "\n"; 12 | visited[node] = 1; 13 | for (auto child : graph[node]) { 14 | if (!visited[child]) 15 | dfs(child, graph); 16 | } 17 | 18 | } 19 | int main() { 20 | int vertices, edges; cin >> vertices >> edges; 21 | vector>graph(vertices); 22 | for (int i = 0; i < edges; i++) { 23 | int u, v, c; 24 | cin >> u >> v; 25 | graph[u].push_back(v); 26 | } 27 | for (int i = 0; i < vertices; i++) { 28 | if (!visited[i]) { dfs(i, graph); } 29 | } 30 | } 31 | ``` 32 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/B-Graph Traversal/README.md: -------------------------------------------------------------------------------- 1 | # Graph Represenation & Traversal 2 | 3 | # Enter Graph 4 | ```cpp 5 | int main() { 6 | int vertices, edges; cin >> vertices >> edges; 7 | vector>graph(vertices + 1); 8 | for (int i = 0; i < edges; i++) { 9 | int u, v, c; 10 | cin >> u >> v; 11 | graph[u].push_back(v); 12 | graph[v].push_back(u); // for undirected graph 13 | } 14 | } 15 | ``` 16 | 17 | # Graph Traversal Complexity 18 | **`O(|V| + |E|)`**
19 | **Traverse all vertices and edges** 20 | 21 | # Tree 22 | - Has no cycles 23 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/B-Graph Traversal/Traversing in a 2D Grid/README.md: -------------------------------------------------------------------------------- 1 | # Traversing in a 2D Grid 2 | ![image](https://user-images.githubusercontent.com/99830416/233385168-a2677c80-264f-4cad-985c-cbfe0ea4d1ce.png) 3 | 4 | - Let’s take the above grid as an example, if you are standing on point (3,2) you can move to the following four points, (3,1), (3,3), (2,2), (4,2). 5 | - So, if you are on point (i,j), you can move to (i - 1, j), (i + 1, j), (i, j + 1), (i, j - 1), but first you need to check if the point you are traversing to is in _**borders**_. 6 | 7 | # Problems 8 | ### [Fire Again | CodeForces](https://codeforces.com/contest/35/problem/C) 9 | 10 | # Traversal 11 | ```cpp 12 | // first four points for vertical & horizontal moves, second four points for diagonal moves 13 | int dx[] = { 1, -1, 0, 0, -1, -1, 1, 1 }; 14 | int dy[] = { 0, 0, 1, -1, -1, 1, 1, -1 }; 15 | bool visited[2005][2005]; 16 | bool inMap(pairpoint, int n, int m, int mapBase) { 17 | int i = point.first, j = point.second; 18 | if (mapBase) return (i > 0 and i <= n and j > 0 and j <= m); 19 | else return (i >= 0 and i < n and j >= 0 and j < m); 20 | } 21 | void bfs(vector>&entryPoints, int n, int m) { 22 | queue>q; 23 | for (int i = 0; i < entryPoints.size(); i++) { q.push(entryPoints[i]); } 24 | pairpoint; 25 | while (q.size()) { 26 | point = q.front(); 27 | visited[point.first][point.second] = 1; 28 | q.pop(); 29 | // traverse 4 connected nodes of the current point [vertical & horizontal] 30 | for (int i = 0; i < 4; i++) { 31 | pair currentPoint = { point.first + dx[i], point.second + dy[i]}; 32 | if (inMap(currentPoint, n, m, 1) and !visited[currentPoint.first][currentPoint.second]) { 33 | visited[currentPoint.first][currentPoint.second] = 1; 34 | q.push(currentPoint); 35 | } 36 | } 37 | } 38 | // print last traversed node 39 | cout << point.first << " " << point.second << "\n"; 40 | } 41 | int main() { 42 | int n, m, numOfEntryPoints; 43 | cin >> n >> m >> numOfEntryPoints; 44 | vector>entryPoints; 45 | 46 | /* 47 | -> in case u have only one entry point at (1, 1) <- 48 | entryPoints.push_back({ 1,1 }); 49 | visited[1][1] = 1; 50 | */ 51 | 52 | while (numOfEntryPoints--) { 53 | int a, b; 54 | cin >> a >> b; // one based points 55 | entryPoints.push_back({ a,b }); 56 | visited[a][b] = 1; 57 | } 58 | bfs(entryPoints, n, m); 59 | } 60 | ``` 61 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/B-Graph Traversal/Update Visited Array/README.md: -------------------------------------------------------------------------------- 1 | # When to Update Visted Array 2 | 3 | # Id Trick 4 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/C-Traversing in a 2D Grid/README.md: -------------------------------------------------------------------------------- 1 | # Traversing in a 2D Grid 2 | ![image](https://user-images.githubusercontent.com/99830416/233385168-a2677c80-264f-4cad-985c-cbfe0ea4d1ce.png) 3 | 4 | - Let’s take the above grid as an example, if you are standing on point (3,2) you can move to the following four points, (3,1), (3,3), (2,2), (4,2). 5 | - So, if you are on point (i,j), you can move to (i - 1, j), (i + 1, j), (i, j + 1), (i, j - 1), but first you need to check if the point you are traversing to is in _**borders**_. 6 | 7 | # Problems 8 | - [Fire Again | CodeForces](https://codeforces.com/contest/35/problem/C) 9 | 10 | # Traversal 11 | ```cpp 12 | // first four points for vertical & horizontal moves, second four points for diagonal moves 13 | int dx[] = { 1, -1, 0, 0, -1, -1, 1, 1 }; 14 | int dy[] = { 0, 0, 1, -1, -1, 1, 1, -1 }; 15 | bool visited[2005][2005]; 16 | bool inMap(pairpoint, int n, int m, int mapBase) { 17 | int i = point.first, j = point.second; 18 | if (mapBase) return (i > 0 and i <= n and j > 0 and j <= m); 19 | else return (i >= 0 and i < n and j >= 0 and j < m); 20 | } 21 | void bfs(vector>&entryPoints, int n, int m) { 22 | queue>q; 23 | for (int i = 0; i < entryPoints.size(); i++) { q.push(entryPoints[i]); } 24 | pairpoint; 25 | while (q.size()) { 26 | point = q.front(); 27 | visited[point.first][point.second] = 1; 28 | q.pop(); 29 | // traverse 4 connected nodes of the current point [vertical & horizontal] 30 | for (int i = 0; i < 4; i++) { 31 | pair currentPoint = { point.first + dx[i], point.second + dy[i]}; 32 | if (inMap(currentPoint, n, m, 1) and !visited[currentPoint.first][currentPoint.second]) { 33 | visited[currentPoint.first][currentPoint.second] = 1; 34 | q.push(currentPoint); 35 | } 36 | } 37 | } 38 | // print last traversed node 39 | cout << point.first << " " << point.second << "\n"; 40 | } 41 | int main() { 42 | int n, m, numOfEntryPoints; 43 | cin >> n >> m >> numOfEntryPoints; 44 | vector>entryPoints; 45 | 46 | /* 47 | -> in case u have only one entry point at (1, 1) <- 48 | entryPoints.push_back({ 1,1 }); 49 | visited[1][1] = 1; 50 | */ 51 | 52 | while (numOfEntryPoints--) { 53 | int a, b; 54 | cin >> a >> b; // one based points 55 | entryPoints.push_back({ a,b }); 56 | visited[a][b] = 1; 57 | } 58 | bfs(entryPoints, n, m); 59 | } 60 | ``` 61 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/D-Graph Connectivity/README.md: -------------------------------------------------------------------------------- 1 | # Graph Connectivity 2 | ## Check Graph Connectivity [Directed & Undirected] 3 | **`Graph Contains n nodes which equal to number of vertices`** 4 | - `Directed : Better to DFS` 5 | - `Undirected : Better to BFS` 6 | 7 | 8 | ```cpp 9 | bool visited[1000]; 10 | int dfs(int node, vector>&graph) { 11 | int visCount = 1; 12 | visited[node] = 1; 13 | for (auto child : graph[node]) { 14 | if (!visited[child]) 15 | visCount += dfs(child, graph); 16 | } 17 | return visCount; 18 | } 19 | int main() { 20 | int vertices, edges; cin >> vertices >> edges; 21 | vector>graph(vertices); 22 | for (int i = 0; i < edges; i++) { 23 | int u, v, c; 24 | cin >> u >> v; 25 | graph[u].push_back(v); 26 | } 27 | int nodes = dfs(anyGraphNode, graph); 28 | if (nodes == vertices) { cout << "Connected Graph"; } 29 | } 30 | ``` 31 | 32 | ## Check Connection between 2 nodes [Directed & Undirected] 33 | ### [Find if Path Exists in Graph | Leetcode](https://leetcode.com/problems/find-if-path-exists-in-graph/description/) 34 | ```cpp 35 | bool checkConecction(int node, int target, vector>& graph) { 36 | visited[node] = true; 37 | if (node == target) { 38 | return true; 39 | } 40 | for (int adj_node : graph[node]) { 41 | if (!visited[adj_node]) { 42 | if (checkConecction(adj_node, target, graph)) { 43 | return true; 44 | } 45 | } 46 | } 47 | return false; 48 | } 49 | int main() { 50 | int vertices, edges; cin >> vertices >> edges; 51 | vector>graph(vertices + 1); 52 | for (int i = 0; i < edges; i++) { 53 | int u, v; 54 | cin >> u >> v; 55 | graph[u].push_back(v); 56 | //graph[v].push_back(u); 57 | } 58 | int a, b; cin >> a >> b; 59 | checkConecction(a, b, graph) ? yes : no; 60 | } 61 | ``` 62 | ```cpp 63 | vectorcolor(100, 'w'); 64 | bool bfs(int node, int target, vector>& graph) { 65 | queuenextToVisit; 66 | nextToVisit.push(node); 67 | color[node] = 'g'; 68 | while (nextToVisit.size()) { 69 | int current = nextToVisit.front(); 70 | //cout << current << "\n"; 71 | nextToVisit.pop(); 72 | for (auto child : graph[current]) { 73 | if (color[child] == 'w') { 74 | if (child == target) { return true; } 75 | nextToVisit.push(child); 76 | color[child] = 'g'; 77 | } 78 | } 79 | color[current] = 'b'; 80 | } 81 | return false; 82 | } 83 | void doIt() { 84 | int vertices, edges; cin >> vertices >> edges; 85 | vector>graph(vertices + 1); 86 | for (int i = 0; i < edges; i++) { 87 | int u, v, c; 88 | cin >> u >> v; 89 | graph[u].push_back(v); 90 | graph[v].push_back(u); 91 | } 92 | int start, target; 93 | cin >> start >> target; 94 | bool valid = bfs(start, target, graph) || (start == target); 95 | valid ? yes : no; 96 | } 97 | ``` 98 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/D-Graph Connectivity/Strongly Connected Components/README.md: -------------------------------------------------------------------------------- 1 | # Strongly Connected Components 2 | ### [Strongly Connected Components | GeeksForGeeks](https://www.geeksforgeeks.org/strongly-connected-components/) -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/E-Edge Classification/README.md: -------------------------------------------------------------------------------- 1 | # Edge Classifications⛓️ 2 | 3 | # Color Reference 4 | 5 | - **White** ▶ has not been discovered. 6 | - **Grey** ▶discovered but not fully explored. 7 | - **Black ▶** discovered and fully explored. 8 | 9 | ## Backward Edge 10 | 11 | - On tree the edge connects `bottom node [child]` with `top node [gray parent]` 12 | - Edge makes cycle. 13 | - Edge connects child with any of its parents. 14 | - Go to **Gray** node. 15 | 16 | ## Forward Edge 17 | 18 | - On tree, the edge goes from `top [parent]` to `bottom [black child of the top]` 19 | - Go to **Black** node & discoveryTime(source) < discoveryTime(destination) 20 | 21 | ## Cross Edge [In Directed Graphs Only] 22 | 23 | - On tree the edge connects 2 nodes in different trees, or 2 different branches in the same tree 24 | - Go to **Black** node & discoveryTime(source) > discoveryTime(destination) 25 | 26 | # Edge Classification [Directed & Undirected] 27 | ```cpp 28 | int backword, forwardd, cross, Time; 29 | vector color(100, 'w'); 30 | vector parent(100, -1), discovery(100), delivery(100); 31 | //mapcolor; 32 | //mapparent, discovery, delivery; 33 | void dfs(int node, vector>& graph) { 34 | Time++; 35 | color[node] = 'g'; 36 | discovery[node] = Time; 37 | cout << "node: " << node << ", parent: " << parent[node] << " discovery time: " << discovery[node] << "\n"; 38 | for (auto child : graph[node]) { 39 | // node is the source and child is the destination 40 | if (color[child] == 'w') { 41 | cout << "tree edge: " << node << " -> " << child << "\n"; 42 | parent[child] = node; 43 | dfs(child, graph); 44 | } 45 | else if (color[child] == 'g' and child != parent[node]) { 46 | cout << "backword edge: " << node << " -> " << child << "\n"; 47 | backword++; 48 | } 49 | else if (color[child] == 'b' and discovery[node] < discovery[child]) { 50 | cout << "forward edge: " << node << " -> " << child << "\n"; 51 | forwardd++; 52 | } 53 | else if (color[child] == 'b' and discovery[node] > discovery[child]) { 54 | cout << "cross edge: " << node << " -> " << child << "\n"; 55 | cross++; 56 | } 57 | } 58 | color[node] = 'b'; 59 | delivery[node] = Time + 1; 60 | } 61 | void doIt() { 62 | backword = forwardd = cross = Time = 0; 63 | int vertices, edges; cin >> vertices >> edges; 64 | vector>graph(vertices + 1); 65 | for (int i = 0; i < edges; i++) { 66 | int u, v, c; 67 | cin >> u >> v; 68 | graph[u].push_back(v); 69 | graph[v].push_back(u); // for undirected graph 70 | } 71 | for (int i = 0; i < vertices; i++) { 72 | if (color[i] == 'w') { 73 | dfs(i, graph); 74 | } 75 | } 76 | cout << "\nNumber of backward edges: " << backword << "\n"; 77 | cout << "Number of forward edges: " << forwardd << "\n"; 78 | cout << "Number of cross edges: " << cross << "\n"; 79 | } 80 | ``` 81 | **Notes** 82 | - There are no cross edges in undirected graph. 83 | - In Undirected graph alwayes number of backword edges equal to number of forward edges. 84 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/F-Cycle Detection/Directed Graph Cycle Detection/README.md: -------------------------------------------------------------------------------- 1 | # `Directed Graph Cycle Detection` 2 | ### [Detect cycle in a directed graph | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/detect-cycle-in-a-directed-graph/1) 3 | ## `Approach` 4 | **The only difference between this this approach and the approach if undirected graph is the check if the child not equal to the parent of this child** 5 | ## `Solution` 6 | ```cpp 7 | bool ok = false; 8 | void dfs(int node, vectorgraph [], vector& color, vector& parent) { 9 | color[node] = 'g'; 10 | for (auto child : graph[node]) { 11 | // node is the source and child is the destination 12 | if (color[child] == 'w') { 13 | parent[child] = node; 14 | dfs(child, graph, color, parent); 15 | } 16 | else if (color[child] == 'g') { 17 | ok = true; 18 | return; 19 | } 20 | } 21 | color[node] = 'b'; 22 | } 23 | // Function to detect cycle in a directed graph. 24 | bool isCyclic(int V, vector adj[]) { 25 | ok = false; 26 | vector color(V + 1, 'w'); 27 | vector parent(V + 1, -1); 28 | for (int i = 0; i < V; i++) { 29 | if (color[i] == 'w') { 30 | dfs(i, adj, color, parent); 31 | } 32 | } 33 | return ok; 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/F-Cycle Detection/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/F-Cycle Detection/Undirected Graph Cycle Detection/README.md: -------------------------------------------------------------------------------- 1 | # `Undirected Graph Cycle Detection` 2 | ### [Detect cycle in an undirected graph | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/detect-cycle-in-an-undirected-graph/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 3 | # Approach 4 | - `DFS Approach` **To detect undirected graph cycle, we should mark any node we visit till now, if the current node is already visited and not its parent, then its cycle. We implement it using dfs** 5 | - `BFS Approach` 6 | 7 | # DFS Approach 8 | ```cpp 9 | bool ok = false; 10 | void dfs(int node, vector>graph, vector& color, vector& parent) { 11 | color[node] = 'g'; 12 | for (auto child : graph[node]) { 13 | // node is the source and child is the destination 14 | if (color[child] == 'w') { 15 | parent[child] = node; 16 | dfs(child, graph, color, parent); 17 | } 18 | else if (color[child] == 'g' and child != parent[node]) { 19 | ok = true; 20 | return; 21 | } 22 | } 23 | color[node] = 'b'; 24 | } 25 | void doIt() { 26 | int vertices, edges; cin >> vertices >> edges; 27 | vector>graph(vertices + 1); 28 | for (int i = 0; i < edges; i++) { 29 | int u, v, c; 30 | cin >> u >> v; 31 | graph[u].push_back(v); 32 | graph[v].push_back(u); // for undirected graph 33 | } 34 | ok = false; 35 | vector color(1e5 + 5, 'w'); 36 | vector parent(1e5 + 5, -1); 37 | for (int i = 0; i < vertices; i++) { 38 | if (color[i] == 'w') { 39 | dfs(i, graph, color, parent); 40 | } 41 | } 42 | ok ? yes : no; 43 | } 44 | ``` 45 | 46 | # BFS Approach 47 | ```cpp 48 | 49 | ``` 50 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/G-Shortest Paths/README.md: -------------------------------------------------------------------------------- 1 | # Shortest Paths 2 | ## Shortest Path [Min Traversed Nodes / Edges] 3 | **It can be implemented using `BFS` as it traverse graph level by level. The counter will be incremented when traverse all level nodes** 4 | ```cpp 5 | mapvisited; 6 | int shortestPath(int node1, int node2, vector>& graph) { 7 | // assum that graph level start from level 1 8 | queuenextToVisit; 9 | nextToVisit.push(node1); 10 | int lvl = 1; 11 | while (nextToVisit.size()) { 12 | int sz = nextToVisit.size(); 13 | lvl++; 14 | for (int i = 0; i < sz; i++) { 15 | int current = nextToVisit.front(); 16 | visited[current] = 1; 17 | nextToVisit.pop(); 18 | for (auto child : graph[current]) { 19 | if (!visited[child]) { 20 | nextToVisit.push(child); 21 | visited[child] = 1; 22 | if (child == node2) { return lvl; } 23 | } 24 | } 25 | } 26 | } 27 | return -1; 28 | } 29 | void do_it() { 30 | int vertices, edges; cin >> vertices >> edges; 31 | vector>graph(vertices + 1); 32 | for (int i = 0; i < edges; i++) { 33 | int u, v, c; 34 | cin >> u >> v; 35 | graph[u].push_back(v); 36 | graph[v].push_back(u); // for undirected graph 37 | } 38 | while (true) { 39 | int a, b; 40 | cout << "enter 2 nodes: "; cin >> a >> b; 41 | int path = shortestPath(a, b, graph); 42 | cout << "level of node2 from node1 is: " << path << "\n"; 43 | if (path == -1) { cout << "\n"; continue; } 44 | // min number of traversed nodes to reach b from a (excluding node1 and node2) 45 | cout << "shortest path (min number of nodes): " << path - 2 << "\n"; 46 | // min number of traversed edges to reach b from a 47 | cout << "shortest path (min number of edges): " << path - 1 << "\n\n"; 48 | visited.clear(); 49 | } 50 | } 51 | ``` 52 | ## Shortest Path [Min Cost] 53 | - It can be implemented using dijstra 54 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/Topics/H-Topoligical Sort [Dependencies]/README.md: -------------------------------------------------------------------------------- 1 | # Topological Sort [Dependencies] 2 | 3 | - **Definition: The correct order to do Depen** 4 | - **It's valid only for DAG** `Directed Graph with no cycles` 5 | - **Starts with nodes with 0 in-degree.** 6 | 7 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/acmASCIS Material/Graph Algorithms [acmASCIS].docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Graph/acmASCIS Material/Graph Algorithms [acmASCIS].docx -------------------------------------------------------------------------------- /Algorithms Design 🌟/Graph/acmASCIS Material/README.md: -------------------------------------------------------------------------------- 1 | # acmASCIS Materials 2 | ### [`Graph Video`](https://youtu.be/Y1l9rjOB7WI) 3 | ### [`Graph I Practice Sheet`](https://vjudge.net/contest/552892) 4 | ### [`Graph I Main Sheet`](https://vjudge.net/contest/552894) 5 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Greedy/Fractional Knapsack/README.md: -------------------------------------------------------------------------------- 1 | # Fractional Knapsack 2 | 3 | ## [Fractional Knapsack | Codeforces](https://codeforces.com/group/Z2G2riS3Yo/contest/428854/problem/C) 4 | *The problem is private in acmASCIS sheet on codeforces. It might not open with you* 5 | ## [Fractional Knapsack | Geeks For Geeks](https://practice.geeksforgeeks.org/problems/fractional-knapsack-1587115620/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 6 | ## Code 7 | ```cpp 8 | int main() { 9 | cout << fixed << setprecision(4); 10 | int n, k; 11 | cin >> n >> k; 12 | double ans = 0; 13 | vectorWeight(n), Cost(n); 14 | vector>gramCost; 15 | for (int i = 0; i < n; i++) { 16 | cin >> Weight[i]; 17 | } 18 | for (int i = 0; i < n; i++) { 19 | cin >> Cost[i]; 20 | } 21 | for (int i = 0; i < n; i++) { 22 | gramCost.push_back({ Cost[i] / Weight[i],Weight[i]}); 23 | } 24 | sort(all(gramCost)); 25 | reverse(all(gramCost)); 26 | for (int i = 0; i < n; i++) { 27 | if (gramCost[i].second <= k) { 28 | ans += (gramCost[i].first* gramCost[i].second); 29 | k -= gramCost[i].second; 30 | } 31 | else { 32 | ans += gramCost[i].first*k; 33 | break; 34 | } 35 | } 36 | cout << ans; 37 | } 38 | ``` 39 | ## Complexity 40 | - O(N.Log(N)) 41 | - `Can we make it better? Think of Kth element technique` 42 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Greedy/Maximum Subarray Sum/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/Greedy/Maximum Subarray Sum/README.md -------------------------------------------------------------------------------- /Algorithms Design 🌟/Greedy/README.md: -------------------------------------------------------------------------------- 1 | # Greedy 2 | `"A greedy algorithm always makes the locally optimal choice at each step, with the hope of finding a global optimum." - Jon Kleinberg` 3 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/Greedy/Scheduling Activities/README.md: -------------------------------------------------------------------------------- 1 | # Scheduling Activities 2 | ## [Scheduling Activities | CSES Problem set](https://cses.fi/problemset/task/1629) 3 | ## [Scheduling Activities | Codeforces](https://codeforces.com/gym/102961/problem/F) 4 | ## [Tutorial | ARS LONGA VITA BREVIS](https://www.youtube.com/watch?v=m5hGKMi-NP8&t=177s) 5 | 6 | ## Naïve Approach 7 | - Try all combinations `Take or Leave` Approach 8 | - Coded using recursion to get all possiblities 9 | - O(2^N) 10 | 11 | ## Greedy Approach | Efficient 12 | - Sort by `Finish Time` 13 | - Iterate over the sorted array and check if the current `start time` >= `last finish time` then take this activity and update the last finish time by the finish time of this activity. Else continue 14 | 15 | 16 | 17 | 18 | ## Code 19 | ```cpp 20 | int main() { 21 | int n; cin >> n; 22 | vector>v(n); 23 | for (auto& it : v) { cin >> it.second >> it.first; } 24 | // it.first = end time, it.second = start time 25 | sort(v.begin(), v.end()); 26 | int last_finish_time = 0; 27 | int cnt = 0; 28 | for (auto it : v) { 29 | if (it.second >= last_finish_time) { cnt++; last_finish_time = it.first; } 30 | } 31 | cout << cnt; 32 | } 33 | ``` 34 | # Complexity 35 | - `O(n.Log(n))` 36 | 37 | # Variations Of This Problem 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Algorithms Design 🌟/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Algorithms Design 🌟/README.md -------------------------------------------------------------------------------- /Backtracking/23 out of 5/README.md: -------------------------------------------------------------------------------- 1 | # 23 out of 5 2 | - ### [23 out of 5 | VJudge](https://vjudge.net/contest/485599#problem/A) 3 | - ### [23 out of 5 | UVA](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1285) 4 | 5 | ## Solution 6 | ```cpp 7 | bool ok = false; 8 | void solve(int i, int cur, vector& v) { 9 | if (i == 5) { 10 | if (cur == 23) { ok = true; } 11 | return; 12 | } 13 | solve(i + 1, cur + v[i], v); 14 | solve(i + 1, cur - v[i], v); 15 | solve(i + 1, cur * v[i], v); 16 | } 17 | void doIt() { 18 | while (true) { 19 | ok = false; 20 | vectorv(5); 21 | bool fail = true; 22 | for (auto& it : v) { 23 | cin >> it; 24 | if (it != 0) { fail = false; } 25 | } 26 | if (fail) { break; } 27 | sort(all(v)); 28 | do { 29 | solve(1, v[0], v); 30 | if (ok) { cout << "Possible\n"; break; } 31 | } while (next_permutation(all(v))); 32 | 33 | if (!ok) cout << "Impossible\n"; 34 | } 35 | } 36 | ``` 37 | 38 | ## Solution [recursive function return bool] 39 | ```cpp 40 | bool solve(int i, int cur, vector& v) { 41 | if (i == 5) { 42 | return cur == 23; 43 | } 44 | bool a = solve(i + 1, cur + v[i], v); 45 | bool b = solve(i + 1, cur * v[i], v); 46 | bool c = solve(i + 1, cur - v[i], v); 47 | return a or b or c; 48 | } 49 | void doIt() { 50 | while (true) { 51 | vectorv(5); 52 | bool fail = true; 53 | for (auto& it : v) { 54 | cin >> it; 55 | if (it != 0) { fail = false; } 56 | } 57 | if (fail) { break; } 58 | sort(all(v)); 59 | bool ok = solve(1, v[0], v); 60 | do { 61 | ok = solve(1, v[0], v); 62 | if (ok) { cout << "Possible\n"; break; } 63 | } while (next_permutation(all(v))); 64 | if (!ok) { cout << "Impossible\n"; } 65 | } 66 | } 67 | ``` 68 | -------------------------------------------------------------------------------- /Backtracking/2D Grid/Basic Number of Paths/README.md: -------------------------------------------------------------------------------- 1 | # Number of Paths 2 | - [Number of paths | GeeksForGeeks](https://practice.geeksforgeeks.org/problems/number-of-paths0926/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article) 3 | # Solution 4 | ```cpp 5 | int n, m; 6 | int generatePaths(int i, int j) { 7 | int count = 0; 8 | if (i == n - 1 and j == m - 1) { return 1; } 9 | if (i + 1 < n) { 10 | count += generatePaths(i + 1, j); 11 | } 12 | if (j + 1 < m) { 13 | count += generatePaths(i, j + 1); 14 | } 15 | return count; 16 | } 17 | void doIt() { 18 | cin >> n >> m; 19 | cout << generatePaths(0, 0); 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /Backtracking/2D Grid/Count Number of Valid Paths from A to B in Grid/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Backtracking/2D Grid/Count Number of Valid Paths from A to B in Grid/README.md -------------------------------------------------------------------------------- /Backtracking/2D Grid/Describe All Valid Paths From A to B/README.md: -------------------------------------------------------------------------------- 1 | # Describe All Valid Paths From A to B 2 | ![image](https://user-images.githubusercontent.com/99830416/236564105-bc55224e-5067-45ba-a5ee-6d8aefc298b5.png) 3 | 4 | # Problem Statement 5 | **Given 2D grid with free and blocked cells. Print all possible paths to reach from top left point to bottom right point in the grid. You can move only right or down** 6 | 7 | # Solution 8 | ```cpp 9 | int n, m; 10 | string path; 11 | void generatePaths(int i, int j, vector>grid) { 12 | if (i == n - 1 and j == m - 1) { 13 | cout << path << "\n"; 14 | return; 15 | } 16 | 17 | if (j + 1 < m and grid[i][j + 1] != '#') { 18 | path += 'R'; 19 | generatePaths(i, j + 1, grid); 20 | path.pop_back(); 21 | } 22 | if (i + 1 < n and grid[i + 1][j] != '#') { 23 | path += 'D'; 24 | generatePaths(i + 1, j, grid); 25 | path.pop_back(); 26 | } 27 | } 28 | int main() { 29 | cin >> n >> m; 30 | vector> V(n, vector(m)); 31 | for (int i = 0; i < n; i++) { 32 | for (int j = 0; j < m; j++) { 33 | cin >> V[i][j]; 34 | } 35 | } 36 | generatePaths(0, 0, V); 37 | } 38 | ``` 39 | ### Test Cases 40 | ``` 41 | 4 4 42 | . . # . 43 | . . . . 44 | . . # . 45 | . . # . 46 | ``` 47 | ``` 48 | RDRRDD 49 | DRRRDD 50 | ``` 51 | 52 | ``` 53 | 4 4 54 | . . # . 55 | . . . . 56 | . # . . 57 | . . # . 58 | ``` 59 | ``` 60 | RDRRDD 61 | RDRDRD 62 | DRRRDD 63 | DRRDRD 64 | ``` 65 | 66 | ## Conclusion 67 | **The path alwayes will contains `m - 1` R and `n - 1` D** 68 | -------------------------------------------------------------------------------- /Backtracking/2D Grid/Generate all Paths from A to B in Grid/README.md: -------------------------------------------------------------------------------- 1 | # Generate all Paths from A to B in 2D Grid 2 | ![image](https://user-images.githubusercontent.com/99830416/236549567-90b016fa-8be8-42c1-bdd5-8b60a0a7494f.png) 3 | 4 | ### [Generating the paths | Codeforces](https://codeforces.com/group/gA8A93jony/contest/270592/problem/N) 5 | 6 | 7 | 8 | # Solution 9 | ```cpp 10 | int n, m; 11 | vector path; 12 | set>ans; 13 | void printPath(vectorv) { 14 | for (auto it : v) { 15 | cout << it << " "; 16 | } 17 | cout << "\n"; 18 | } 19 | void generatePaths(vector>v, int i, int j) { 20 | path.push_back(v[i][j]); 21 | if (i == n - 1 and j == m - 1) { 22 | //printPath(path); 23 | ans.insert(path); 24 | return; 25 | } 26 | // go right (increase j) 27 | if (j + 1 < m) { 28 | generatePaths(v, i, j + 1); 29 | // path ends & backtrack 30 | path.pop_back(); 31 | } 32 | // go down (increase i) 33 | if (i + 1 < n) { 34 | generatePaths(v, i + 1, j); 35 | // path ends & backtrack 36 | path.pop_back(); 37 | } 38 | } 39 | int main() { 40 | cin >> n >> m; 41 | vector>v(n, vector(m)); 42 | for (int i = 0; i < n; i++) { 43 | for (int j = 0; j < m; j++) { 44 | cin >> v[i][j]; 45 | } 46 | } 47 | generatePaths(v, 0, 0); 48 | cerr << "--\n"; 49 | for (auto it : ans) { 50 | for (int i = 0; i < it.size(); i++) { 51 | cout << it[i] << " "; 52 | } 53 | cout << "\n"; 54 | } 55 | } 56 | ``` 57 | -------------------------------------------------------------------------------- /Backtracking/All Paths From Source to Target/README.md: -------------------------------------------------------------------------------- 1 | # All Paths From Source to Target 2 | ### [All Paths From Source to Target | Leetcode](https://leetcode.com/problems/all-paths-from-source-to-target/) 3 | ## Solution 4 | ```cpp 5 | 6 | ``` -------------------------------------------------------------------------------- /Backtracking/Apple Division/README.md: -------------------------------------------------------------------------------- 1 | # Apple Division 2 | ### [Apple Division | CSES](https://cses.fi/problemset/task/1623) 3 | 4 | ## Approach 5 | 6 | ## Solution 7 | ```cpp 8 | ll mn = 1e9 + 8; 9 | void solve(int i, ll sum1, ll overall, vector& v, int n) { 10 | if (i == n) { 11 | ll sum2 = overall - sum1; 12 | mn = min(mn, abs(sum1 - sum2)); 13 | return; 14 | } 15 | solve(i + 1, sum1 + v[i], overall, v, n); //take 16 | solve(i + 1, sum1, overall, v, n); //leave 17 | } 18 | void doIt() { 19 | int n; cin >> n; 20 | vectorv(n); 21 | ll sum = 0; 22 | for (auto& it : v) { cin >> it; sum += it; } 23 | solve(0, 0, sum, v, n); 24 | cout << mn; 25 | } 26 | ``` 27 | -------------------------------------------------------------------------------- /Backtracking/CD/README.md: -------------------------------------------------------------------------------- 1 | # CD 2 | ### [CD | Vjudge](https://vjudge.net/contest/485599#problem/B) 3 | - Backtracking problem. Get the best path 4 | 5 | # Solution 6 | ```cpp 7 | vectorsongs, bestPath; 8 | int mx; 9 | void solve(int i, int cur, int capacity, vector&path) { 10 | if (i == songs.size()) { 11 | if (cur > mx) { 12 | mx = cur; 13 | bestPath = path; 14 | } 15 | return; 16 | } 17 | if (cur + songs[i] <= capacity) { 18 | path.push_back(songs[i]); 19 | solve(i + 1, cur + songs[i], capacity, path); // Take this current song 20 | path.pop_back(); // Backtrack and remove the current song from the path 21 | } 22 | 23 | solve(i + 1, cur, capacity, path); // Skip this song 24 | } 25 | int main() { 26 | int n; 27 | while (cin >> n) { 28 | mx = 0; 29 | int m; cin >> m; 30 | for (int i = 0; i < m; i++) { 31 | int a; cin >> a; 32 | songs.push_back(a); 33 | } 34 | vectorpath; 35 | solve(0, 0, n, path); 36 | for (auto& it : bestPath) { cout << it << " "; } 37 | cout << "sum:" << mx << "\n"; 38 | songs.clear(); 39 | bestPath.clear(); 40 | } 41 | } 42 | ``` 43 | -------------------------------------------------------------------------------- /Backtracking/Combination Sum/README.md: -------------------------------------------------------------------------------- 1 | # Combination Sum 2 | ### [Combination Sum | Leetcode](https://leetcode.com/problems/combination-sum/) 3 | 4 | ## Solution 5 | ```cpp 6 | vectorpath; 7 | vector>paths; 8 | void solve(int i, int cur, int target, vector& v) { 9 | if (i == v.size()) { return; } 10 | if (cur > target) { return; } 11 | if (cur == target) { 12 | paths.push_back(path); 13 | return; 14 | } 15 | path.push_back(v[i]); 16 | solve(i, cur + v[i], target, v); 17 | path.pop_back(); 18 | 19 | solve(i + 1, cur, target, v); 20 | } 21 | vector> combinationSum(vector& candidates, int target) { 22 | solve(0,0,target, candidates); 23 | return paths; 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /Backtracking/Palindrome Partitioning/README.md: -------------------------------------------------------------------------------- 1 | # Palindrome Partitioning 2 | ### [Palindrome Partitioning | Leetcode](https://leetcode.com/problems/palindrome-partitioning/) 3 | 4 | ## Solution 5 | ```cpp 6 | 7 | 8 | ``` -------------------------------------------------------------------------------- /Backtracking/Partition to K Equal Sum Subsets/README.md: -------------------------------------------------------------------------------- 1 | # Partition to K Equal Sum Subsets 2 | ### [Partition to K Equal Sum Subsets | Leetcode](https://leetcode.com/problems/partition-to-k-equal-sum-subsets/) 3 | ## Solution 4 | ```cpp 5 | 6 | ``` -------------------------------------------------------------------------------- /Backtracking/Permutations/README.md: -------------------------------------------------------------------------------- 1 | # Permutations 2 | ## Resources 3 | - [Permutations | LeetCode](https://leetcode.com/problems/permutations/) 4 | - [Toutorial | Eng.Ahmed Ali](https://www.youtube.com/watch?v=bj2Qdu08XYw&t=316s) 5 | -------------------------------------------------------------------------------- /Backtracking/README.md: -------------------------------------------------------------------------------- 1 | # Backtracking 2 | 3 | 4 | -------------------------------------------------------------------------------- /Backtracking/Subsets/README.md: -------------------------------------------------------------------------------- 1 | # Subsets 2 | ### [Subsets | Leetcode](https://leetcode.com/problems/subsets/) 3 | 4 | ## Solution 5 | ```cpp 6 | 7 | ``` -------------------------------------------------------------------------------- /Backtracking/Target Sum/README.md: -------------------------------------------------------------------------------- 1 | # Target Sum 2 | ### [Target Sum | Leetcode](https://leetcode.com/problems/target-sum/) 3 | 4 | ## Solution 5 | ```cpp 6 | int solve(int i, int cur, int target,vector& v) { 7 | if (i == v.size()) { 8 | if (cur == target) { return 1; } 9 | else { return 0; } 10 | } 11 | int a = solve(i + 1, cur + v[i], target, v); 12 | int b = solve(i + 1, cur - v[i], target, v); 13 | return a + b; 14 | } 15 | void doIt() { 16 | int n, target; 17 | cin >> n >> target; 18 | vectorv(n); 19 | for (auto& it : v) { cin >> it; } 20 | int ans = solve(0, 0, target, v); 21 | cout << ans << "\n"; 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /Backtracking/Tavas and SaDDas/README.md: -------------------------------------------------------------------------------- 1 | # Tavas and SaDDas 2 | ![image](https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/d88d669e-d764-4ba1-989c-29efc5f68eb2) 3 | 4 | - ## [Tavas and SaDDas | Codeforces](https://codeforces.com/problemset/problem/535/B) 5 | - ## [Tavas and SaDDas | vjudege](https://vjudge.net/contest/485599#problem/E) 6 | 7 | ## Solution 8 | ```cpp 9 | 10 | 11 | ``` 12 | -------------------------------------------------------------------------------- /Backtracking/Tavas and SaDDas/Tavas and SaDDas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Backtracking/Tavas and SaDDas/Tavas and SaDDas.png -------------------------------------------------------------------------------- /Backtracking/Transforme A To B/README.md: -------------------------------------------------------------------------------- 1 | # Transformation From A To B 2 | ## [Transformation From A To B | Codeforces](https://codeforces.com/contest/727/problem/A) 3 | 4 | ## Backtracking Approach 5 | - We need to make a equal to b. 6 | - We need to keep track of the path so we will use backtracking 7 | 8 | ## Graph Approach 9 | - This problem has also a graph approach can be found at `Algorithms Design/Graph/Problems` 10 | 11 | ## Backtracking Solution 12 | ```cpp 13 | vectorpath, bestPath; 14 | bool valid = false; 15 | void solve(ll a, int b) { 16 | if (a == b) { 17 | valid = true; 18 | bestPath = path; 19 | return; 20 | } 21 | if (a > b) { 22 | return; 23 | } 24 | // backtracking 25 | path.push_back(a * 2); 26 | solve(a * 2, b); 27 | path.pop_back(); 28 | 29 | path.push_back(a * 10 + 1); 30 | solve(a * 10 + 1, b); 31 | path.pop_back(); 32 | } 33 | int main() { 34 | int a, b; 35 | cin >> a >> b; 36 | path.push_back(a); 37 | solve(a, b); 38 | if (valid) { 39 | cout << "YES\n"; 40 | cout << bestPath.size() << "\n"; 41 | for (auto it : bestPath) { cout << it << " "; } 42 | } 43 | if (!valid) { no; } 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /Bit Manipulation/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Bit Manipulation/README.md -------------------------------------------------------------------------------- /Bit Manipulation/Subsets/README.md: -------------------------------------------------------------------------------- 1 | # Subsets 2 | ### [Subsets | Leetcode](https://leetcode.com/problems/subsets/) 3 | 4 | ## Solution 5 | ```cpp 6 | bool getBit(long long n, int index) { 7 | return ((n >> index) & 1); 8 | } 9 | vector> subsets(vector& nums) { 10 | int n = nums.size(); 11 | vector>ans; 12 | for(int i=0; i < (1<v; 14 | for(int j=0 ;j < n;j++){ 15 | if (getBit(i, j)) 16 | { 17 | v.push_back(nums[j]); 18 | } 19 | } 20 | ans.push_back(v); 21 | } 22 | return ans; 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Algorithms 2 | ## [Algorithms Play List](https://youtube.com/playlist?list=PLNukXZDkTp4Pv-VcC9F9Xs6tiGZIt6hl-) 3 | 4 | ![عالم-الرياضيات-الخوارزمي](https://user-images.githubusercontent.com/99830416/218716222-201d2f86-1dc1-4f07-97ff-8d8321083c95.jpg) 5 | 6 | -------------------------------------------------------------------------------- /Recursion/Problems/All K Subarrays/README.md: -------------------------------------------------------------------------------- 1 | # All K Subarrays 2 | 3 | # Problem statement 4 | Given array `a` of size `n` and number `k` find all subarrays can be generated from array a of lenght k 5 | 6 | # Solution 7 | ```cpp 8 | vectorv; 9 | int k; 10 | void rec(vectorvec) { 11 | if (vec.size() == k) { 12 | for (auto it : vec) { 13 | cout << it << " "; 14 | } 15 | cout << "\n"; 16 | return; 17 | } 18 | for (int i = 0; i < v.size(); i++) { 19 | vec.push_back(v[i]); 20 | rec(vec); 21 | vec.pop_back(); 22 | } 23 | } 24 | int main() { 25 | int n; cin >> n >> k; 26 | for (int i = 0; i < n; i++) { 27 | int in; cin >> in; v.push_back(in); 28 | } 29 | rec({}); 30 | } 31 | ``` 32 | 33 | ## Notes 34 | - Here we update vector glopally before the recursive call so the vector will be seen over all function calls but we need each call has its version so after adding element in vector, recurse and reach the base case of the current call we should `pop` this element 35 | -------------------------------------------------------------------------------- /Recursion/Problems/All K Substrings/README.md: -------------------------------------------------------------------------------- 1 | ```cpp 2 | vectorv; 3 | int k; 4 | void rec(string s) { 5 | if (s.size() == k) { 6 | cout << s << "\n"; 7 | return; 8 | } 9 | for (int i = 0; i < v.size(); i++) { 10 | rec(s+v[i]); 11 | } 12 | } 13 | int main() { 14 | int n; cin >> n >> k; 15 | for (int i = 0; i < n; i++) { 16 | char ch; cin >> ch; v.push_back(ch); 17 | } 18 | rec(""); 19 | } 20 | ``` 21 | ## Notes 22 | - we update string in the `function call` `rec(s + ch)` not glopally this means that each recursion call has its string version 23 | -------------------------------------------------------------------------------- /Recursion/Problems/Generate Parentheses/README.md: -------------------------------------------------------------------------------- 1 | # [Generate Parentheses](https://leetcode.com/problems/generate-parentheses/) 2 | 3 | # PRE TEST 4 | `Create function that generate all possible Parentheses of length n * 2` 5 | `Build Tree to get all possible answers` 6 | ```cpp 7 | int n; 8 | void generate(string s, int n) { 9 | if (s.size() == n*2) { cout << s << "\n"; return; } 10 | generate(s + '(', n); 11 | generate(s + ')', n); 12 | } 13 | int main() { 14 | cin >> n; 15 | generate("", n); 16 | } 17 | ``` 18 | # Hint 19 | - If we have `n = 3` so string size = 3 * 2 = 6, `L = 3`, `R = 3` 20 | - I can put any L while L > 0 21 | - At any call `L` should be greater than or equal `R` to create valid Parentheses else the recursion must stop 22 | 23 | # Solution 24 | ```cpp 25 | int n; 26 | void generate(string s, int l , int r) { 27 | if (s.size() == n*2) { cout << s << "\n"; return; } 28 | 29 | if (l > 0) 30 | generate(s + '(', l - 1, r); 31 | 32 | if (r > l) 33 | generate(s + ')', l, r - 1); 34 | } 35 | int main() { 36 | cin >> n; 37 | generate("", n, n); 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /Recursion/Problems/Knapsack/README.md: -------------------------------------------------------------------------------- 1 | # [Knapsack](https://codeforces.com/group/gA8A93jony/contest/270592/problem/J) 2 | 3 | # Solution [recursive] 4 | ```cpp 5 | int n, w; 6 | vector>v; 7 | int mx = 0; 8 | void solve(int index, int curval, int remain_weight) { 9 | if (index == n) { if (remain_weight >= 0) mx = max(mx, curval); return; } 10 | if (remain_weight - v[index].first >= 0) 11 | solve(index + 1, curval + v[index].second, remain_weight-v[index].first); 12 | solve(index + 1, curval, remain_weight); 13 | } 14 | void you_can_do_it() { 15 | cin >> n >> w; 16 | for (int i = 0; i < n; i++) { 17 | int w, val; 18 | cin >> w >> val; 19 | v.push_back({ w, val }); 20 | } 21 | solve(0, 0, w); 22 | cout << mx ; 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /Recursion/Problems/Power Set/README.md: -------------------------------------------------------------------------------- 1 | # [Power Set](https://leetcode.com/problems/subsets/) 2 | # Solution [Bitmask] 3 | ```cpp 4 | bool getBit(long long n, int index) { 5 | return ((n >> index) & 1); 6 | } 7 | vector> subsets(vector& nums) { 8 | int n = nums.size(); 9 | vector>ans; 10 | for(int i=0; i < (1<v; 12 | for(int j=0 ;j < n;j++){ 13 | if (getBit(i, j)) 14 | { 15 | v.push_back(nums[j]); 16 | } 17 | } 18 | ans.push_back(v); 19 | } 20 | return ans; 21 | } 22 | ``` 23 | # Solution [Backtracking] 24 | ```cpp 25 | 26 | 27 | 28 | ``` 29 | -------------------------------------------------------------------------------- /Recursion/Problems/Power Sum/README.md: -------------------------------------------------------------------------------- 1 | # [Power Sum](https://www.hackerrank.com/challenges/the-power-sum/problem?isFullScreen=true) 2 | # Hint 3 | ### `Take or Leave` Sum = [1^n or 0] + [2^n or 0] + [3^n or 0] + [..] 4 | # Solution 5 | ```cpp 6 | ll x, n, cnt; 7 | void solve(ll i, ll sum) { 8 | if (sum > x) { return; } 9 | if (i == 50) { if (sum == x) { cnt++; } return; } 10 | solve(i + 1, sum + pow(i, n)); 11 | solve(i + 1, sum); 12 | } 13 | int main() { 14 | cnt = 0; 15 | cin >> x >> n; 16 | solve(1, 0); 17 | cout << cnt; 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /Recursion/Problems/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Recursion/Problems/README.md -------------------------------------------------------------------------------- /Recursion/Problems/binary strings/README.md: -------------------------------------------------------------------------------- 1 | # Binary strings 2 | # Problem statement 3 | Given a number `n` find all binary sequances of length `2n` such that the sum of first n bits equals to the sum of second n bits 4 | 5 | # Test case 6 | - input: n = 1 7 | - output: 00, 11 8 | 9 | # Solution 10 | 11 | ```cpp 12 | int n; 13 | void rec(string s, int sum1, int sum2) { 14 | // we need to create 2 branches 0, 1 15 | if (s.size() == 2 * n) { 16 | if (sum1 == sum2) { cout << s << "\n"; } 17 | return; 18 | } 19 | rec(s + '0', sum1, sum2); 20 | if (s.size() < n) { 21 | rec(s + '1', sum1 + 1, sum2); 22 | } 23 | else { 24 | rec(s + '1', sum1, sum2 + 1); 25 | } 26 | } 27 | int main() { 28 | cin >> n; 29 | rec ("", 0, 0); 30 | } 31 | ``` 32 | -------------------------------------------------------------------------------- /Recursion/README.md: -------------------------------------------------------------------------------- 1 | # Recursion 2 | # What is Recursion 3 | - Process in which function calls its self directly or indirectly. This function called `recursive function` 4 | 5 | # Recursion Components 6 | 7 | ## `State` 8 | - **Definition of the current problem [Params]** 9 | ## `Transition` 10 | - **Movement: Move the recursion from state to another state** 11 | - **Each transition create branch of tree** 12 | ## `Base case` 13 | - **Stopping Condition** 14 | ## `Tree` 15 | - **Each node has n branches [n number of transitions] and the leaves are the base case condition** 16 | - **Use** [**Recursion Tree Visualizer**](https://recursion.vercel.app/ "‌") 17 | 18 | 19 | # Recursion Types 20 | - Direct recurion 21 | ```cpp 22 | void directrec(){ 23 | // code 24 | directrec() 25 | // code 26 | } 27 | ``` 28 | 29 | - Indirect recursion 30 | ```cpp 31 | void indirectrec1(){ 32 | indirectrec2() 33 | } 34 | void indirectrec2(){ 35 | indirectrec1() 36 | } 37 | ``` 38 | 39 | 40 | # Simple Example 41 | ### `sum numbers from 1 to n` 42 | ```cpp 43 | int rec(int n){ 44 | if (n == 1) { return n;} 45 | return n + rec(n-1); 46 | } 47 | int main(){ 48 | int n; cin >> n; 49 | cout << rec(3); 50 | } 51 | ``` 52 | 53 | ### `Fibonacci` 54 | ```cpp 55 | int fib(int n) { 56 | if (n < 2) { return n; } 57 | return fib(n - 1) + fib(n - 2); 58 | } 59 | int main(){ 60 | int n; cin >> n; 61 | cout << fib(n); 62 | } 63 | ``` 64 | 65 | # How to think Recursively ? 66 | - `Build Tree`. Tree that get all possible answers and filter your answers 67 | - `Bulding Cubes`. Build the base cube [Base case] and compose the rest of cubes to get the final formed cube. 68 | - `Take or Leave` 69 | 70 | 71 | # Where to solve 72 | - ### [Assuit Sheet [Basic]](https://codeforces.com/group/MWSDmqGsZm/contest/223339) 73 | - ### [ProgVar.Fun](https://progvar.fun/problemsets/recursion) 74 | - ### [Hacker Rank](https://www.hackerrank.com/domains/algorithms?filters%5Bsubdomains%5D%5B%5D=recursion) 75 | - ### Problems Folder in this directory 76 | -------------------------------------------------------------------------------- /Recursion/Recursion Components/README.md: -------------------------------------------------------------------------------- 1 | # Recursion 2 | # `Recursion Components` 3 | - ### Parameters passed to rec function [stored at **stack**] 4 | - ### Recursive call [automatically created stack frame (space in stack) save info of called function] 5 | - ### Stack frame components: 6 | `1- Return address` 7 | `2- Params` 8 | `3- Local vars` 9 | `4- Return value` 10 | - ### Unfinished business [Post code] 11 | `code will not be excted until recursion ends` 12 | - ### Returned value from base case 13 | `Release stack frame` 14 | 15 | 16 | # 17 | ![image](https://user-images.githubusercontent.com/99830416/221371787-356adb3e-491c-4df2-9312-160802ae6d21.png) 18 | -------------------------------------------------------------------------------- /Sorting Algorithms/Bubble Sort/README.md: -------------------------------------------------------------------------------- 1 | # Bubble Sort 2 | ![0_nh6F_qERbgD3xmV-](https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/863e0e5a-13fc-4603-a85f-2d5dedb2abd8) 3 | 4 | # Algorithm 5 | - Check for each 2 consecutive elements and swap them if the first is greater than the second 6 | 7 | # Code 8 | ```cpp 9 | void bubbleSort(vector& v) { 10 | int n = v.size(); 11 | for (int i = 0; i < n - 1; i++) { 12 | for (int j = 0; j < n - i - 1; j++) { 13 | if (v[j] > v[j + 1]) { swap(v[j], v[j + 1]); } 14 | } 15 | } 16 | } 17 | ``` 18 | 19 | # Time Complexity 20 | - Worst Case: Θ(n^2) 21 | - Best Case: Θ(n^2) 22 | - Average Case: Θ(n^2) 23 | 24 | # Can we do better ? 25 | `YES`. If no swap occures at one iteration of the outer loop then we can stop the algorithm 26 | - Best Case : Θ(n) Already sorted array 27 | 28 | 29 | # Advatages 30 | - O(n) in the best case (sorted array) 31 | - 32 | # Disadvantages 33 | - O(n^2) in other cases 34 | - Max number of swaps 35 | - 36 | -------------------------------------------------------------------------------- /Sorting Algorithms/Insertion Sort/README.md: -------------------------------------------------------------------------------- 1 | # Insertion sort 2 | ![1_VxgYISRmyEOCPGMbBh8VFg](https://user-images.githubusercontent.com/99830416/218607314-4181b809-c3fc-47d0-8042-04304f00c498.gif) 3 | ![1_UpB6EEJZB8HihhERZWxC-A](https://user-images.githubusercontent.com/99830416/218608524-bf4fe665-fd37-4ace-ae8b-6488be3cf52b.gif) 4 | 5 | ```cs 6 | static void InsertionSort(int[]arr) 7 | { 8 | for(int i = 1; i < arr.Length; i++) 9 | { 10 | int key = arr[i]; 11 | int j = i - 1; 12 | while (true) 13 | { 14 | if (j < 0 || arr[j] <= key) 15 | { 16 | break; 17 | } 18 | arr[j + 1] = arr[j]; 19 | j--; 20 | } 21 | arr[j + 1] = key; 22 | } 23 | } 24 | ``` 25 | 26 | ## `Time complexity` 27 | ### Best Case 28 | 29 | - Already sorted array 30 | - Inner loop never excuted O(1) 31 | - Final Order : O(N) 32 | 33 | ### Worst Case 34 | 35 | - Array sorted reversely 36 | - Inner loop excuted for all iterations of the outer loop O(N) 37 | - Final Order : O(N^2) 38 | 39 | # Advantages 40 | - Fastest on small inputs (les than 50) 41 | - Fastest on nearly sorted array nearly take `O(n)` 42 | 43 | # Disadvantages 44 | - O(n^2) in other cases 45 | -------------------------------------------------------------------------------- /Sorting Algorithms/Merge Sort/README.md: -------------------------------------------------------------------------------- 1 | # Merge Sort 2 | 3 | # Approach 4 | `Divide and Conquer` approach 5 | - `Divide` Split array into 2 halves 6 | - `Conquer` Recursively solve 2 sub-arrayes 7 | - `Combine` Merge tow sorted aub-arrays of each node 8 | 9 | # Code 10 | ```cpp 11 | void merge(vector& v, int left, int right, int mid) 12 | { 13 | // copy the right array in array R and left array to L 14 | int n1 = mid - left + 1; 15 | int n2 = right - mid; 16 | int left_pointer = left, right_pointer2 = mid + 1; 17 | vectorL(n1 + 1), R(n2 + 1); 18 | for (int i = 0; i < n1; i++) { 19 | L[i] = v[left_pointer]; 20 | left_pointer++; 21 | } 22 | for (int i = 0; i < n2; i++) { 23 | R[i] = v[right_pointer2]; 24 | right_pointer2++; 25 | } 26 | L[n1] = INT_MAX; R[n2] = INT_MAX; 27 | // Update the original array 28 | int ptr1 = 0, ptr2 = 0; 29 | for (int i = left; i <= right; i++) { 30 | if (L[ptr1] <= R[ptr2]) { 31 | v[i] = L[ptr1]; 32 | ptr1++; 33 | } 34 | else { 35 | v[i] = R[ptr2]; 36 | ptr2++; 37 | } 38 | } 39 | } 40 | void mergeSort(vector&v, int left, int right) 41 | { 42 | if (left >= right) { return; } 43 | int mid = (left + right) / 2; 44 | mergeSort(v, left, mid); 45 | mergeSort(v, mid + 1, right); 46 | merge(v, left, right, mid); 47 | } 48 | ``` 49 | # Complexity 50 | 51 | - T(n) = 2T(n/2) + O(n) 52 | - Solve using Master `O(N.Log(N))` **In all cases.** 53 | 54 | # Advantages 55 | - O(N.Log(n)) in all cases 56 | - Can be parallized 57 | - Work well in case of small RAM 58 | # Disadvantages 59 | - Requires extra space `array of size n` cause of **Out Place** -> sort in another array. `Can we do better?`
60 | YES, we can use extra array of size n/2 not n. We will move the first sub-array into this array and update the original one.🤝🏻 61 | 62 | 63 | -------------------------------------------------------------------------------- /Sorting Algorithms/README.md: -------------------------------------------------------------------------------- 1 | # Sorting Wars 2 | ## To check your Algo correctness submit [Sorting Problem](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/H) 3 | ![image](https://user-images.githubusercontent.com/99830416/226123918-49b395c0-2f22-43da-aa1a-634e3ac56b9a.png) 4 | -------------------------------------------------------------------------------- /Sorting Algorithms/Selection Sort/README.md: -------------------------------------------------------------------------------- 1 | # Selection Sort 2 | ![0_R0MHc4Hd26q6FPut](https://github.com/Abdelrhman-Sayed70/Algorithms/assets/99830416/b46cfecf-8371-4f78-ac38-3ca46e8dfb40) 3 | 4 | # Algorithm 5 | - From index i search for the min value in the remaining array and swap it with value at index i. 6 | 7 | # Code 8 | ```cpp 9 | void selectionSort(vector&v) { 10 | int n = v.size(); 11 | int mn_index; 12 | for (int i = 0; i < n - 1; i++) { 13 | mn_index = i; 14 | for (int j = i + 1; j < n; j++) { 15 | if (v[j] < v[mn_index]) { 16 | mn_index = j; 17 | } 18 | } 19 | swap(v[i], v[mn_index]); 20 | } 21 | } 22 | ``` 23 | 24 | # Time Complexity 25 | - Best Case : Θ(n^2) 26 | - Worst Case : Θ(n^2) 27 | - Average Case : Θ(n^2) 28 | 29 | # Advantages 30 | - Min number of swaps O(n) swaps [memory read & write] 31 | 32 | # DisAdvantages 33 | - O(n^2) in all Cases 34 | -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting Wars/README.md: -------------------------------------------------------------------------------- 1 | # Sorting Wars 2 | **Here we will know which sorting algorithm is proper for the problem. So you need to be aware about sorting algorithms and what is flow of each algo** 3 | 4 | # Which sorting algo is proper ? 5 | 6 | ### 1. Sort a file with huge records with tiny keys 7 | - Files are huge so we need to minimize number of swaps (exhange) so the most proper algo is **`Selection Sort`** 8 | 9 | --- 10 | ### 2. Sort huge numebr of records of small size (phone company) 11 | - **`Quick Sort`** or **`Merge Sort`** 12 | 13 | --- 14 | ### 3. Sort Database that is almost ordred 15 | - **`Insertion Sort`** Take almost O(n) 16 | --- 17 | 18 | ### 4. Double check on sorted file 19 | - **`Insertion Sort`** without any changes and O(n) Complexity 20 | -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/FileContentIndex/4048ebce-37cd-4845-a0c1-6720acfe5a5b.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/FileContentIndex/4048ebce-37cd-4845-a0c1-6720acfe5a5b.vsidx -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/FileContentIndex/81f26b47-1e00-47d1-b4e1-7b5aa39c3d10.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/FileContentIndex/81f26b47-1e00-47d1-b4e1-7b5aa39c3d10.vsidx -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/FileContentIndex/read.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/FileContentIndex/read.lock -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/v17/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/v17/.suo -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/v17/Browse.VC.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/v17/Browse.VC.db -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/v17/ipch/AutoPCH/2dc6f71f2d75eb9b/SORTING_ALGORITHMS.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/v17/ipch/AutoPCH/2dc6f71f2d75eb9b/SORTING_ALGORITHMS.ipch -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/v17/ipch/AutoPCH/32a4344b4eec7333/SORTING_ALGORITHMS.ipch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/.vs/Sorting_Algorithms/v17/ipch/AutoPCH/32a4344b4eec7333/SORTING_ALGORITHMS.ipch -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33213.308 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Sorting_Algorithms", "Sorting_Algorithms\Sorting_Algorithms.vcxproj", "{EC3F3595-0ADC-4C4B-9FF2-E5F354985A2C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {EC3F3595-0ADC-4C4B-9FF2-E5F354985A2C}.Debug|x64.ActiveCfg = Debug|x64 17 | {EC3F3595-0ADC-4C4B-9FF2-E5F354985A2C}.Debug|x64.Build.0 = Debug|x64 18 | {EC3F3595-0ADC-4C4B-9FF2-E5F354985A2C}.Debug|x86.ActiveCfg = Debug|Win32 19 | {EC3F3595-0ADC-4C4B-9FF2-E5F354985A2C}.Debug|x86.Build.0 = Debug|Win32 20 | {EC3F3595-0ADC-4C4B-9FF2-E5F354985A2C}.Release|x64.ActiveCfg = Release|x64 21 | {EC3F3595-0ADC-4C4B-9FF2-E5F354985A2C}.Release|x64.Build.0 = Release|x64 22 | {EC3F3595-0ADC-4C4B-9FF2-E5F354985A2C}.Release|x86.ActiveCfg = Release|Win32 23 | {EC3F3595-0ADC-4C4B-9FF2-E5F354985A2C}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {8892BA8E-D088-4E5C-BF6C-82CFDAB586BF} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/Sorting_Algorithms.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void insertionSort(vector&arr) 4 | { 5 | for (int i = 1; i < arr.size(); i++){ 6 | int key = arr[i]; 7 | int j = i - 1; 8 | while (true){ 9 | if (j < 0 || arr[j] <= key){ 10 | break; 11 | } 12 | arr[j + 1] = arr[j]; 13 | j--; 14 | } 15 | arr[j + 1] = key; 16 | } 17 | } 18 | void selectionSort(vector&v) 19 | { 20 | int n = v.size(); 21 | int mn_index; 22 | for (int i = 0; i < n - 1; i++) { 23 | mn_index = i; 24 | for (int j = i + 1; j < n; j++) { 25 | if (v[j] < v[mn_index]) { 26 | mn_index = j; 27 | } 28 | } 29 | swap(v[i], v[mn_index]); 30 | } 31 | } 32 | void bubbleSort(vector& v) 33 | { 34 | int n = v.size(); 35 | for (int i = 0; i < n - 1; i++) { 36 | for (int j = 0; j < n - i - 1; j++) { 37 | if (v[j] > v[j + 1]) { swap(v[j], v[j + 1]); } 38 | } 39 | } 40 | } 41 | void merge(vector& v, int left, int right, int mid) 42 | { 43 | // copy the right array in array R and left array to L 44 | int n1 = mid - left + 1; 45 | int n2 = right - mid; 46 | int left_pointer = left, right_pointer2 = mid + 1; 47 | vectorL(n1 + 1), R(n2 + 1); 48 | for (int i = 0; i < n1; i++) { 49 | L[i] = v[left_pointer]; 50 | left_pointer++; 51 | } 52 | for (int i = 0; i < n2; i++) { 53 | R[i] = v[right_pointer2]; 54 | right_pointer2++; 55 | } 56 | L[n1] = INT_MAX; R[n2] = INT_MAX; 57 | // Update the original array 58 | int ptr1 = 0, ptr2 = 0; 59 | for (int i = left; i <= right; i++) { 60 | if (L[ptr1] <= R[ptr2]) { 61 | v[i] = L[ptr1]; 62 | ptr1++; 63 | } 64 | else { 65 | v[i] = R[ptr2]; 66 | ptr2++; 67 | } 68 | } 69 | } 70 | void mergeSort(vector&v, int left, int right) 71 | { 72 | if (left >= right) { return; } 73 | int mid = (left + right) / 2; 74 | mergeSort(v, left, mid); 75 | mergeSort(v, mid + 1, right); 76 | merge(v, left, right, mid); 77 | } 78 | int main() 79 | { 80 | int n; cin >> n; 81 | vectorv(n); 82 | for (auto& it : v) { cin >> it; } 83 | // choose your sorting algo 84 | mergeSort(v, 0, v.size()-1); 85 | for (auto it : v) { cout << it << " "; } 86 | } -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/Sorting_Algorithms.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/Sorting_Algorithms.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/CL.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/CL.command.1.tlog -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/CL.write.1.tlog -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/Sorting_Algorithms.lastbuildstate: -------------------------------------------------------------------------------- 1 | PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.34.31933:TargetPlatformVersion=10.0.22000.0: 2 | Debug|x64|F:\visual_studio_projects\Sorting_Algorithms\| 3 | -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/link.command.1.tlog -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/link.read.1.tlog -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_.ec3f3595.tlog/link.write.1.tlog -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_Algorithms.exe.recipe: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | F:\visual_studio_projects\Sorting_Algorithms\x64\Debug\Sorting_Algorithms.exe 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_Algorithms.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_Algorithms.ilk -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_Algorithms.log: -------------------------------------------------------------------------------- 1 |  Sorting_Algorithms.cpp 2 | F:\visual_studio_projects\Sorting_Algorithms\Sorting_Algorithms\Sorting_Algorithms.cpp(20,21): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data 3 | F:\visual_studio_projects\Sorting_Algorithms\Sorting_Algorithms\Sorting_Algorithms.cpp(34,21): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data 4 | F:\visual_studio_projects\Sorting_Algorithms\Sorting_Algorithms\Sorting_Algorithms.cpp(84,31): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data 5 | Sorting_Algorithms.vcxproj -> F:\visual_studio_projects\Sorting_Algorithms\x64\Debug\Sorting_Algorithms.exe 6 | -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_Algorithms.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/Sorting_Algorithms.obj -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/vc143.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/vc143.idb -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/vc143.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/Sorting_Algorithms/x64/Debug/vc143.pdb -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/x64/Debug/Sorting_Algorithms.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/x64/Debug/Sorting_Algorithms.exe -------------------------------------------------------------------------------- /Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/x64/Debug/Sorting_Algorithms.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Abdelrhman-Sayed70/Algorithms/db43d8d29c4c5fb5f85e39fba5458f82a7ef101b/Sorting Algorithms/Sorting_Algorithms [ALL IN ONE]/x64/Debug/Sorting_Algorithms.pdb -------------------------------------------------------------------------------- /z-Others/FCIS Quizzes/Lec 1/README.md: -------------------------------------------------------------------------------- 1 | # Lec 1 2 | 3 | # `Quizzes` 4 | ![1](https://user-images.githubusercontent.com/99830416/218709781-25021c5b-995f-48e3-a618-fac63414287b.png) 5 | ![2](https://user-images.githubusercontent.com/99830416/218709799-3c21c5e0-b836-4511-98c0-d8c4053363be.png) 6 | ![3](https://user-images.githubusercontent.com/99830416/218709828-151d23bb-8cfe-4dcf-b5fe-bd00420e61bc.png) 7 | 8 | # `Solutions` 9 | ![1](https://user-images.githubusercontent.com/99830416/218711658-e85fad59-5d42-420a-bf4b-f3e8de3599a0.png) 10 | ![2](https://user-images.githubusercontent.com/99830416/218711672-984a3eed-c8dc-4291-a45a-dcbdd1823027.png) 11 | ![3](https://user-images.githubusercontent.com/99830416/218711702-7f6fea30-0fa1-41ee-967d-fd2630b5ce53.png) 12 | -------------------------------------------------------------------------------- /z-Others/FCIS Quizzes/Lec 2/README.md: -------------------------------------------------------------------------------- 1 | # Lec 2 2 | # `Quizzes` 3 | ![image](https://user-images.githubusercontent.com/99830416/221301161-ce994e3c-ae66-41a7-b7d2-7112570c22d2.png) 4 | ![image](https://user-images.githubusercontent.com/99830416/221301068-4eaa3973-a80b-49ab-9484-b6f9f56da51f.png) 5 | ![image](https://user-images.githubusercontent.com/99830416/221301246-b8104ebb-4c62-4c3b-8357-633e3df0dd0e.png) 6 | # `Solutions` 7 | ![image](https://user-images.githubusercontent.com/99830416/221347663-afa835d6-a7c3-4c69-818f-262cf262e835.png) 8 | ![image](https://user-images.githubusercontent.com/99830416/221302727-9a4f88ff-03df-457a-b15e-eb8cd44a6b75.png) 9 | ![image](https://user-images.githubusercontent.com/99830416/221354511-40e8162e-1b3c-4be4-ae49-6d9c6bae68cf.png) 10 | -------------------------------------------------------------------------------- /z-Others/FCIS Quizzes/Lec 3/README.md: -------------------------------------------------------------------------------- 1 | # Lec 3 2 | 3 | # `Quizzes` 4 | ![image](https://user-images.githubusercontent.com/99830416/223587980-3d0d495f-0788-49dd-9ca2-e76df1636091.png) 5 | ![image](https://user-images.githubusercontent.com/99830416/223588028-71ee3194-bb15-4478-b76b-479498cceab7.png) 6 | ![image](https://user-images.githubusercontent.com/99830416/223588098-8c89998f-1957-4526-b239-ca595f06dd3e.png) 7 | 8 | ![image](https://user-images.githubusercontent.com/99830416/224512699-ed851c50-b654-4246-b463-ffbccd13cfd0.png) 9 | ![image](https://user-images.githubusercontent.com/99830416/224512711-397176b8-d57b-482a-a44f-ac704e54677e.png) 10 | ![image](https://user-images.githubusercontent.com/99830416/224512806-4918cd4e-ac4e-4681-b0ef-e8acf3d53171.png) 11 | 12 | 13 | # `Solution of first 3 Quizzes` 14 | ## Quiz 1 15 | ![1 1](https://user-images.githubusercontent.com/99830416/223590098-e370fdf0-5c32-476a-add1-46ad74d9956c.jpg) 16 | ![1 2](https://user-images.githubusercontent.com/99830416/223590106-0695de8c-ce0c-411e-8772-b15036df8f8e.jpg) 17 | ## Quiz 2 18 | ![2 1](https://user-images.githubusercontent.com/99830416/223590129-8ac125c9-22de-40c2-8f65-a86c558d1fa1.jpg) 19 | ![2 2](https://user-images.githubusercontent.com/99830416/223590144-19e68708-80a4-49c9-a5fb-52df0417c2c7.jpg) 20 | ## Quiz 3 21 | ![3 1](https://user-images.githubusercontent.com/99830416/223590159-564fb8b5-03cd-4151-93a0-2d3edc5dd9e7.jpg) 22 | ![3 2](https://user-images.githubusercontent.com/99830416/223590172-8d3d5afd-b8e8-4cfe-8fb0-6d9af9fc37e9.jpg) 23 | 24 | -------------------------------------------------------------------------------- /z-Others/FCIS Quizzes/Lec 4/README.md: -------------------------------------------------------------------------------- 1 | # Lec 4 2 | 3 | # `Quizzes` 4 | ### `Quiz 1` 5 | ![image](https://user-images.githubusercontent.com/99830416/227741644-d4e7e0f4-718d-453a-b849-3ccf3c901825.png) 6 | 7 | ### `Quiz 2` 8 | ![image](https://user-images.githubusercontent.com/99830416/227741671-c656a7d3-9a8c-4dd9-86a7-76f3766594da.png) 9 | 10 | ### `Quiz 3` 11 | ![image](https://user-images.githubusercontent.com/99830416/227741710-b12b0cef-b73d-424d-92a0-c71f337f853a.png) 12 | 13 | # `Quizzes Solution` 14 | ### `Quiz 1` 15 | ![image](https://user-images.githubusercontent.com/99830416/227743148-bff5f59b-b150-4c5e-b49b-7b1f3ac277cf.png) 16 | ### `Quiz 2` 17 | ![image](https://user-images.githubusercontent.com/99830416/227743176-f1dbb2ea-d16f-41ff-a5c6-70cf008346d7.png) 18 | 19 | ### `Quiz 3` 20 | ![image](https://user-images.githubusercontent.com/99830416/227743208-72239650-e56e-4d7f-a867-c73a11da6568.png) 21 | 22 | --------------------------------------------------------------------------------