├── 1- Big O ├── Slides │ ├── 1-Basics │ │ ├── 6.3-Search In BST.html │ │ ├── 0.1.PNG │ │ ├── 0.2.PNG │ │ ├── 0.3.PNG │ │ ├── 1.1.PNG │ │ ├── 1.2.PNG │ │ ├── 1.3.PNG │ │ ├── 2.1.PNG │ │ ├── 3.1.PNG │ │ ├── 4.1.PNG │ │ ├── 4.2.PNG │ │ ├── 5.1.PNG │ │ ├── 6.1.PNG │ │ ├── 6.2.PNG │ │ ├── 7.1.PNG │ │ ├── 7.2.PNG │ │ ├── 7.3.PNG │ │ ├── 6.5-BST Print Code.html │ │ ├── 7.4-Merge Sort.html │ │ └── 6.4-Deeply Understanding Logarithms In Time Complexities & Their Role In Computer Science.html │ ├── 3-Example │ │ ├── 1.1.PNG │ │ └── 1.2.PNG │ └── 2-Simplify BigO │ │ ├── 0.1.PNG │ │ ├── 1.1.PNG │ │ ├── 2.1.PNG │ │ ├── 3.1.PNG │ │ └── 4.1.PNG └── BigO │ ├── BigO │ ├── BigO.csproj │ ├── 1-Basics │ │ ├── 2-O(n).cs │ │ ├── 3-O(n^2).cs │ │ ├── 4-O(n!).cs │ │ ├── 1-O(1).cs │ │ ├── 5-O(2^n).cs │ │ ├── 7-O(nLogn).cs │ │ └── 6-O(log n).cs │ ├── 2-Simplify BigO │ │ ├── Rule1 (Worst Case).cs │ │ ├── Rule4 (Drop Non Dominants).cs │ │ ├── Rule3 (Different Terms for Inputs).cs │ │ └── Rule2 (Remove Constants).cs │ ├── 3-Example │ │ └── Example.cs │ └── Program.cs │ └── BigO.sln ├── 3-Algorithms ├── Slides │ ├── 1-Recursion │ │ ├── Recursion.html │ │ ├── 1.1.PNG │ │ ├── 1.2.PNG │ │ ├── 1.3.PNG │ │ ├── 1.4.PNG │ │ ├── 1.5.PNG │ │ ├── 1.6.PNG │ │ ├── Tail and Non-Tail Recursion.html │ │ └── Recursion VS Iteration.html │ ├── 2-Dynamic Programming │ │ ├── Closures in Arabic.html │ │ ├── Dynamic Programming.html │ │ ├── 1.1.PNG │ │ ├── 1.2.PNG │ │ ├── 1.3.PNG │ │ ├── 1.4.PNG │ │ ├── 1.5.PNG │ │ ├── 1.6.PNG │ │ ├── 1.7.PNG │ │ └── 1.8.PNG │ ├── 4-Sorting │ │ ├── Animation Videos │ │ │ ├── 5.1-Quick Sort.html │ │ │ ├── 5.2-Quick Sort.html │ │ │ ├── 3-Bubble Sort.html │ │ │ ├── 4-Merge Sort.html │ │ │ ├── 1-Insertion Sort.html │ │ │ └── 2-Selection Sort.html │ │ └── Useful links │ │ │ ├── Stable V.S. Unstable Sorting Algorithms.html │ │ │ └── Comparing different sorting algorithms by different data sets.html │ └── 3- Algorithms Searching + BFS + DFS │ │ ├── 1.PNG │ │ ├── 2.PNG │ │ ├── 3.PNG │ │ ├── 4.PNG │ │ ├── Connected vs Disconnected Graphs - Copy.html │ │ └── Tree Traversals (Inorder, Preorder and Postorder).html └── Algorithms │ ├── Algorithms │ ├── Algorithms.csproj │ ├── 3-Searching_Traversing │ │ ├── Helper │ │ │ ├── BinarySearchTree │ │ │ │ ├── 0-Node.cs │ │ │ │ └── 1-BinarySearchTree.cs │ │ │ └── GraphDataStructure │ │ │ │ └── Graph.cs │ │ ├── DepthFirstSearch │ │ │ ├── 2-DFSforGraph.cs │ │ │ └── 1-DFSforTree.cs │ │ └── BreadthFirstSearch │ │ │ ├── 1-BFSforTree.cs │ │ │ └── 2-BFSforGraph.cs │ ├── 2-DynamicProgramming │ │ └── Example(Fibonacci) │ │ │ ├── 2-UsingDynamicProramming │ │ │ ├── 2-TabulatedSolution.cs │ │ │ └── 1-MemoizedSolution.cs │ │ │ └── 1-UsingRecursion │ │ │ └── 1-Recursive solution.cs │ ├── 1-Recursion │ │ ├── 2-StackOverflowInRecursion │ │ │ └── 2-StackOverflowInRecursion.cs │ │ ├── 1-DirectAndIndirectRecursion │ │ │ └── 1-DirectAndIndirectRecursion.cs │ │ ├── 4-Recursion VS Iteration │ │ │ ├── Factorial.cs │ │ │ └── Fibonacci.cs │ │ └── 3-TailAndNon_TailRecursion │ │ │ └── 3-TailAndNon_TailRecursion.cs │ ├── 4-Sorting │ │ ├── 2-SelectionSort.cs │ │ ├── 1-InsertionSort.cs │ │ ├── 3-BubbleSort.cs │ │ ├── 5-QuickSort.cs │ │ └── 4-MergeSort.cs │ └── Program.cs │ └── Algorithms.sln ├── 2-Data Structure ├── Slides │ ├── 5-Tree │ │ ├── 2.7-Binary Search Tree ( VisuAlgo).html │ │ ├── 0.1.PNG │ │ ├── 0.2.PNG │ │ ├── 0.3.PNG │ │ ├── 1.1.PNG │ │ ├── 1.2.PNG │ │ ├── 1.3.PNG │ │ ├── 1.4.PNG │ │ ├── 2.1.PNG │ │ ├── 2.2.PNG │ │ ├── 2.3.PNG │ │ ├── 2.4.PNG │ │ ├── 2.5.PNG │ │ └── 2.6-Binary Search Tree (Remove Cases).html │ ├── 2-Stack │ │ ├── 1.1.PNG │ │ ├── 1.2.PNG │ │ ├── 1.3.PNG │ │ ├── 1.4.PNG │ │ └── 1.5.PNG │ ├── 3-Queue │ │ ├── 1.1.PNG │ │ ├── 1.2.PNG │ │ ├── 1.3.PNG │ │ ├── 1.4.PNG │ │ └── 1.5.PNG │ ├── 6-Gragh │ │ ├── 1.1.PNG │ │ ├── 1.2.PNG │ │ ├── 1.3.PNG │ │ ├── 1.4.PNG │ │ ├── 1.5.PNG │ │ └── 1.6-Graph (Wikipedia).html │ ├── 1-Linked list │ │ ├── 1.1.PNG │ │ ├── 1.2.PNG │ │ ├── 1.3.PNG │ │ ├── 1.4.PNG │ │ └── 1.5.PNG │ └── 4-Hashtable │ │ ├── 1.1.PNG │ │ ├── 1.2.PNG │ │ ├── 1.3.PNG │ │ ├── 1.4.PNG │ │ ├── 1.5.PNG │ │ ├── 1.6.PNG │ │ ├── 1.7.PNG │ │ └── 1.8.PNG └── DataStructure │ ├── DataStructure │ ├── DataStructure.csproj │ ├── 5-Trees │ │ ├── 2-BinarySearchTree │ │ │ ├── 0-Helper │ │ │ │ ├── BinarySearchTypes.cs │ │ │ │ ├── TypeA.cs │ │ │ │ ├── TypeC.cs │ │ │ │ └── TypeB.cs │ │ │ ├── 1-BSTNode.cs │ │ │ └── 2-BinarySearchTree.cs │ │ ├── 1-BinaryTree │ │ │ ├── 2-BinaryTree.cs │ │ │ └── 1-BTNode.cs │ │ └── TreesPractices.cs │ ├── 1-LinkedList │ │ ├── 1-SingleLinkedList │ │ │ ├── 1-SLLNode.cs │ │ │ └── 2-SingleLinkedList.cs │ │ ├── 2-DoublyLinkedLists │ │ │ ├── 1-DLLNode.cs │ │ │ └── 2-DoublyLinkedLists.cs │ │ └── LinkedListPractices.cs │ ├── 4-HashTable │ │ ├── 0-HashNode.cs │ │ ├── HashtablePractices.cs │ │ ├── 1-WithoutHandlingCollision │ │ │ └── 1-CustomHashTable.cs │ │ └── 2-HandlingCollisionUsingSeparateChaining │ │ │ └── 2-CustomHashTable2.cs │ ├── 6-Graph │ │ ├── GraphPrctices.cs │ │ └── Graph.cs │ ├── 2-Stack │ │ ├── 2-StackUsingList.cs │ │ ├── StackPractices.cs │ │ └── 1-StackUsingLinkedList.cs │ ├── Program.cs │ └── 3-Queue │ │ ├── QueuePractices.cs │ │ ├── 1-QueueUsingStack.cs │ │ └── 2- QueueUsingLinkedlist.cs │ └── DataStructure.sln ├── LICENSE ├── README.md └── .gitignore /1- Big O/Slides/1-Basics/6.3-Search In BST.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/0.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/0.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/0.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/0.2.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/0.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/0.3.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/1.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/1.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/1.2.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/1.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/1.3.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/2.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/2.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/3.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/3.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/4.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/4.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/4.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/4.2.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/5.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/5.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/6.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/6.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/6.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/6.2.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/7.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/7.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/7.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/7.2.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/7.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/1-Basics/7.3.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/1-Recursion/Recursion.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /1- Big O/Slides/3-Example/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/3-Example/1.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/3-Example/1.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/3-Example/1.2.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/2.7-Binary Search Tree ( VisuAlgo).html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /1- Big O/Slides/2-Simplify BigO/0.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/2-Simplify BigO/0.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/2-Simplify BigO/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/2-Simplify BigO/1.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/2-Simplify BigO/2.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/2-Simplify BigO/2.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/2-Simplify BigO/3.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/2-Simplify BigO/3.1.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/2-Simplify BigO/4.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/1- Big O/Slides/2-Simplify BigO/4.1.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/2-Stack/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/2-Stack/1.1.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/2-Stack/1.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/2-Stack/1.2.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/2-Stack/1.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/2-Stack/1.3.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/2-Stack/1.4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/2-Stack/1.4.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/2-Stack/1.5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/2-Stack/1.5.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/3-Queue/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/3-Queue/1.1.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/3-Queue/1.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/3-Queue/1.2.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/3-Queue/1.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/3-Queue/1.3.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/3-Queue/1.4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/3-Queue/1.4.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/3-Queue/1.5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/3-Queue/1.5.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/0.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/0.1.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/0.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/0.2.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/0.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/0.3.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/1.1.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/1.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/1.2.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/1.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/1.3.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/1.4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/1.4.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/2.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/2.1.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/2.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/2.2.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/2.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/2.3.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/2.4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/2.4.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/2.5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/5-Tree/2.5.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/6-Gragh/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/6-Gragh/1.1.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/6-Gragh/1.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/6-Gragh/1.2.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/6-Gragh/1.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/6-Gragh/1.3.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/6-Gragh/1.4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/6-Gragh/1.4.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/6-Gragh/1.5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/6-Gragh/1.5.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/1-Recursion/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/1-Recursion/1.1.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/1-Recursion/1.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/1-Recursion/1.2.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/1-Recursion/1.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/1-Recursion/1.3.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/1-Recursion/1.4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/1-Recursion/1.4.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/1-Recursion/1.5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/1-Recursion/1.5.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/1-Recursion/1.6.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/1-Recursion/1.6.PNG -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/6.5-BST Print Code.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /2-Data Structure/Slides/1-Linked list/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/1-Linked list/1.1.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/1-Linked list/1.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/1-Linked list/1.2.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/1-Linked list/1.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/1-Linked list/1.3.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/1-Linked list/1.4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/1-Linked list/1.4.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/1-Linked list/1.5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/1-Linked list/1.5.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/4-Hashtable/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/4-Hashtable/1.1.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/4-Hashtable/1.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/4-Hashtable/1.2.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/4-Hashtable/1.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/4-Hashtable/1.3.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/4-Hashtable/1.4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/4-Hashtable/1.4.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/4-Hashtable/1.5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/4-Hashtable/1.5.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/4-Hashtable/1.6.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/4-Hashtable/1.6.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/4-Hashtable/1.7.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/4-Hashtable/1.7.PNG -------------------------------------------------------------------------------- /2-Data Structure/Slides/4-Hashtable/1.8.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/2-Data Structure/Slides/4-Hashtable/1.8.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/1-Recursion/Tail and Non-Tail Recursion.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/2-Dynamic Programming/Closures in Arabic.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/4-Sorting/Animation Videos/5.1-Quick Sort.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/4-Sorting/Animation Videos/5.2-Quick Sort.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /2-Data Structure/Slides/6-Gragh/1.6-Graph (Wikipedia).html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/2-Dynamic Programming/Dynamic Programming.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/2-Dynamic Programming/1.1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/2-Dynamic Programming/1.1.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/2-Dynamic Programming/1.2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/2-Dynamic Programming/1.2.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/2-Dynamic Programming/1.3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/2-Dynamic Programming/1.3.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/2-Dynamic Programming/1.4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/2-Dynamic Programming/1.4.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/2-Dynamic Programming/1.5.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/2-Dynamic Programming/1.5.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/2-Dynamic Programming/1.6.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/2-Dynamic Programming/1.6.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/2-Dynamic Programming/1.7.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/2-Dynamic Programming/1.7.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/2-Dynamic Programming/1.8.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/2-Dynamic Programming/1.8.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/1-Recursion/Recursion VS Iteration.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/4-Sorting/Useful links/Stable V.S. Unstable Sorting Algorithms.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/7.4-Merge Sort.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /2-Data Structure/Slides/5-Tree/2.6-Binary Search Tree (Remove Cases).html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/3- Algorithms Searching + BFS + DFS/1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/3- Algorithms Searching + BFS + DFS/1.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/3- Algorithms Searching + BFS + DFS/2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/3- Algorithms Searching + BFS + DFS/2.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/3- Algorithms Searching + BFS + DFS/3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/3- Algorithms Searching + BFS + DFS/3.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/3- Algorithms Searching + BFS + DFS/4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohamedHashish42/Data-Structures-And-Algorithms/HEAD/3-Algorithms/Slides/3- Algorithms Searching + BFS + DFS/4.PNG -------------------------------------------------------------------------------- /3-Algorithms/Slides/4-Sorting/Animation Videos/3-Bubble Sort.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/4-Sorting/Animation Videos/4-Merge Sort.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /1- Big O/Slides/1-Basics/6.4-Deeply Understanding Logarithms In Time Complexities & Their Role In Computer Science.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/4-Sorting/Animation Videos/1-Insertion Sort.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/4-Sorting/Animation Videos/2-Selection Sort.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/4-Sorting/Useful links/Comparing different sorting algorithms by different data sets.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/3- Algorithms Searching + BFS + DFS/Connected vs Disconnected Graphs - Copy.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/BigO.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3-Algorithms/Slides/3- Algorithms Searching + BFS + DFS/Tree Traversals (Inorder, Preorder and Postorder).html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/DataStructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/5-Trees/2-BinarySearchTree/0-Helper/BinarySearchTypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.Trees.BinarySearchTree.Helper 6 | { 7 | public abstract class BinarySearchTypes 8 | { 9 | public int Key { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/Algorithms.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/1-Basics/2-O(n).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class Linear 8 | { 9 | public static void PrinFromOneToNumber(int number) 10 | { 11 | for (int i = 1; i <= number; i++) 12 | { 13 | Console.WriteLine(i); 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/1-LinkedList/1-SingleLinkedList/1-SLLNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.LinkedList 6 | { 7 | public class SLLNode 8 | { 9 | public T Value { get; set; } 10 | public SLLNode Next { get; set; } 11 | 12 | public SLLNode(T value) 13 | { 14 | Value = value; 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/4-HashTable/0-HashNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.HashTable 6 | { 7 | class HashNode 8 | { 9 | public object Key { get; set; } 10 | public object Value { get; set; } 11 | 12 | public HashNode(object key, object value) 13 | { 14 | Key = key; 15 | Value = value; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/5-Trees/2-BinarySearchTree/0-Helper/TypeA.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.Trees.BinarySearchTree.Helper 6 | { 7 | class TypeA : BinarySearchTypes 8 | { 9 | public int Value { get; set; } 10 | public TypeA(int key, int value) 11 | { 12 | Key = key; 13 | Value = value; 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/5-Trees/2-BinarySearchTree/0-Helper/TypeC.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.Trees.BinarySearchTree.Helper 6 | { 7 | class TypeC : BinarySearchTypes 8 | { 9 | public float Value { get; set; } 10 | public TypeC(int key, float value) 11 | { 12 | Key = key; 13 | Value = value; 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/5-Trees/2-BinarySearchTree/0-Helper/TypeB.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.Trees.BinarySearchTree.Helper 6 | { 7 | class TypeB : BinarySearchTypes 8 | { 9 | public string Value { get; set; } 10 | public TypeB(int key,string value) 11 | { 12 | Key = key; 13 | Value = value; 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/1-LinkedList/2-DoublyLinkedLists/1-DLLNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.LinkedList 6 | { 7 | 8 | public class DLLNode 9 | { 10 | public T Value { get; set; } 11 | public DLLNode Next { get; set; } 12 | public DLLNode Previous { get; set; } 13 | 14 | public DLLNode(T value) 15 | { 16 | Value = value; 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/5-Trees/1-BinaryTree/2-BinaryTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.Trees.BinaryTree 6 | { 7 | 8 | public class BinaryTree 9 | { 10 | 11 | public BTNode root { get; set; } 12 | 13 | public BinaryTree() 14 | { 15 | root = null; 16 | } 17 | 18 | public BinaryTree(T value) 19 | { 20 | root = new BTNode(value); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/3-Searching_Traversing/Helper/BinarySearchTree/0-Node.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Searching_Traversing 6 | { 7 | class Node 8 | { 9 | public int Value { get; set; } 10 | public Node Left { get; set; } 11 | public Node Right { get; set; } 12 | 13 | public Node(int value) 14 | { 15 | Value = value; 16 | Left = null; 17 | Right = null; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/1-Basics/3-O(n^2).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class Quadratic 8 | { 9 | public static void MultiplicationTable(int n) 10 | { 11 | for (int i = 1; i < n; i++) 12 | { 13 | for (int j = 1; j < n; j++) 14 | { 15 | Console.WriteLine(i +" * "+j+" =" +i*j); 16 | } 17 | Console.WriteLine("\n"); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/2-Simplify BigO/Rule1 (Worst Case).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class WorstCase 8 | { 9 | public static void FindNameInArray(string [] arr,string name) 10 | { 11 | foreach (var item in arr) 12 | { 13 | if (item == name) 14 | { 15 | Console.WriteLine(name); //O(n) 16 | break; 17 | } 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/5-Trees/1-BinaryTree/1-BTNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.Trees.BinaryTree 6 | { 7 | public class BTNode 8 | { 9 | public T Value { get; set; } 10 | public BTNodeLeft { get; set; } 11 | public BTNode Right { get; set; } 12 | 13 | public BTNode(T value) 14 | { 15 | Value = value; 16 | Left = null; 17 | Right = null; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/2-DynamicProgramming/Example(Fibonacci)/2-UsingDynamicProramming/2-TabulatedSolution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.DynamicProgramming 6 | { 7 | class TabulatedSolution 8 | { 9 | public static int Fib(int index) 10 | { 11 | 12 | var fibSeq = new List { 0, 1 }; 13 | for (int i = 2; i <= index; i++) 14 | { 15 | fibSeq.Add(fibSeq[i - 1] + fibSeq[i - 2]); 16 | } 17 | 18 | return fibSeq[index]; 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/1-Basics/4-O(n!).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class Factorial 8 | { 9 | public static void PrintUntilFactorial(int n) 10 | { 11 | 12 | for (int i = 1; i <= Fact(n); i++) 13 | { 14 | Console.WriteLine(i); //O(n!) 15 | } 16 | } 17 | 18 | public static int Fact(int number) 19 | { 20 | int factorial = 1; 21 | for (int i = number; i >= 1; i--) 22 | { 23 | factorial *= i; 24 | } 25 | return factorial; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/5-Trees/2-BinarySearchTree/1-BSTNode.cs: -------------------------------------------------------------------------------- 1 | using DataStructure.Trees.BinarySearchTree.Helper; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace DataStructure.Trees.BinarySearchTree 7 | { 8 | public class BSTNode where T: BinarySearchTypes 9 | { 10 | public T Obj { get; set; } 11 | public BSTNode Left { get; set; } 12 | public BSTNode Right { get; set; } 13 | public BSTNode() 14 | { 15 | 16 | } 17 | public BSTNode(T obj) 18 | { 19 | Obj = obj; 20 | Left = null; 21 | Right = null; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/2-Simplify BigO/Rule4 (Drop Non Dominants).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class DropNonDominants 8 | { 9 | public static void PrintDone(int n) 10 | { 11 | for (int i = 0; i < n; i++) 12 | { 13 | for (int j = 0; j < n; j++) 14 | { 15 | Console.WriteLine("Done"); //O(n^2) 16 | } 17 | } 18 | 19 | for (int i = 0; i < n; i++) 20 | { 21 | Console.WriteLine("Done"); //O(n) 22 | } 23 | //Time complixity for this function = O(n^2 + n) = O(n^2) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/2-Simplify BigO/Rule3 (Different Terms for Inputs).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class DifferentTermsForInputs 8 | { 9 | public static void PrintNumberInTwoArrays(int [] arr1,int [] arr2) 10 | { 11 | var n = arr1.Length; 12 | var a = arr2.Length; 13 | 14 | for (int i = 0; i < n; i++) 15 | { 16 | Console.WriteLine(arr1[i]); 17 | } 18 | 19 | for (int i = 0; i < a; i++) 20 | { 21 | Console.WriteLine(arr2[i]); 22 | } 23 | 24 | //Time complixity for this function = O( n + a) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/6-Graph/GraphPrctices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.Graph 6 | { 7 | class GraphPrctices 8 | { 9 | public static void CustomGraph() 10 | { 11 | Graph myGraph = new Graph(); 12 | myGraph.AddVertex("A"); 13 | myGraph.AddVertex("B"); 14 | myGraph.AddVertex("C"); 15 | myGraph.AddVertex("D"); 16 | myGraph.AddEdge("A", "B"); 17 | myGraph.AddEdge("A", "C"); 18 | myGraph.AddEdge("B", "C"); 19 | myGraph.AddEdge("C", "D"); 20 | 21 | 22 | myGraph.ShowConnections(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/1-Recursion/2-StackOverflowInRecursion/2-StackOverflowInRecursion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Recursion 6 | { 7 | class StackOverflowInRecursion 8 | { 9 | #region Base case is not reached 10 | 11 | int Fact(int n) 12 | { 13 | //Here if i called Fact as Fact(10) the 14 | //base case is never reached 15 | if (n == 100) 16 | return 1; 17 | 18 | else 19 | return n * Fact(n - 1); 20 | } 21 | 22 | #endregion 23 | 24 | 25 | 26 | #region Base case is not defined 27 | 28 | int fact(int n) 29 | { 30 | return n * fact(n - 1); 31 | } 32 | 33 | 34 | 35 | #endregion 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/1-Recursion/1-DirectAndIndirectRecursion/1-DirectAndIndirectRecursion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Recursion 6 | { 7 | class DirectAndIndirectRecursion 8 | { 9 | #region Direct recursion 10 | 11 | 12 | void Fun() 13 | { 14 | // Some code.... 15 | Fun(); 16 | // Some code... 17 | } 18 | 19 | #endregion 20 | 21 | 22 | 23 | 24 | #region Indirect recursion 25 | 26 | void Fun1() 27 | { 28 | // Some code... 29 | Fun2(); 30 | // Some code... 31 | } 32 | void Fun2() 33 | { 34 | // Some code... 35 | Fun1(); 36 | // Some code... 37 | } 38 | 39 | 40 | #endregion 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/2-Simplify BigO/Rule2 (Remove Constants).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class RemoveConstants 8 | { 9 | public static void PrintFromOneToNumberTwiceAndFromOneToTen(int number) 10 | { 11 | for (int i = 1; i < number; i++) 12 | { 13 | Console.WriteLine(i); //O(n) 14 | } 15 | 16 | for (int i = 1; i < number; i++) 17 | { 18 | Console.WriteLine(i); //O(n) 19 | } 20 | 21 | for (int i = 1; i < 10; i++) 22 | { 23 | Console.WriteLine(i); //O(10) 24 | } 25 | 26 | 27 | //Time complixity for this function 28 | // = O(2n + 10) 29 | // = O(2n + 1) 30 | // = O(n) 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/4-Sorting/2-SelectionSort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Sorting 6 | { 7 | class SelectionSort 8 | { 9 | 10 | public static int[] Sort(int[] arr) 11 | { 12 | var n = arr.Length; 13 | 14 | // One by one move boundary of unsorted subarray 15 | for (int i = 0; i < n - 1; i++) 16 | { 17 | // Find the minimum element in unsorted array 18 | var min = i; 19 | for (int j = i + 1; j < n; j++) 20 | { 21 | if (arr[j] < arr[min]) 22 | min = j; 23 | } 24 | 25 | // Swap the found minimum element 26 | var temp = arr[min]; 27 | arr[min] = arr[i]; 28 | arr[i] = temp; 29 | } 30 | 31 | return arr; 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/2-DynamicProgramming/Example(Fibonacci)/1-UsingRecursion/1-Recursive solution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.DynamicProgramming 6 | { 7 | class RecursiveSolution 8 | { 9 | 10 | public static int Fib(int index) 11 | { 12 | if (index < 2) 13 | { 14 | return index; 15 | } 16 | return Fib(index - 1) + Fib(index - 2); 17 | 18 | // Fib(6) 19 | 20 | // Fib(5) + Fib(4) 21 | 22 | // Fib(4) + Fib(3) Fib(3) + Fib(2) 23 | 24 | // Fib(3) + Fib(2) Fib(2) + Fib(1) Fib(2) + Fib(1) 25 | 26 | // Fib(2) + Fib(1) 27 | 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/4-Sorting/1-InsertionSort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Sorting 6 | { 7 | class InsertionSort 8 | { 9 | 10 | 11 | public static int[] Sort(int[] arr) 12 | { 13 | int n = arr.Length; 14 | for (int i = 1; i < n; ++i) 15 | { 16 | int key = arr[i]; 17 | int j; 18 | 19 | // when Key 30 20 | // 40, 50, 30, 70 21 | 22 | for (j = i - 1; j >= 0 && key < arr[j]; j--) 23 | { 24 | 25 | // 1th 40, 50, 50, 70 26 | // 2th 40, 40, 50, 70 27 | 28 | arr[j + 1] = arr[j]; 29 | 30 | 31 | } 32 | 33 | arr[j + 1] = key; // 30, 40, 50, 70 34 | } 35 | return arr; 36 | } 37 | 38 | 39 | 40 | 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/1-Recursion/4-Recursion VS Iteration/Factorial.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Recursion 6 | { 7 | class Factorial 8 | { 9 | public static int UsingItteration(int number) 10 | { 11 | int factorial = 1; 12 | for (int i = number; i >= 1; i--) 13 | { 14 | factorial *= i; 15 | } 16 | return factorial; 17 | } 18 | 19 | public static int UsingRecursion(int number) 20 | { 21 | 22 | //Base Case 23 | if (number == 0 || number == 1) 24 | { 25 | return 1; 26 | } 27 | //Recursive Case 28 | return number * UsingRecursion(number - 1); 29 | //5 * 4! 30 | // 4 * 3! 31 | // 3 * 2! 32 | // 2 * 1! 33 | // 1 34 | 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/4-Sorting/3-BubbleSort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Sorting 6 | { 7 | class BubbleSort 8 | { 9 | 10 | 11 | public static int[] Sort(int[] arr) 12 | { 13 | var n = arr.Length; 14 | bool swapped; 15 | for (int i = 0; i < n - 1; i++) 16 | { 17 | swapped = false; 18 | for (int j = 0; j < n - i - 1; j++) 19 | { 20 | if (arr[j] > arr[j + 1]) 21 | { 22 | // swap arr[j] and arr[j+1] 23 | var temp = arr[j]; 24 | arr[j] = arr[j + 1]; 25 | arr[j + 1] = temp; 26 | swapped = true; 27 | } 28 | } 29 | 30 | if (swapped == false) 31 | break; 32 | } 33 | return arr; 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 MohamedHashish42 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BigO", "BigO\BigO.csproj", "{D8C8B9C2-C8F6-4694-923C-E070E73F46B1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D8C8B9C2-C8F6-4694-923C-E070E73F46B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D8C8B9C2-C8F6-4694-923C-E070E73F46B1}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D8C8B9C2-C8F6-4694-923C-E070E73F46B1}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D8C8B9C2-C8F6-4694-923C-E070E73F46B1}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {AA0DDC1A-0F98-44E0-B1FC-FCE5F042381D} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/1-Basics/1-O(1).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class Constant 8 | { 9 | public static void PrintNumber(int number) 10 | { 11 | Console.WriteLine(number); 12 | } 13 | 14 | public static void PrintNumberTwice(int number) 15 | { 16 | //This method gives O(2) 17 | 18 | Console.WriteLine(number); //O(1) 19 | Console.WriteLine(number); //O(1) 20 | } 21 | 22 | 23 | public static void PrintNumberThrice(int number) 24 | { 25 | //This method gives O(3) 26 | 27 | Console.WriteLine(number); //O(1) 28 | Console.WriteLine(number); //O(1) 29 | Console.WriteLine(number); //O(1) 30 | } 31 | 32 | public static void PrintNumberFourTimes(int number) 33 | { 34 | //This method gives O(4) 35 | 36 | Console.WriteLine(number); //O(1) 37 | Console.WriteLine(number); //O(1) 38 | Console.WriteLine(number); //O(1) 39 | Console.WriteLine(number); //O(1) 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Algorithms", "Algorithms\Algorithms.csproj", "{2BF325C3-1A30-4333-8FBE-5F72404683FB}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {2BF325C3-1A30-4333-8FBE-5F72404683FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {2BF325C3-1A30-4333-8FBE-5F72404683FB}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {2BF325C3-1A30-4333-8FBE-5F72404683FB}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {2BF325C3-1A30-4333-8FBE-5F72404683FB}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {A09F7D49-DDB6-406F-97ED-2959C48584A5} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31229.75 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataStructure", "DataStructure\DataStructure.csproj", "{54C57C17-B3B9-4610-AD73-EA6E5087CE91}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {54C57C17-B3B9-4610-AD73-EA6E5087CE91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {54C57C17-B3B9-4610-AD73-EA6E5087CE91}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {54C57C17-B3B9-4610-AD73-EA6E5087CE91}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {54C57C17-B3B9-4610-AD73-EA6E5087CE91}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {9164C979-6EF8-40FD-A9C0-9182C4F8D7A0} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/3-Searching_Traversing/DepthFirstSearch/2-DFSforGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Searching_Traversing 6 | { 7 | class DFSforGraph 8 | { 9 | public static void DFSUtil(T v, List visited, Graph graph) 10 | { 11 | 12 | visited.Add(v); 13 | Console.Write(v + " "); 14 | 15 | var vList = graph.AdjacentList[v]; 16 | foreach (var n in vList) 17 | { 18 | if (!visited.Contains(n)) 19 | DFSUtil(n, visited, graph); 20 | } 21 | } 22 | 23 | 24 | public static void DFS(Graph graph, T v) 25 | { 26 | 27 | var visited = new List(); 28 | DFSUtil(v, visited, graph); 29 | } 30 | 31 | 32 | public static void DFS(Graph graph) 33 | { 34 | var visited = new List(); 35 | foreach (var item in graph.AdjacentList) 36 | { 37 | if (!visited.Contains(item.Key)) 38 | DFSUtil(item.Key, visited, graph); 39 | } 40 | 41 | 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/3-Example/Example.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace BigO 7 | { 8 | class Example 9 | { 10 | public static bool HasPairWithSum(int[] arr, int sum) 11 | { 12 | for (int i = 0; i < arr.Length; i++) 13 | { 14 | for (int j = 0; j < arr.Length; j++) 15 | { 16 | if (arr[i] + arr[j] == sum) 17 | return true; 18 | } 19 | 20 | } 21 | return false; 22 | 23 | //Time Complexity is O(n^2) 24 | //Space Complexity is O(1) 25 | } 26 | 27 | public static bool HasPairWithSum2(int[] arr, int sum) 28 | { 29 | List list = new List(); 30 | for (int i = 0; i < arr.Length; i++) 31 | { 32 | if (list.Contains(arr[i])) 33 | { 34 | return true; 35 | } 36 | 37 | list.Add(sum - arr[i]); 38 | } 39 | return false; 40 | 41 | //Time Complexity is O(n) 42 | //Space Complexity is O(n) 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/2-Stack/2-StackUsingList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace DataStructure.Stack 7 | { 8 | 9 | class StackUsingList 10 | { 11 | private List _list; 12 | 13 | public StackUsingList() 14 | { 15 | _list = new List(); 16 | 17 | } 18 | 19 | public T Peek() 20 | { 21 | if (_list.Count > 0) 22 | return _list[_list.Count - 1]; 23 | return default(T); 24 | } 25 | 26 | public void Push(T value) 27 | { 28 | _list.Add(value); 29 | } 30 | 31 | public T Pop() 32 | { 33 | if (_list.Count == 0) 34 | { 35 | return default(T); 36 | } 37 | T lastItem = _list[_list.Count - 1]; 38 | _list.RemoveAt(_list.Count - 1); 39 | return lastItem; 40 | } 41 | 42 | public void Display() 43 | { 44 | 45 | foreach (var item in _list) 46 | { 47 | Console.Write(item +" "); 48 | } 49 | Console.WriteLine("\n"); 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/1-Recursion/3-TailAndNon_TailRecursion/3-TailAndNon_TailRecursion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Recursion 6 | { 7 | class TailAndNon_TailRecursion 8 | { 9 | #region Non Tail Recursion 10 | public static int NonTRFact(int number) 11 | { 12 | 13 | //Base Case 14 | if (number == 0 || number == 1) 15 | { 16 | return 1; 17 | } 18 | //Recursive Case 19 | return number * NonTRFact(number - 1); 20 | //5 * 4! 21 | // 4 * 3! 22 | // 3 * 2! 23 | // 2 * 1! 24 | // 1 25 | 26 | } 27 | #endregion 28 | 29 | #region Tail Recursion 30 | public static int TRFact(int n, int a = 1) 31 | { 32 | if (n == 0) 33 | return a; 34 | 35 | return TRFact(n - 1, n * a); 36 | 37 | // TRFact(5 , 1) = TRFact(5-1 , 5*1) 38 | 39 | // TRFact(4-1 , 4*5) 40 | 41 | // TRFact(3-1 , 3*20) 42 | 43 | // TRFact(2-1 , 2*60) 44 | 45 | // TRFact(1-1 , 1*120) 46 | 47 | } 48 | #endregion 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/1-Basics/5-O(2^n).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class Exponential 8 | { 9 | public static List PowerSet(string input) 10 | { 11 | int n = input.Length; 12 | 13 | // Power set contains 2^N subsets. 14 | // . . . 2^5 2^4 2^3 2^2 2^1 2^0 15 | // . . . 32 16 8 4 2 1 16 | 17 | int powerSetCount = 1 << n; 18 | var ans = new List(); 19 | for (int counter = 0; counter < powerSetCount; counter++) 20 | { 21 | ans.Add(GetSet(input, n, counter)); //O(2^n) 22 | } 23 | ans.ForEach(s => Console.WriteLine(s)); 24 | return ans; 25 | } 26 | 27 | public static string GetSet(string input, int n, int counter) 28 | { 29 | var s = new StringBuilder(); 30 | 31 | for (int j = 0; j < n; j++) 32 | { 33 | //Console.WriteLine((counter ) +" & " +(1 << j)+" = "+(counter & (1 << j))); 34 | if ((counter & (1 << j)) > 0) 35 | { 36 | s.Append(input[j]); 37 | } 38 | } 39 | // Console.WriteLine("-----------------------------"); 40 | return s.ToString(); 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/1-Recursion/4-Recursion VS Iteration/Fibonacci.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Recursion 6 | { 7 | class Fibonacci 8 | { 9 | // Fibonacci Sequence = 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610 ...... 10 | public static int UsingItteration(int index) 11 | { 12 | 13 | var fibSeq = new List { 0, 1 }; 14 | for (int i = 2; i <= index; i++) 15 | { 16 | fibSeq.Add(fibSeq[i - 1] + fibSeq[i - 2]); 17 | } 18 | 19 | return fibSeq[index]; 20 | } 21 | 22 | 23 | 24 | public static int UsingRecursion(int index) 25 | { 26 | if (index < 2) 27 | { 28 | return index; 29 | } 30 | return UsingRecursion(index - 1) + UsingRecursion(index - 2); 31 | 32 | //Fib(5) = Fib(4) + Fib(3) 33 | 34 | // Fib(3) + Fib(2) Fib(2) + Fib(1) 35 | 36 | // Fib(2) + Fib(1) Fib(1) + Fib(0) Fib(1) + Fib(0) 1 37 | 38 | // Fib(1) + Fib(0) 1 1 + 0 1 + 0 39 | 40 | // 1 + 0 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/4-Sorting/5-QuickSort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | class QuickSort 4 | { 5 | 6 | static void Swap(int[] arr, int i, int j) 7 | { 8 | int temp = arr[i]; 9 | arr[i] = arr[j]; 10 | arr[j] = temp; 11 | } 12 | 13 | /* 14 | This function takes last element as pivot, places 15 | the pivot element at its correct position in sorted 16 | array, and places all smaller (smaller than pivot) 17 | to left of pivot and all greater elements to right 18 | of pivot 19 | */ 20 | static int Partition(int[] arr, int low, int high) 21 | { 22 | 23 | 24 | int pivot = arr[high]; 25 | 26 | //i : index of smaller element 27 | //j : index of greater element 28 | int i = (low - 1); 29 | 30 | for (int j = low; j <= high - 1; j++) 31 | { 32 | if (arr[j] < pivot) 33 | { 34 | i++; 35 | Swap(arr, i, j); 36 | } 37 | } 38 | Swap(arr, i + 1, high); 39 | return (i + 1); 40 | } 41 | 42 | 43 | public static int[] Sort(int[] arr, int low, int high) 44 | { 45 | if (low < high) 46 | { 47 | 48 | // p is partitioning index, arr[p] is now at right place 49 | int p = Partition(arr, low, high); 50 | 51 | // Separately sort elements before partition and after partition 52 | Sort(arr, low, p - 1); 53 | Sort(arr, p + 1, high); 54 | } 55 | return arr; 56 | } 57 | } -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/6-Graph/Graph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.Graph 6 | { 7 | class Graph 8 | { 9 | public int NumOfNodes { get; set; } 10 | 11 | public Dictionary> AdjacentList { get; set; } 12 | 13 | public bool Directed { get; set; } 14 | 15 | public Graph(bool directed =false) 16 | { 17 | Directed = directed; 18 | NumOfNodes = 0; 19 | AdjacentList = new Dictionary>(); 20 | } 21 | public void AddVertex(T node) 22 | { 23 | AdjacentList.Add(node, new List()); 24 | NumOfNodes++; 25 | } 26 | 27 | public void AddEdge(T node1, T node2) 28 | { 29 | if (Directed) 30 | { 31 | AdjacentList[node1].Add(node2); 32 | return; 33 | } 34 | 35 | AdjacentList[node1].Add(node2); 36 | AdjacentList[node2].Add(node1); 37 | } 38 | public void ShowConnections() 39 | { 40 | 41 | foreach (var item in AdjacentList) 42 | { 43 | List nodeConnections = AdjacentList[item.Key]; 44 | StringBuilder connections = new StringBuilder(); 45 | for (int i = 0; i < nodeConnections.Count; i++) 46 | { 47 | connections.Append(nodeConnections[i]).Append(" "); 48 | } 49 | Console.WriteLine(item.Key + "-->" + connections); 50 | 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/3-Searching_Traversing/Helper/GraphDataStructure/Graph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Searching_Traversing 6 | { 7 | class Graph 8 | { 9 | public int NumOfNodes { get; set; } 10 | 11 | public Dictionary> AdjacentList { get; set; } 12 | 13 | public bool Directed { get; set; } 14 | 15 | public Graph(bool directed = false) 16 | { 17 | Directed = directed; 18 | NumOfNodes = 0; 19 | AdjacentList = new Dictionary>(); 20 | } 21 | public void AddVertex(T node) 22 | { 23 | AdjacentList.Add(node, new List()); 24 | NumOfNodes++; 25 | } 26 | 27 | public void AddEdge(T node1, T node2) 28 | { 29 | if (Directed) 30 | { 31 | AdjacentList[node1].Add(node2); 32 | return; 33 | } 34 | 35 | AdjacentList[node1].Add(node2); 36 | AdjacentList[node2].Add(node1); 37 | } 38 | public void ShowConnections() 39 | { 40 | 41 | foreach (var item in AdjacentList) 42 | { 43 | List nodeConnections = AdjacentList[item.Key]; 44 | StringBuilder connections = new StringBuilder(); 45 | for (int i = 0; i < nodeConnections.Count; i++) 46 | { 47 | connections.Append(nodeConnections[i]).Append(" "); 48 | } 49 | Console.WriteLine(item.Key + "-->" + connections); 50 | 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/3-Searching_Traversing/BreadthFirstSearch/1-BFSforTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Searching_Traversing 6 | { 7 | class BFSforTree 8 | { 9 | public static List BFS_Iterative(Node currentNode) 10 | { 11 | List list = new List(); 12 | Queue queue = new Queue(); 13 | queue.Enqueue(currentNode); 14 | 15 | while (queue.Count > 0) 16 | { 17 | currentNode = queue.Dequeue(); 18 | list.Add(currentNode.Value); 19 | if (currentNode.Left != null) 20 | { 21 | queue.Enqueue(currentNode.Left); 22 | } 23 | 24 | if (currentNode.Right != null) 25 | { 26 | queue.Enqueue(currentNode.Right); 27 | } 28 | } 29 | return list; 30 | } 31 | 32 | public static List BFS_Recurcive(Queue queue, List list) 33 | { 34 | if (queue.Count == 0) 35 | { 36 | return list; 37 | } 38 | 39 | var currentNode = queue.Dequeue(); 40 | list.Add(currentNode.Value); 41 | if (currentNode.Left != null) 42 | { 43 | queue.Enqueue(currentNode.Left); 44 | } 45 | 46 | if (currentNode.Right != null) 47 | { 48 | queue.Enqueue(currentNode.Right); 49 | } 50 | 51 | return BFS_Recurcive(queue, list); 52 | 53 | 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/Program.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using DataStructure.Graph; 6 | using DataStructure.HashTable; 7 | using DataStructure.LinkedList; 8 | using DataStructure.Queue; 9 | using DataStructure.Stack; 10 | using DataStructure.Trees.BinaryTree; 11 | 12 | namespace DataStructure 13 | { 14 | class Program 15 | { 16 | static void Main(string[] args) 17 | { 18 | #region 1-Linked List 19 | //LinkedListPractices.CustomSingleLinkedList(); 20 | //LinkedListPractices.CsharpBuiltInDoublyLinkedList(); 21 | //LinkedListPractices.CustomDoublyLinkedList(); 22 | #endregion 23 | 24 | #region 2-Stack 25 | //StackPractices.CsharpBuiltInStack(); 26 | //StackPractices.CustomStackUsingLinkedList(); 27 | //StackPractices.CustomStackUsingList(); 28 | #endregion 29 | 30 | #region 3-Queue 31 | //QueuePractices.CsharpBuiltInQueue(); 32 | //QueuePractices.CustomQueueUsingStack(); 33 | //QueuePractices.CustomQueueUsingLinkedlist(); 34 | #endregion 35 | 36 | #region 4-HashTable 37 | //HashtablePractices.CsharpBuiltInHashtable(); 38 | //HashtablePractices.CustomHashtableWithoutHandlingCollision(); 39 | //HashtablePractices.HandlingCollisionUsingSeparateChaining(); 40 | #endregion 41 | 42 | #region 5-BinarySearchTree 43 | //TreesPractices.CustomBinaryTree(); 44 | //TreesPractices.CustomBinarySearchTree(); 45 | 46 | #endregion 47 | 48 | #region 6-Graph 49 | //GraphPrctices.CustomGraph(); 50 | #endregion 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/2-Stack/StackPractices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DataStructure.Stack 7 | { 8 | class StackPractices 9 | { 10 | public static void CsharpBuiltInStack() 11 | { 12 | Stack myStack = new Stack(); 13 | myStack.Push(1); 14 | myStack.Push(2); 15 | myStack.Push(3); 16 | myStack.Pop(); 17 | Console.WriteLine("Element At 0 = " + myStack.ElementAt(0)); 18 | Console.WriteLine("Peek = " + myStack.Peek()); 19 | Display(myStack); 20 | } 21 | 22 | 23 | public static void CustomStackUsingLinkedList() 24 | { 25 | StackUsingLinkedList myStack = new StackUsingLinkedList(); 26 | myStack.Push(1); 27 | myStack.Push(2); 28 | myStack.Push(3); 29 | myStack.Pop(); 30 | Console.WriteLine("Element At 0 = " + myStack.ElementAt(0)); 31 | Console.WriteLine("Peek = " + myStack.Peek()); 32 | myStack.Display(); 33 | } 34 | 35 | 36 | public static void CustomStackUsingList() 37 | { 38 | StackUsingList myStack = new StackUsingList(); 39 | myStack.Push(1); 40 | myStack.Push(2); 41 | myStack.Push(3); 42 | myStack.Pop(); 43 | Console.WriteLine("Peek = " + myStack.Peek()); 44 | myStack.Display(); 45 | } 46 | 47 | 48 | public static void Display(Stack stack) 49 | { 50 | foreach (T Item in stack) 51 | { 52 | Console.Write(Item + " "); 53 | } 54 | Console.WriteLine("\n"); 55 | 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/3-Queue/QueuePractices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.Queue 6 | { 7 | class QueuePractices 8 | { 9 | public static void CsharpBuiltInQueue() 10 | { 11 | Queue myQueue = new Queue(); 12 | myQueue.Enqueue(1); 13 | myQueue.Enqueue(2); 14 | myQueue.Enqueue(3); 15 | myQueue.Dequeue(); 16 | myQueue.Enqueue(4); 17 | Console.WriteLine("Peek = " + myQueue.Peek()); 18 | Display(myQueue); 19 | } 20 | 21 | 22 | public static void CustomQueueUsingStack() 23 | { 24 | QueueUsingStack myQueue = new QueueUsingStack(); 25 | myQueue.Enqueue(1); 26 | myQueue.Enqueue(2); 27 | myQueue.Enqueue(3); 28 | myQueue.Dequeue(); 29 | myQueue.Enqueue(4); 30 | Console.WriteLine("Peek = " + myQueue.Peek()); 31 | myQueue.Display(); 32 | } 33 | 34 | public static void CustomQueueUsingLinkedlist() 35 | { 36 | QueueUsingLinkedlist myQueue = new QueueUsingLinkedlist(); 37 | myQueue.Enqueue(1); 38 | myQueue.Enqueue(2); 39 | myQueue.Enqueue(3); 40 | myQueue.Dequeue(); 41 | myQueue.Enqueue(4); 42 | Console.WriteLine("Peek = " + myQueue.Peek()); 43 | myQueue.Display(); 44 | } 45 | 46 | 47 | 48 | 49 | 50 | public static void Display(Queue queue) 51 | { 52 | foreach (T Item in queue) 53 | { 54 | Console.Write(Item + " "); 55 | } 56 | Console.WriteLine("\n"); 57 | 58 | } 59 | 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

3 | بسم الله الرحمن الرحيم 4 |

5 | 6 | 7 | # Data Structures And Algorithms 8 | 9 | This is a summary for some of Data Structures And Algorithms in C# 10 | 11 | This summary consists of 3 parts 12 | 13 | 1- Big O 14 | 15 | 2- Data Structures 16 | 17 | 3- Algorithms 18 | 19 | For each part, you will find 20 | 21 | 1- Separate slides folder for each subject derived from this part, please read the slides first 22 | 23 | 2- Simple console application contains an example for each subject derived from this part 24 | 25 | 26 | 27 | ## 1. Big O 28 | 29 | 1.1- Basics 30 | 31 | 1.2- Simplify Big O 32 | 33 | 1.3- Example 34 | 35 | 36 | 37 | ![image](https://user-images.githubusercontent.com/81900786/136651043-83675c3a-a308-4ed5-8bff-b0c774acd878.png) 38 | 39 | 40 | 41 | ## 2- Data Structures 42 | 43 | 2.1- Linked List 44 | 45 | 2.2- Stack 46 | 47 | 2.3- Queue 48 | 49 | 2.4- Hash table 50 | 51 | 2.5- Tree 52 | 53 | 2.6- Gragh 54 | 55 | ![image](https://user-images.githubusercontent.com/81900786/136651134-097f8afe-5fcb-47e2-a393-c25ee061dfff.png) 56 | 57 | 58 | 59 | ## 3- Algorithms 60 | 61 | 3.1- Recursion 62 | 63 | 3.2- Dynamic Programming 64 | 65 | 3.3- BFS + DFS 66 | 67 | 3.4- Sorting 68 | 69 | ![image](https://user-images.githubusercontent.com/81900786/141678992-7040ebb0-d029-478f-b839-c432501e8a12.png) 70 | 71 | 72 | 73 | ## References 74 | 75 | The main two sources I relied on for this summary are 76 | 77 | Master the Coding Interview: Data Structures + Algorithms 78 | 79 | GeeksforGeeks 80 | 81 | ## Other references 82 | 83 | wikipedia 84 | 85 | Tutorialspoint 86 | 87 | ## أخيرا أرجو من الله ان يكون نافعا 88 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/3-Queue/1-QueueUsingStack.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.Queue 6 | { 7 | class QueueUsingStack 8 | { 9 | private Stack _PushStack = new Stack(); 10 | private Stack _PopStack = new Stack(); 11 | 12 | public T Peek() 13 | { 14 | 15 | 16 | if (_PopStack.Count == 0) 17 | { 18 | var count = _PushStack.Count; 19 | for (int i = 0; i < count; i++) 20 | { 21 | _PopStack.Push(_PushStack.Pop()); 22 | } 23 | } 24 | if (_PopStack.Count > 0) 25 | { 26 | return _PopStack.Peek(); 27 | } 28 | 29 | 30 | return default(T); 31 | } 32 | 33 | public void Enqueue(T value) 34 | { 35 | int count = _PopStack.Count; 36 | 37 | for (int i = 0; i < count; i++) 38 | { 39 | _PushStack.Push(_PopStack.Pop()); 40 | } 41 | 42 | _PushStack.Push(value); 43 | 44 | } 45 | 46 | public T Dequeue() 47 | { 48 | 49 | int count = _PushStack.Count; 50 | for (int i = 0; i < count; i++) 51 | { 52 | _PopStack.Push(_PushStack.Pop()); 53 | } 54 | 55 | return _PopStack.Pop(); 56 | 57 | } 58 | 59 | public void Display() 60 | { 61 | 62 | if (_PopStack.Count == 0) 63 | { 64 | var count = _PushStack.Count; 65 | for (int i = 0; i < count; i++) 66 | { 67 | _PopStack.Push(_PushStack.Pop()); 68 | } 69 | } 70 | foreach (T Item in _PopStack) 71 | { 72 | Console.Write(Item + " "); 73 | } 74 | Console.WriteLine("\n"); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/3-Queue/2- QueueUsingLinkedlist.cs: -------------------------------------------------------------------------------- 1 | using DataStructure.LinkedList; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace DataStructure.Queue 7 | { 8 | 9 | 10 | class QueueUsingLinkedlist 11 | { 12 | public SLLNode First; 13 | public SLLNode Last; 14 | public int Length; 15 | 16 | public QueueUsingLinkedlist() 17 | { 18 | First = null; 19 | Last = null; 20 | Length = 0; 21 | } 22 | 23 | public T Peek() 24 | { 25 | if (Length > 0) 26 | { 27 | return First.Value; 28 | } 29 | return default(T); 30 | } 31 | 32 | public void Enqueue(T value) 33 | { 34 | SLLNode newSLLNode = new SLLNode(value); 35 | if (Length == 0) 36 | { 37 | First = newSLLNode; 38 | Last = newSLLNode; 39 | } 40 | else 41 | { 42 | Last.Next = newSLLNode; 43 | Last = newSLLNode; 44 | } 45 | Length++; 46 | } 47 | 48 | public T Dequeue() 49 | { 50 | if (First == null) 51 | { 52 | return default(T); 53 | } 54 | if (Length == 0) 55 | { 56 | Last = null; 57 | } 58 | SLLNode holdingPointer = First; 59 | First = First.Next; 60 | 61 | Length--; 62 | 63 | return holdingPointer.Value; 64 | } 65 | 66 | public void Display() 67 | { 68 | if (First == null) 69 | { 70 | return; 71 | } 72 | SLLNode currentSLLNode = First; 73 | Console.Write(currentSLLNode.Value); 74 | currentSLLNode = currentSLLNode.Next; 75 | while (currentSLLNode != null) 76 | { 77 | Console.Write(" " + currentSLLNode.Value); 78 | currentSLLNode = currentSLLNode.Next; 79 | } 80 | Console.WriteLine(); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/2-DynamicProgramming/Example(Fibonacci)/2-UsingDynamicProramming/1-MemoizedSolution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.DynamicProgramming 6 | { 7 | class MemoizedSolution 8 | { 9 | 10 | // Fibonacci Sequence = 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610 .... 11 | 12 | 13 | public Dictionary Cache = new Dictionary(); 14 | public int Fib1(int index) 15 | { 16 | 17 | if (index < 2) 18 | { 19 | return index; 20 | } 21 | if (Cache.ContainsKey(index)) 22 | { 23 | return Cache[index]; 24 | } 25 | else 26 | { 27 | Cache[index] = Fib1(index - 1) + Fib1(index - 2); 28 | return Cache[index]; 29 | } 30 | // Fib(6) 31 | 32 | // Fib(5) + Fib(4) 33 | 34 | // Fib(4) + Fib(3) 35 | 36 | // Fib(3) + Fib(2) 37 | 38 | // Fib(2) + Fib(1) 39 | } 40 | 41 | public Func Fib2() 42 | { 43 | var cache = new Dictionary(); 44 | 45 | return (index) => 46 | { 47 | if (index < 2) 48 | { 49 | return index; 50 | } 51 | 52 | if (cache.ContainsKey(index)) 53 | { 54 | return cache[index]; 55 | } 56 | 57 | else 58 | { 59 | cache[index] = Fib2()(index - 1) + Fib2()(index - 2); 60 | 61 | return cache[index]; 62 | } 63 | 64 | }; 65 | 66 | // Fib(6) 67 | 68 | // Fib(5) + Fib(4) 69 | 70 | // Fib(4) + Fib(3) 71 | 72 | // Fib(3) + Fib(2) 73 | 74 | // Fib(2) + Fib(1) 75 | } 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/1-LinkedList/LinkedListPractices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DataStructure.LinkedList 6 | { 7 | class LinkedListPractices 8 | { 9 | 10 | 11 | public static void CustomSingleLinkedList() 12 | { 13 | SingleLinkedList sentence = new SingleLinkedList(); 14 | sentence.AddFirst("This"); 15 | sentence.AddLast("Is"); 16 | sentence.AddLast("Linked"); 17 | sentence.AddLast("List"); 18 | sentence.AddLast("Lesson"); 19 | sentence.Remove(4); 20 | SLLNode IsNode2 = sentence.Find(2); 21 | sentence.AddAfter(IsNode2, "The"); 22 | sentence.Display(); 23 | 24 | sentence.Reverse(); 25 | sentence.Display(); 26 | 27 | } 28 | 29 | public static void CsharpBuiltInDoublyLinkedList() 30 | { 31 | LinkedList sentence = new LinkedList(); 32 | sentence.AddFirst("This"); 33 | sentence.AddLast("Is"); 34 | sentence.AddLast("Linked"); 35 | sentence.AddLast("List"); 36 | sentence.AddLast("Lesson"); 37 | LinkedListNode IsNode = sentence.Find("Is"); 38 | sentence.AddAfter(IsNode, "The"); 39 | Display(sentence); 40 | } 41 | 42 | 43 | public static void CustomDoublyLinkedList() 44 | { 45 | DoublyLinkedLists sentence = new DoublyLinkedLists(); 46 | sentence.AddFirst("This"); 47 | sentence.AddLast("Is"); 48 | sentence.AddLast("Linked"); 49 | sentence.AddLast("List"); 50 | sentence.AddLast("Lesson"); 51 | DLLNode IsNode2 = sentence.Find("Is"); 52 | sentence.AddAfter(IsNode2, "The"); 53 | sentence.Display(); 54 | 55 | //sentence.Reverse(); 56 | //sentence.Display(); 57 | 58 | } 59 | 60 | 61 | 62 | 63 | 64 | public static void Display(LinkedList linkedList) 65 | { 66 | 67 | foreach (T Item in linkedList) 68 | { 69 | Console.Write(Item + " "); 70 | } 71 | Console.WriteLine(); 72 | Console.WriteLine(); 73 | } 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/4-HashTable/HashtablePractices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace DataStructure.HashTable 7 | { 8 | class HashtablePractices 9 | { 10 | public static void CsharpBuiltInHashtable() 11 | { 12 | Hashtable myHashtable = new Hashtable(); 13 | myHashtable.Add("First", "One"); 14 | myHashtable.Add("Second", "Two"); 15 | myHashtable.Add("Third", "Three"); 16 | myHashtable.Add("Four", "Three"); 17 | myHashtable.Add(9, "Nine"); 18 | myHashtable.Remove(9); 19 | Console.WriteLine(myHashtable["Third"]); 20 | 21 | Display(myHashtable); 22 | 23 | 24 | 25 | } 26 | 27 | public static void CustomHashtableWithoutHandlingCollision() 28 | { 29 | CustomHashTable myHashtable = new CustomHashTable(); 30 | myHashtable.Add("First", "One"); 31 | myHashtable.Add("Second", "Two"); 32 | myHashtable.Add("Third", "Three"); 33 | myHashtable.Add("Four", "Three"); 34 | myHashtable.Add(9, "Nine"); 35 | //myHashtable.Add(8, "Eight"); // will make collision with First because (First and 8) keys have the same hash which equals 6 36 | 37 | myHashtable.Remove(9); 38 | Console.WriteLine(myHashtable["Third"]); 39 | 40 | myHashtable.Display(); 41 | 42 | } 43 | 44 | public static void Display(Hashtable hashTable) 45 | { 46 | foreach (DictionaryEntry de in hashTable) 47 | Console.WriteLine("Key: {0}, Value: {1}", de.Key, de.Value); 48 | 49 | Console.WriteLine("\n\n"); 50 | } 51 | 52 | 53 | public static void HandlingCollisionUsingSeparateChaining() 54 | { 55 | CustomHashTable2 myHashtable = new CustomHashTable2(); 56 | myHashtable.Add(10, "Mohamed"); 57 | myHashtable.Add(11, "Khalid"); 58 | myHashtable.Add(12, "Mahmod"); 59 | myHashtable.Add(13, "Ibrahim"); 60 | myHashtable.Add(14, "Ali"); 61 | myHashtable.Add(20, "Moaz"); 62 | myHashtable.Remove(14); 63 | Console.WriteLine(myHashtable[20]); 64 | 65 | myHashtable.Display(); 66 | 67 | } 68 | 69 | 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/2-Stack/1-StackUsingLinkedList.cs: -------------------------------------------------------------------------------- 1 | using DataStructure.LinkedList; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace DataStructure.Stack 7 | { 8 | 9 | class StackUsingLinkedList 10 | { 11 | public SLLNode Top; 12 | public SLLNode Bottom; 13 | public int Length; 14 | 15 | public StackUsingLinkedList() 16 | { 17 | Top = null; 18 | Bottom = null; 19 | Length = 0; 20 | } 21 | 22 | public T Peek() 23 | { 24 | if (Length > 0) 25 | return Top.Value; 26 | return default(T); 27 | } 28 | 29 | public void Push(T value) 30 | { 31 | SLLNode newNode = new SLLNode(value); 32 | if (Length == 0) 33 | { 34 | Top = newNode; 35 | Bottom = newNode; 36 | } 37 | else 38 | { 39 | SLLNode holdingPointer = Top; 40 | Top = newNode; 41 | Top.Next = holdingPointer; 42 | } 43 | Length++; 44 | } 45 | 46 | public T Pop() 47 | { 48 | if (Top == null) 49 | { 50 | return default(T); 51 | } 52 | SLLNode holdingPointer = Top; 53 | Top = Top.Next; 54 | Length--; 55 | return holdingPointer.Value; 56 | } 57 | 58 | 59 | public T ElementAt(int index) 60 | { 61 | int counter = 0; 62 | var currentNode = Top; 63 | while (counter != index) 64 | { 65 | currentNode = currentNode.Next; 66 | counter++; 67 | } 68 | return currentNode.Value; 69 | } 70 | 71 | 72 | public void Display() 73 | { 74 | if (Top == null) 75 | { 76 | return; 77 | } 78 | SLLNode currentNode = Top; 79 | Console.Write(currentNode.Value); 80 | currentNode = currentNode.Next; 81 | while (currentNode != null) 82 | { 83 | Console.Write(" " + currentNode.Value); 84 | currentNode = currentNode.Next; 85 | } 86 | Console.WriteLine("\n"); 87 | } 88 | 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/3-Searching_Traversing/BreadthFirstSearch/2-BFSforGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Algorithms.Searching_Traversing 7 | { 8 | class BFSforGraph 9 | { 10 | public static void BFS(Graph graph, T v) 11 | { 12 | var visited = new List(); 13 | 14 | 15 | 16 | Queue queue = new Queue(); 17 | 18 | // Mark the current node as 19 | // visited and enqueue it 20 | visited.Add(v); 21 | queue.Enqueue(v); 22 | 23 | while (queue.Any()) 24 | { 25 | 26 | v = queue.First(); 27 | Console.Write(v + " "); 28 | queue.Dequeue(); 29 | 30 | var list = graph.AdjacentList[v]; 31 | 32 | foreach (var val in list) 33 | { 34 | if (!visited.Contains(val)) 35 | { 36 | visited.Add(val); 37 | queue.Enqueue(val); 38 | } 39 | } 40 | } 41 | } 42 | 43 | public static void BFS(Graph graph) 44 | { 45 | var visited = new List(); 46 | foreach (var adj in graph.AdjacentList) 47 | { 48 | 49 | 50 | if (!visited.Contains(adj.Key)) 51 | { 52 | Queue queue = new Queue(); 53 | 54 | // Mark the current node as 55 | // visited and enqueue it 56 | visited.Add(adj.Key); 57 | queue.Enqueue(adj.Key); 58 | 59 | while (queue.Any()) 60 | { 61 | 62 | var v = queue.First(); 63 | Console.Write(v + " "); 64 | queue.Dequeue(); 65 | 66 | var list = graph.AdjacentList[v]; 67 | 68 | foreach (var val in list) 69 | { 70 | if (!visited.Contains(val)) 71 | { 72 | visited.Add(val); 73 | queue.Enqueue(val); 74 | } 75 | } 76 | } 77 | } 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/4-Sorting/4-MergeSort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | class MergeSort 4 | { 5 | 6 | public static int T (int n) 7 | { 8 | if (n <= 1) 9 | return 0; 10 | 11 | return 2 * T(n / 2) + n; 12 | 13 | } 14 | 15 | #region Divide Part 16 | public static int[] Sort(int[] array) 17 | { 18 | 19 | //As this is a recursive algorithm, we need to have a base case to 20 | //avoid an infinite recursion and therfore a stackoverflow 21 | if (array.Length <= 1) 22 | return array; 23 | 24 | 25 | 26 | int[] left; 27 | int[] right; 28 | 29 | int midPoint = array.Length / 2; 30 | var leftLen = array.Length - midPoint; 31 | var rightLen = midPoint; 32 | left = new int[leftLen]; 33 | right = new int[rightLen]; 34 | 35 | 36 | for (int i = 0; i < leftLen; i++) 37 | left[i] = array[i]; 38 | 39 | for (int i = leftLen; i < array.Length; i++) 40 | right[i - (leftLen)] = array[i]; 41 | 42 | left = Sort(left); 43 | right = Sort(right); 44 | 45 | //Merge our two sorted arrays 46 | return Merge(left, right); 47 | 48 | } 49 | #endregion 50 | 51 | #region Conquer Part 52 | private static int[] Merge(int[] left, int[] right) 53 | { 54 | var leftLength = left.Length; 55 | var rightLength = right.Length; 56 | int resultLength = right.Length + left.Length; 57 | int[] result = new int[resultLength]; 58 | 59 | int leftindex = 0, rightIndex = 0, resultIndex = 0; 60 | 61 | 62 | while (leftindex < leftLength && rightIndex < rightLength) 63 | { 64 | if (left[leftindex] <= right[rightIndex]) 65 | { 66 | result[resultIndex] = left[leftindex]; 67 | leftindex++; 68 | } 69 | else 70 | { 71 | result[resultIndex] = right[rightIndex]; 72 | rightIndex++; 73 | } 74 | resultIndex++; 75 | } 76 | 77 | // Copy remaining elements of L[] if any 78 | while (leftindex < leftLength) 79 | { 80 | result[resultIndex] = left[leftindex]; 81 | leftindex++; 82 | resultIndex++; 83 | } 84 | 85 | // Copy remaining elements of R[] if any 86 | while (rightIndex < rightLength) 87 | { 88 | result[resultIndex] = right[rightIndex]; 89 | rightIndex++; 90 | resultIndex++; 91 | } 92 | return result; 93 | } 94 | #endregion 95 | 96 | } 97 | 98 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/1-Basics/7-O(nLogn).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class MergeSort 8 | { 9 | 10 | #region Divide Part 11 | public static int[] Sort(int[] array) 12 | { 13 | 14 | //As this is a recursive algorithm, we need to have a base case to 15 | //avoid an infinite recursion and therfore a stackoverflow 16 | if (array.Length <= 1) 17 | return array; 18 | 19 | 20 | 21 | int[] left; 22 | int[] right; 23 | 24 | int midPoint = array.Length / 2; 25 | var leftLen = array.Length - midPoint; 26 | var rightLen = midPoint; 27 | left = new int[leftLen]; 28 | right = new int[rightLen]; 29 | 30 | 31 | for (int i = 0; i < leftLen; i++) 32 | left[i] = array[i]; 33 | 34 | for (int i = leftLen; i < array.Length; i++) 35 | right[i - (leftLen)] = array[i]; 36 | 37 | left = Sort(left); 38 | right = Sort(right); 39 | 40 | return Merge(left, right); 41 | 42 | } 43 | #endregion 44 | 45 | #region Conquer Part 46 | private static int[] Merge(int[] left, int[] right) 47 | { 48 | var leftLength = left.Length; 49 | var rightLength = right.Length; 50 | int resultLength = right.Length + left.Length; 51 | int[] result = new int[resultLength]; 52 | 53 | int leftindex = 0, rightIndex = 0, resultIndex = 0; 54 | 55 | 56 | while (leftindex < leftLength && rightIndex < rightLength) 57 | { 58 | if (left[leftindex] <= right[rightIndex]) 59 | { 60 | result[resultIndex] = left[leftindex]; 61 | leftindex++; 62 | } 63 | else 64 | { 65 | result[resultIndex] = right[rightIndex]; 66 | rightIndex++; 67 | } 68 | resultIndex++; 69 | } 70 | 71 | // Copy remaining elements of L[] if any 72 | while (leftindex < leftLength) 73 | { 74 | result[resultIndex] = left[leftindex]; 75 | leftindex++; 76 | resultIndex++; 77 | } 78 | 79 | // Copy remaining elements of R[] if any 80 | while (rightIndex < rightLength) 81 | { 82 | result[resultIndex] = right[rightIndex]; 83 | rightIndex++; 84 | resultIndex++; 85 | } 86 | return result; 87 | } 88 | #endregion 89 | 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/4-HashTable/1-WithoutHandlingCollision/1-CustomHashTable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DataStructure.HashTable 7 | { 8 | 9 | 10 | class CustomHashTable 11 | { 12 | 13 | Dictionary data; 14 | 15 | public CustomHashTable() 16 | { 17 | data = new Dictionary(); 18 | } 19 | private int Hash(object key) 20 | { 21 | var keytoString = key.ToString(); 22 | int hash = 0; 23 | for (int i = 0; i < keytoString.Length; i++) 24 | { 25 | hash = hash * 15 + (int)keytoString[i]; 26 | } 27 | hash = hash % 10; 28 | return hash; 29 | 30 | } 31 | public object this[object key] 32 | { 33 | get 34 | { 35 | 36 | int hashKey = Hash(key); 37 | try 38 | { 39 | return data[hashKey].Value; 40 | } 41 | 42 | catch (Exception) 43 | { 44 | 45 | Console.WriteLine("This key (" + key + ") is not exist"); 46 | return null; 47 | } 48 | } 49 | 50 | } 51 | 52 | 53 | 54 | public void Add(object key, object value) 55 | { 56 | 57 | int hashKey = Hash(key); 58 | try 59 | { 60 | data.Add(hashKey, new HashNode(key, value)); 61 | } 62 | 63 | catch 64 | { 65 | Console.WriteLine("This key is used before"); 66 | return; 67 | } 68 | 69 | } 70 | 71 | public void Remove(object key) 72 | { 73 | int hashKey = Hash(key); 74 | try 75 | { 76 | data.Remove(hashKey); 77 | } 78 | 79 | catch 80 | { 81 | Console.WriteLine("This key is not exist"); 82 | return; 83 | } 84 | } 85 | 86 | 87 | public List keys() 88 | { 89 | List result = new List(); 90 | foreach (var item in data) 91 | { 92 | result.Add(item.Key.ToString()); 93 | } 94 | 95 | return result; 96 | } 97 | 98 | 99 | 100 | public void Display() 101 | { 102 | foreach (var obje in data) 103 | { 104 | Console.WriteLine("Key: {0}, Value: {1}", obje.Value.Key, obje.Value.Value); 105 | } 106 | 107 | Console.WriteLine("\n\n"); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/5-Trees/TreesPractices.cs: -------------------------------------------------------------------------------- 1 | using DataStructure.Trees.BinarySearchTree; 2 | using DataStructure.Trees.BinarySearchTree.Helper; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace DataStructure.Trees.BinaryTree 8 | { 9 | public class TreesPractices 10 | { 11 | public static void CustomBinaryTree() 12 | { 13 | BinaryTree tree = new BinaryTree(); 14 | 15 | 16 | tree.root = new BTNode(1); 17 | 18 | tree.root.Left = new BTNode(2); 19 | tree.root.Right = new BTNode(3); 20 | 21 | var rootLeft = tree.root.Left; 22 | rootLeft.Left = new BTNode(4); 23 | 24 | 25 | // 1 26 | // / \ 27 | // 2 3 28 | // / \ / \ 29 | // 4 null null null 30 | // / \ 31 | // null null 32 | 33 | 34 | } 35 | 36 | public static void CustomBinarySearchTree() 37 | { 38 | BinarySearchTree BST = new BinarySearchTree(); 39 | BST.insert(new TypeB(8, "Mohamed")); 40 | BST.insert(new TypeB(5, "Ibrahim")); 41 | BST.insert(new TypeB(20, "Youssef")); 42 | BST.insert(new TypeB(3, "Ismail")); 43 | BST.insert(new TypeB(6, "Mahmoud")); 44 | BST.insert(new TypeB(15, "Yahya")); 45 | BST.insert(new TypeB(110, "Khalid")); 46 | 47 | // 8 48 | // / \ 49 | // 5 20 50 | // / \ / \ 51 | // 3 6 15 110 52 | 53 | 54 | BST.printTree(); 55 | 56 | var node = BST.Search(20); 57 | Console.WriteLine( 58 | "\n Value = " + node.Obj.Value + 59 | "\n Left Node Value = " + node.Left.Obj.Value + 60 | "\n Right Node Value = " + node.Right.Obj.Value); 61 | 62 | 63 | //BST.insert(new TypeB(150, "Khalid")); 64 | //BST.insert(new TypeB(100, "Khalid")); 65 | //BST.insert(new TypeB(200, "Khalid")); 66 | 67 | //BST.insert(new TypeB(120, "Khalid")); 68 | 69 | //BST.insert(new TypeB(2, "Khalid")); 70 | //BST.insert(new TypeB(4, "Khalid")); 71 | 72 | //BST.Remove(110); 73 | 74 | 75 | // 8 76 | // / \ 77 | // 5 20 78 | // / \ / \ 79 | // 3 6 15 110 80 | // / \ / \ 81 | // 2 4 100 150 82 | // / \ 83 | // 120 200 84 | 85 | 86 | 87 | 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/3-Searching_Traversing/Helper/BinarySearchTree/1-BinarySearchTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Searching_Traversing 6 | { 7 | class BinarySearchTree 8 | { 9 | public Node Root { get; set; } 10 | public BinarySearchTree() 11 | { 12 | Root = null; 13 | } 14 | public void Insert(int value) 15 | { 16 | var newNode = new Node(value); 17 | 18 | if (Root == null) 19 | { 20 | Root = newNode; 21 | return; 22 | } 23 | 24 | var current = Root; 25 | while (true) 26 | { 27 | if (value < current.Value) 28 | { 29 | if (current.Left == null) 30 | { 31 | current.Left = newNode; 32 | return; 33 | } 34 | current = current.Left; 35 | } 36 | else if (value > current.Value) 37 | { 38 | if (current.Right == null) 39 | { 40 | current.Right = newNode; 41 | return; 42 | } 43 | current = current.Right; 44 | } 45 | } 46 | 47 | } 48 | 49 | 50 | public Node Search(int value) 51 | { 52 | if (Root == null) 53 | { 54 | return null; 55 | } 56 | Node currentNode = Root; 57 | while (currentNode != null) 58 | { 59 | if (value < currentNode.Value) 60 | { 61 | currentNode = currentNode.Left; 62 | } 63 | else if (value > currentNode.Value) 64 | { 65 | currentNode = currentNode.Right; 66 | } 67 | else 68 | { 69 | return currentNode; 70 | } 71 | } 72 | return null; 73 | } 74 | 75 | 76 | public void PrintTree() 77 | { 78 | print2DUtil(Root, 0); 79 | } 80 | 81 | private void print2DUtil(Node root, int space, int COUNT = 5) 82 | { 83 | 84 | if (root == null) 85 | return; 86 | 87 | // Increase distance between levels 88 | space += COUNT; 89 | 90 | // Process right child first 91 | print2DUtil(root.Right, space); 92 | 93 | // Print current node after space 94 | // count 95 | Console.Write("\n"); 96 | for (int i = COUNT; i < space; i++) 97 | { 98 | Console.Write(" "); 99 | } 100 | Console.Write(root.Value + "\n"); 101 | 102 | // Process left child 103 | print2DUtil(root.Left, space); 104 | } 105 | 106 | 107 | 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BigO 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | #region Basics 10 | 11 | #region Linear 12 | //Linear.PrinFromOneToNumber(5); 13 | #endregion 14 | 15 | #region Constant 16 | //Constant.PrintNumber(5); 17 | #endregion 18 | 19 | #region Quadratic 20 | //Square.MultiplicationTable(12); 21 | #endregion 22 | 23 | #region Factorial 24 | //Factorial.PrintUntilFactorial(6); 25 | #endregion 26 | 27 | #region Exponential 28 | //Exponential.PowerSet("ABC"); 29 | #endregion 30 | 31 | #region Logarithmic 32 | //BinarySearchTree BST = new BinarySearchTree(); 33 | //BST.Insert(8); 34 | //BST.Insert(5); 35 | //BST.Insert(20); 36 | //BST.Insert(1); 37 | //BST.Insert(6); 38 | //BST.Insert(15); 39 | //BST.Insert(110); 40 | //BST.printTree(); 41 | 42 | //// 8 43 | //// / \ 44 | //// 5 20 45 | //// / \ / \ 46 | //// 1 6 15 110 47 | 48 | //var node = BST.Search(20); 49 | //Console.WriteLine( 50 | // "\n Value = " + node.Value + 51 | // "\n Left Node Value = " + node.Left.Value + 52 | // "\n Right Node Value = " + node.Right.Value); 53 | #endregion 54 | 55 | #region Linearithmic 56 | //var arr4 = new int[] { 50, 40, 30, 70, 60, 90, 80 }; 57 | //var arrAfterMS = MergeSort.Sort(arr4); 58 | //Console.WriteLine(string.Join(", ", arrAfterMS)); 59 | #endregion 60 | 61 | 62 | #endregion 63 | 64 | #region 2-Simplify BigO 65 | 66 | #region Rule1 (Worst Case) 67 | //var Names = new string[] 68 | //{"Ahmed","Fatima" ,"Ali", "khadija", "Mahmoud", 69 | // "Aisha", "Khalid", "Ibrahim", "Mohamed" }; 70 | //WorstCase.FindNameInArray(Names, "Mohamed"); 71 | #endregion 72 | 73 | #region Rule2 (Remove Constants) 74 | //RemoveConstants.PrintFromOneToNumberTwiceAndFromOneToTen(20); 75 | #endregion 76 | 77 | #region Rule3 (Different Terms For Inputs) 78 | //var arr1 = new int[] {1,2,3,4,5,6 }; 79 | //var arr2 = new int[] {1,2,3}; 80 | //DifferentTermsForInputs.PrintNumberInTwoArrays(arr1,arr2); 81 | #endregion 82 | 83 | #region Rule4 (Drop Non Dominants) 84 | //DropNonDominants.PrintDone(3); 85 | #endregion 86 | 87 | #endregion 88 | 89 | #region 3-Example 90 | //var result1 = Example.HasPairWithSum(new int[] { 1, 2, 9, 4 }, 5); 91 | //var result2 = Example.HasPairWithSum2(new int[] { 1, 2, 9, 4 }, 5); 92 | //Console.WriteLine("Result 1 : " + result1 + " Result2 : " + result2); 93 | #endregion 94 | 95 | } 96 | 97 | } 98 | } 99 | 100 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/3-Searching_Traversing/DepthFirstSearch/1-DFSforTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Algorithms.Searching_Traversing 6 | { 7 | 8 | class DFSforTree 9 | { 10 | 11 | public static List TraversePreOrder(Node node, List list) 12 | { 13 | list.Add(node.Value); 14 | 15 | if (node.Left != null) 16 | { 17 | TraversePreOrder(node.Left, list); 18 | } 19 | 20 | if (node.Right != null) 21 | { 22 | TraversePreOrder(node.Right, list); 23 | } 24 | 25 | return list; 26 | 27 | /* 28 | 9 29 | TraversePreOrder(node 9) 30 | 4 31 | TraversePreOrder(node 4) 32 | 1 33 | TraversePreOrder(node 1) 34 | 6 35 | TraversePreOrder(node 6) 36 | 20 37 | TraversePreOrder(node 20) 38 | 15 39 | TraversePreOrder(node 15) 40 | 170 41 | TraversePreOrder(node 170) 42 | */ 43 | 44 | // 9, 4, 1, 6, 20, 15, 170 45 | } 46 | 47 | public static List TraverseInOrder(Node node, List list) 48 | { 49 | if (node.Left != null) 50 | { 51 | TraverseInOrder(node.Left, list); 52 | } 53 | 54 | list.Add(node.Value); 55 | 56 | if (node.Right != null) 57 | { 58 | TraverseInOrder(node.Right, list); 59 | } 60 | 61 | return list; 62 | 63 | /* 64 | TraversePreOrder(node 9) 65 | TraversePreOrder(node 4) 66 | TraversePreOrder(node 1) 67 | 1 68 | 4 69 | TraversePreOrder(node 6) 70 | 6 71 | 9 72 | TraversePreOrder(node 20) 73 | TraversePreOrder(node 15) 74 | 15 75 | 20 76 | TraversePreOrder(node 170) 77 | 170 78 | */ 79 | // 1, 4, 6, 9, 15, 20, 170 80 | 81 | } 82 | 83 | 84 | public static List TraversePostOrder(Node node, List list) 85 | { 86 | if (node.Left != null) 87 | { 88 | TraversePostOrder(node.Left, list); 89 | } 90 | 91 | if (node.Right != null) 92 | { 93 | TraversePostOrder(node.Right, list); 94 | } 95 | list.Add(node.Value); 96 | 97 | return list; 98 | 99 | /* 100 | TraversePreOrder(node 4) 101 | TraversePreOrder(node 1) 102 | 1 103 | TraversePreOrder(node 6) 104 | 6 105 | 4 106 | TraversePreOrder(node 20) 107 | TraversePreOrder(node 15) 108 | 15 109 | TraversePreOrder(node 170) 110 | 170 111 | 20 112 | 9 113 | */ 114 | // 1, 6, 4, 15, 170, 20, 9 115 | } 116 | 117 | 118 | 119 | } 120 | } -------------------------------------------------------------------------------- /1- Big O/BigO/BigO/1-Basics/6-O(log n).cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace BigO 6 | { 7 | class Node 8 | { 9 | public int Value { get; set; } 10 | public Node Left { get; set; } 11 | public Node Right { get; set; } 12 | 13 | public Node(int value) 14 | { 15 | Value = value; 16 | Left = null; 17 | Right = null; 18 | } 19 | } 20 | 21 | 22 | class BinarySearchTree 23 | { 24 | public Node Root { get; set; } 25 | public BinarySearchTree() 26 | { 27 | Root = null; 28 | } 29 | public void Insert(int value) 30 | { 31 | var newNode = new Node(value); 32 | 33 | if (Root == null) 34 | { 35 | Root = newNode; 36 | return; 37 | } 38 | 39 | var current = Root; 40 | while (true) 41 | { 42 | if (value < current.Value) 43 | { 44 | if (current.Left == null) 45 | { 46 | current.Left = newNode; 47 | return; 48 | } 49 | current = current.Left; 50 | } 51 | else if (value > current.Value) 52 | { 53 | if (current.Right == null) 54 | { 55 | current.Right = newNode; 56 | return; 57 | } 58 | current= current.Right; 59 | } 60 | } 61 | 62 | } 63 | 64 | 65 | public Node Search(int value) 66 | { 67 | if (Root == null) 68 | { 69 | return null; 70 | } 71 | Node currentNode = Root; 72 | while (currentNode != null) 73 | { 74 | if (value < currentNode.Value) 75 | { 76 | currentNode = currentNode.Left; 77 | } 78 | else if (value > currentNode.Value) 79 | { 80 | currentNode = currentNode.Right; 81 | } 82 | else 83 | { 84 | return currentNode; 85 | } 86 | } 87 | return null; 88 | } 89 | 90 | 91 | public void printTree() 92 | { 93 | print2DUtil(Root, 0); 94 | } 95 | 96 | private void print2DUtil(Node root, int space, int COUNT = 5) 97 | { 98 | 99 | if (root == null) 100 | return; 101 | 102 | // Increase distance between levels 103 | space += COUNT; 104 | 105 | // Process right child first 106 | print2DUtil(root.Right, space); 107 | 108 | // Print current node after space 109 | // count 110 | Console.Write("\n"); 111 | for (int i = COUNT; i < space; i++) 112 | { 113 | Console.Write(" "); 114 | } 115 | Console.Write(root.Value + "\n"); 116 | 117 | // Process left child 118 | print2DUtil(root.Left, space); 119 | } 120 | 121 | 122 | 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/1-LinkedList/1-SingleLinkedList/2-SingleLinkedList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataStructure.LinkedList 4 | { 5 | 6 | public class SingleLinkedList 7 | { 8 | private SLLNode Head; 9 | private SLLNode Tail; 10 | private int Length; 11 | public int getLength() 12 | { 13 | return Length; 14 | } 15 | 16 | public SLLNode getHead() 17 | { 18 | return Head; 19 | } 20 | 21 | public SLLNode getTail() 22 | { 23 | return Tail; 24 | } 25 | public SingleLinkedList() 26 | { 27 | Length = 0; 28 | } 29 | 30 | 31 | public void AddFirst(T value) // In some language called (prepend) 32 | { 33 | 34 | var newNode = new SLLNode(value); 35 | newNode.Next = Head; 36 | Head = newNode; 37 | 38 | if (Length == 0) 39 | { 40 | Tail = Head; 41 | } 42 | Length++; 43 | } 44 | 45 | public void AddLast(T value) // In some language called (append) 46 | { 47 | var newNode = new SLLNode(value); 48 | Tail.Next = newNode; 49 | Tail = newNode; 50 | if (Length == 0) 51 | { 52 | Head = Tail; 53 | } 54 | Length++; 55 | } 56 | 57 | 58 | public void AddAfter(SLLNode Node, T value) 59 | { 60 | if (Node != null) 61 | { 62 | var newNode = new SLLNode(value); 63 | var holdingPointer = Node.Next; 64 | Node.Next = newNode; 65 | newNode.Next = holdingPointer; 66 | Length++; 67 | } 68 | else 69 | { 70 | Console.WriteLine("The Node You Passed Not Exist"); 71 | } 72 | } 73 | 74 | public void Remove(int index) 75 | { 76 | 77 | var UnWantedNode = Find(index); 78 | var PrevOfUnWantedNode = Find(index - 1); 79 | 80 | if (PrevOfUnWantedNode != null) 81 | { 82 | PrevOfUnWantedNode.Next = UnWantedNode.Next; 83 | Length--; 84 | } 85 | else 86 | { 87 | Console.WriteLine("The Value You Passed Not Exist"); 88 | } 89 | } 90 | 91 | 92 | public SLLNode Find(int index) 93 | { 94 | int counter = 0; 95 | var currentNode = Head; 96 | while (counter != index) 97 | { 98 | currentNode = currentNode.Next; 99 | counter++; 100 | } 101 | return currentNode; 102 | } 103 | 104 | 105 | public void Reverse() 106 | { 107 | SLLNode first = Head; 108 | Tail = Head; 109 | 110 | SLLNode second = first.Next; 111 | while (second != null) 112 | { 113 | SLLNode temp = second.Next; 114 | second.Next = first; 115 | first = second; 116 | second = temp; 117 | } 118 | Head.Next = null;//because head become tail 119 | Head = first; 120 | } 121 | 122 | public void Display() 123 | { 124 | if (Head == null) 125 | { 126 | return; 127 | } 128 | var current = Head; 129 | while (current != null) 130 | { 131 | Console.Write(current.Value + " "); 132 | current = current.Next; 133 | } 134 | Console.WriteLine(); 135 | } 136 | 137 | } 138 | } 139 | 140 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/1-LinkedList/2-DoublyLinkedLists/2-DoublyLinkedLists.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DataStructure.LinkedList 4 | { 5 | 6 | public class DoublyLinkedLists 7 | { 8 | private DLLNode Head; 9 | private DLLNode Tail; 10 | private int Length; 11 | public int getLength() 12 | { 13 | return Length; 14 | } 15 | 16 | public DLLNode getHead() 17 | { 18 | return Head; 19 | } 20 | 21 | public DLLNode getTail() 22 | { 23 | return Tail; 24 | } 25 | public DoublyLinkedLists() 26 | { 27 | Length = 0; 28 | } 29 | 30 | 31 | public void AddFirst(T value) // In some language called (prepend) 32 | { 33 | 34 | var newNode = new DLLNode(value); 35 | newNode.Next = Head; 36 | newNode.Previous = null; 37 | 38 | if (Head != null) 39 | Head.Previous = newNode; 40 | 41 | Head = newNode; 42 | 43 | if (Length == 0) 44 | { 45 | Tail = Head; 46 | } 47 | 48 | Length++; 49 | 50 | } 51 | 52 | 53 | 54 | public void AddLast(T value) // In some language called (append) 55 | { 56 | var newNode = new DLLNode(value); 57 | newNode.Previous = Tail; 58 | newNode.Next = null; 59 | 60 | if (Length == 0) 61 | { 62 | Head = Tail; 63 | } 64 | 65 | if (Tail != null) 66 | Tail.Next = newNode; 67 | 68 | Tail = newNode; 69 | 70 | 71 | 72 | Length++; 73 | } 74 | 75 | 76 | public void AddAfter(DLLNode node, T value) 77 | { 78 | if (node != null) 79 | { 80 | var newNode = new DLLNode(value); 81 | var holdingPointerToNext = node.Next; 82 | 83 | node.Next = newNode; 84 | newNode.Previous = newNode; 85 | 86 | newNode.Next = holdingPointerToNext; 87 | holdingPointerToNext.Previous = newNode; 88 | 89 | 90 | newNode.Previous = node; 91 | Length++; 92 | } 93 | else 94 | { 95 | Console.WriteLine("The Node You Passed Not Exist"); 96 | } 97 | } 98 | 99 | public void Remove(T value) 100 | { 101 | 102 | var UnWantedNode = Find(value); 103 | 104 | if (UnWantedNode != null) 105 | { 106 | var nextOfUnWantedNode = UnWantedNode.Next; 107 | var PrevOfUnWantedNode = UnWantedNode.Previous; 108 | PrevOfUnWantedNode.Next = nextOfUnWantedNode; 109 | Length--; 110 | } 111 | else 112 | { 113 | Console.WriteLine("The Value You Passed Not Exist"); 114 | } 115 | } 116 | 117 | public DLLNode Find(T value) 118 | { 119 | int counter = 0; 120 | var currentNode = Head; 121 | while (!currentNode.Value.Equals(value)) 122 | { 123 | currentNode = currentNode.Next; 124 | counter++; 125 | } 126 | return currentNode; 127 | } 128 | public void Reverse() 129 | { 130 | DLLNode first = Head; 131 | Tail = Head; 132 | 133 | DLLNode second = first.Next; 134 | while (second != null) 135 | { 136 | DLLNode temp = second.Next; 137 | second.Next = first; 138 | first.Previous = second; 139 | 140 | first = second; 141 | second = temp; 142 | } 143 | 144 | Head.Next = null;//because head become tail 145 | Head = first; 146 | Head.Previous = null; 147 | } 148 | 149 | public void Display() 150 | { 151 | if (Head == null) 152 | { 153 | return; 154 | } 155 | var current = Head; 156 | while (current != null) 157 | { 158 | Console.Write(current.Value + " "); 159 | current = current.Next; 160 | } 161 | Console.WriteLine(); 162 | } 163 | 164 | } 165 | } 166 | 167 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/4-HashTable/2-HandlingCollisionUsingSeparateChaining/2-CustomHashTable2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DataStructure.HashTable 7 | { 8 | 9 | 10 | class CustomHashTable2 11 | { 12 | 13 | Dictionary> data; 14 | 15 | public CustomHashTable2() 16 | { 17 | data = new Dictionary>(); 18 | } 19 | private int Hash(object key) 20 | { 21 | var keytoString = key.ToString(); 22 | int hash = 0; 23 | Int32.TryParse(keytoString, out hash); 24 | if (hash != 0) 25 | return hash % 10; 26 | 27 | 28 | for (int i = 0; i < keytoString.Length; i++) 29 | { 30 | hash = hash +15* (int)keytoString[i]; 31 | } 32 | hash = hash % 10; 33 | return hash; 34 | 35 | } 36 | 37 | 38 | 39 | public object this[object key] 40 | { 41 | get 42 | { 43 | int hashKey = Hash(key); 44 | if (data.ContainsKey(hashKey)) 45 | { 46 | foreach (var hashNode in data[hashKey]) 47 | { 48 | if (hashNode.Key.Equals(key)) 49 | return hashNode.Value; 50 | } 51 | } 52 | Console.WriteLine("This key (" + key + ") is not exist"); 53 | return null; 54 | } 55 | 56 | } 57 | 58 | 59 | 60 | 61 | 62 | public void Add(object key, object value) 63 | { 64 | 65 | 66 | if (Keys().Contains(key.ToString())) 67 | { 68 | Console.WriteLine("This key is used before"); 69 | return; 70 | } 71 | 72 | 73 | //If Collision Exists 74 | int hashKey = Hash(key); 75 | if (data.Keys.Contains(hashKey)) 76 | { 77 | foreach (var item in data) 78 | { 79 | if (item.Key.Equals(hashKey)) 80 | { 81 | data[hashKey].AddLast(new HashNode(key, value)); 82 | return; 83 | } 84 | } 85 | } 86 | 87 | 88 | 89 | var listOfHashNode = new LinkedList(); 90 | listOfHashNode.AddLast(new HashNode(key, value)); 91 | data.Add(hashKey, listOfHashNode); 92 | 93 | } 94 | 95 | public void Remove(object key) 96 | { 97 | 98 | 99 | int hashKey = Hash(key); 100 | try 101 | { 102 | if (data[hashKey].Count == 1) 103 | { 104 | data.Remove(hashKey); 105 | return; 106 | } 107 | 108 | 109 | //If Collision Exist 110 | foreach (var item in data[hashKey]) 111 | { 112 | if (item.Key.Equals(key)) 113 | { 114 | var nodeToRemove = data[hashKey].SingleOrDefault(a => a.Key.Equals(key)); 115 | if (nodeToRemove != null) 116 | { 117 | data[hashKey].Remove(nodeToRemove); 118 | } 119 | } 120 | } 121 | } 122 | catch 123 | { 124 | Console.WriteLine("This key is not exist"); 125 | return; 126 | } 127 | } 128 | 129 | 130 | 131 | 132 | public List Keys() 133 | { 134 | List result = new List(); 135 | foreach (var item in data) 136 | { 137 | foreach (var hashNode in item.Value) 138 | { 139 | result.Add(hashNode.Key.ToString()); 140 | } 141 | } 142 | return result; 143 | } 144 | 145 | 146 | public void Display() 147 | { 148 | foreach (var item in data) 149 | { 150 | foreach (var hashNode in item.Value) 151 | { 152 | Console.WriteLine("Key: {0}, Value: {1}", hashNode.Key, hashNode.Value); 153 | } 154 | } 155 | Console.WriteLine("\n\n"); 156 | } 157 | } 158 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /3-Algorithms/Algorithms/Algorithms/Program.cs: -------------------------------------------------------------------------------- 1 | 2 | using Algorithms.DynamicProgramming; 3 | using Algorithms.Recursion; 4 | using Algorithms.Searching_Traversing; 5 | using Algorithms.Sorting; 6 | using System; 7 | using System.Collections.Generic; 8 | 9 | namespace Algorithms 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | 16 | 17 | #region 1-Recursion 18 | 19 | //Console.WriteLine("Factorial(" + 5 + ") Using Non-tail Recursion = " 20 | // + TailAndNon_TailRecursion.NonTRFact(5)); 21 | 22 | 23 | //Console.WriteLine("Factorial(" + 5 + ") Using Tail Recursion = " 24 | // + TailAndNon_TailRecursion.TRFact(5)); 25 | 26 | 27 | 28 | //Console.WriteLine("Factorial(" + 5 + ") Using Itteration : " 29 | // + Factorial.UsingItteration(5)); 30 | //Console.WriteLine("Factorial(" + 5 + ") Using Recursion : " 31 | // + Factorial.UsingRecursion(5)); 32 | 33 | 34 | //Console.WriteLine("Fibonacci(" + 5 + ") Using Itteration : " 35 | // + Fibonacci.UsingItteration(5)); 36 | //Console.WriteLine("Fibonacci(" + 5 + ") Using Recursion : " 37 | // + Fibonacci.UsingRecursion(5)); 38 | 39 | 40 | #endregion 41 | 42 | #region 2-Dynamic Programming 43 | 44 | //RecursiveSolution.Fib(6); 45 | 46 | //MemoizedSolution fm = new MemoizedSolution(); 47 | //Console.WriteLine(fm.Fib1(6)); 48 | //Console.WriteLine(fm.Fib2()(6)); 49 | 50 | //TabulatedSolution.Fib(6); 51 | 52 | #endregion 53 | 54 | #region 3-Searching_Traversing 55 | 56 | #region Breadth First Search For Tree 57 | //BinarySearchTree tree = new BinarySearchTree(); 58 | //tree.Insert(9); 59 | //tree.Insert(4); 60 | //tree.Insert(6); 61 | //tree.Insert(20); 62 | //tree.Insert(170); 63 | //tree.Insert(15); 64 | //tree.Insert(1); 65 | ///* 66 | // 9 67 | // / \ 68 | // 4 20 69 | // / \ / \ 70 | // 1 6 15 170 71 | //*/ 72 | 73 | #region BFS Iterative 74 | //var BFSIterativeResult = BFSforTree.BFS_Iterative(tree.Root); 75 | //Console.WriteLine(string.Join(", ", BFSIterativeResult)); 76 | //Console.WriteLine(); 77 | #endregion 78 | #region BFS Recurcive 79 | //List list = new List(); 80 | //Queue queue = new Queue(); 81 | //queue.Enqueue(tree.Root); 82 | //var BFSRecurciveResult = BFSforTree.BFS_Recurcive(queue, list); 83 | //Console.WriteLine(string.Join(", ", BFSRecurciveResult)); 84 | //Console.WriteLine(); 85 | #endregion 86 | #endregion 87 | 88 | #region Breadth First Search For graph 89 | 90 | 91 | #region Connected Graph 92 | 93 | 94 | //Graph myGraph1 = new Graph(true); 95 | //myGraph1.AddVertex("A"); 96 | //myGraph1.AddVertex("B"); 97 | //myGraph1.AddVertex("C"); 98 | //myGraph1.AddVertex("D"); 99 | //myGraph1.AddEdge("A", "B"); 100 | //myGraph1.AddEdge("A", "C"); 101 | //myGraph1.AddEdge("C", "A"); 102 | //myGraph1.AddEdge("B", "C"); 103 | //myGraph1.AddEdge("C", "D"); 104 | //myGraph1.AddEdge("D", "C"); 105 | //BFSforGraph.BFS(myGraph1, "C"); 106 | 107 | #endregion 108 | 109 | 110 | #region Disconnected Graph 111 | 112 | //Graph myGraph2 = new Graph(true); 113 | //myGraph2.AddVertex("A"); 114 | //myGraph2.AddVertex("B"); 115 | //myGraph2.AddVertex("C"); 116 | //myGraph2.AddVertex("D"); 117 | //myGraph2.AddEdge("A", "B"); 118 | //myGraph2.AddEdge("C", "D"); 119 | //BFSforGraph.BFS(myGraph2); 120 | #endregion 121 | #endregion 122 | 123 | 124 | #region Depth First Search For tree 125 | //BinarySearchTree BTree2 = new BinarySearchTree(); 126 | //BTree2.Insert(9); 127 | //BTree2.Insert(4); 128 | //BTree2.Insert(6); 129 | //BTree2.Insert(20); 130 | //BTree2.Insert(170); 131 | //BTree2.Insert(15); 132 | //BTree2.Insert(1); 133 | ///* 134 | // 9 135 | // / \ 136 | // 4 20 137 | // / \ / \ 138 | // 1 6 15 170 139 | //*/ 140 | //var result1 = DFSforTree.TraversePreOrder(BTree2.Root, new List()); 141 | //Console.WriteLine(string.Join(", ", result1) + "\n"); 142 | //// 9, 4, 1, 6, 20, 15, 170 143 | 144 | //var result2 = DFSforTree.TraverseInOrder(BTree2.Root, new List()); 145 | //Console.WriteLine(string.Join(", ", result2) + "\n"); 146 | //// 1, 4, 6, 9, 15, 20, 170 147 | 148 | //var result3 = DFSforTree.TraversePostOrder(BTree2.Root, new List()); 149 | //Console.WriteLine(string.Join(", ", result3) + "\n"); 150 | //// 1, 6, 4, 15, 170, 20, 9 151 | 152 | #endregion 153 | 154 | #region Depth First Search For Graph 155 | #region Connected Graph 156 | 157 | 158 | //Graph myGraph3 = new Graph(true); 159 | //myGraph3.AddVertex("A"); 160 | //myGraph3.AddVertex("B"); 161 | //myGraph3.AddVertex("C"); 162 | //myGraph3.AddVertex("D"); 163 | //myGraph3.AddEdge("A", "B"); 164 | //myGraph3.AddEdge("A", "C"); 165 | //myGraph3.AddEdge("C", "A"); 166 | //myGraph3.AddEdge("B", "C"); 167 | //myGraph3.AddEdge("C", "D"); 168 | //myGraph3.AddEdge("D", "C"); 169 | //DFSforGraph.DFS(myGraph3, "C"); 170 | 171 | #endregion 172 | 173 | 174 | #region Disconnected Graph 175 | //Graph myGraph4 = new Graph(true); 176 | //myGraph4.AddVertex("A"); 177 | //myGraph4.AddVertex("B"); 178 | //myGraph4.AddVertex("C"); 179 | //myGraph4.AddVertex("D"); 180 | //myGraph4.AddEdge("A", "B"); 181 | //myGraph4.AddEdge("C", "D"); 182 | //DFSforGraph.DFS(myGraph4); 183 | #endregion 184 | 185 | #endregion 186 | 187 | #endregion 188 | 189 | #region 4- Sorting 190 | 191 | #region InsertionSort Sort 192 | //var arr1 = new int[] { 50, 40, 30, 70 }; 193 | //var arrAfterIS = InsertionSort.Sort(arr1); 194 | //Console.WriteLine(string.Join(", ", arrAfterIS)); 195 | #endregion 196 | 197 | #region Selection Sort 198 | //var arr2 = new int[] { 50, 40, 30, 70 }; 199 | //var arrAfterSS = SelectionSort.Sort(arr2); 200 | //Console.WriteLine(string.Join(", ", arrAfterSS)); 201 | #endregion 202 | 203 | #region Bubble Sort 204 | //var arr3 = new int[] { 50, 40, 30, 70 }; 205 | //var arrAfterBS = BubbleSort.Sort(arr3); 206 | //Console.WriteLine(string.Join(", ", arrAfterBS)); 207 | #endregion 208 | 209 | 210 | 211 | #region Merge Sort 212 | //var arr4 = new int[] { 50, 40, 30, 70, 60, 90, 80 }; 213 | //var arrAfterMS = MergeSort.Sort(arr4); 214 | //Console.WriteLine(string.Join(", ", arrAfterMS)); 215 | #endregion 216 | 217 | #region Quick Sort 218 | //var arr5 = new int[] { 50, 70, 80, 90, 100, 40, 30, 7, 60, 8, 9 }; 219 | //int n = arr5.Length; 220 | //var arrAfterQS = QuickSort.Sort(arr5, 0, n - 1); 221 | //Console.WriteLine(string.Join(", ", arrAfterQS)); 222 | 223 | #endregion 224 | 225 | #endregion 226 | 227 | 228 | 229 | } 230 | } 231 | } 232 | 233 | -------------------------------------------------------------------------------- /2-Data Structure/DataStructure/DataStructure/5-Trees/2-BinarySearchTree/2-BinarySearchTree.cs: -------------------------------------------------------------------------------- 1 | using DataStructure.Trees.BinarySearchTree.Helper; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace DataStructure.Trees.BinarySearchTree 7 | { 8 | class BinarySearchTree where T : BinarySearchTypes 9 | { 10 | public BSTNode Root { get; set; } 11 | public BinarySearchTree() 12 | { 13 | Root = null; 14 | } 15 | public void insert(T value) 16 | { 17 | 18 | var newBSTNode = new BSTNode(value); 19 | 20 | if (Root == null) 21 | { 22 | Root = newBSTNode; 23 | return; 24 | } 25 | 26 | var current = Root; 27 | while (true) 28 | { 29 | if (value.Key < current.Obj.Key) 30 | { 31 | if (current.Left == null) 32 | { 33 | current.Left = newBSTNode; 34 | break; 35 | } 36 | current = current.Left; 37 | 38 | } 39 | else if (value.Key > current.Obj.Key) 40 | { 41 | if (current.Right == null) 42 | { 43 | current.Right = newBSTNode; 44 | break; 45 | } 46 | current = current.Right; 47 | } 48 | } 49 | 50 | 51 | } 52 | 53 | 54 | public BSTNode Search(int key) 55 | { 56 | if (Root == null) 57 | { 58 | return null; 59 | } 60 | BSTNode currentNode = Root; 61 | while (currentNode != null) 62 | { 63 | if (key < currentNode.Obj.Key) 64 | { 65 | currentNode = currentNode.Left; 66 | } 67 | else if (key > currentNode.Obj.Key) 68 | { 69 | currentNode = currentNode.Right; 70 | } 71 | else 72 | { 73 | return currentNode; 74 | } 75 | } 76 | return null; 77 | } 78 | 79 | #region Remove 80 | public void Remove(int key) 81 | { 82 | if (Root == null) 83 | return; 84 | 85 | BSTNode currentNode = Root; 86 | BSTNode parentNode = null; 87 | while (currentNode != null) 88 | { 89 | if (key < currentNode.Obj.Key) 90 | { 91 | parentNode = currentNode; 92 | currentNode = currentNode.Left; 93 | } 94 | else if (key > currentNode.Obj.Key) 95 | { 96 | parentNode = currentNode; 97 | currentNode = currentNode.Right; 98 | } 99 | 100 | 101 | else if (currentNode.Obj.Key == key) 102 | { 103 | 104 | //Option1: Node to be deleted is the leaf 105 | if (Isleaf(currentNode) && IsRoot(parentNode)/*Root*/) 106 | { 107 | Root = null; 108 | break; 109 | } 110 | else if (IsTheRightLeaftToItsParent(currentNode, parentNode)) 111 | { 112 | 113 | parentNode.Right = null; 114 | break; 115 | } 116 | else if (IsTheLeftLeaftToItsParent(currentNode, parentNode)) 117 | { 118 | parentNode.Left = null; 119 | break; 120 | } 121 | 122 | 123 | //Option2: Node to be deleted has only one child 124 | if (HasOnlyLeftChild(currentNode)) 125 | { 126 | if (parentNode == null) 127 | { 128 | Root = currentNode.Left; 129 | break; 130 | } 131 | 132 | 133 | if (IsTheRightChildToItsParent(currentNode, parentNode)) 134 | { 135 | parentNode.Right = currentNode.Left; 136 | break; 137 | } 138 | else 139 | { 140 | 141 | parentNode.Left = currentNode.Left; 142 | break; 143 | } 144 | 145 | } 146 | 147 | else if (HasOnlyRightChild(currentNode)) 148 | { 149 | if (parentNode == null) 150 | { 151 | Root = currentNode.Right; 152 | break; 153 | } 154 | 155 | 156 | if (IsTheRightChildToItsParent(currentNode, parentNode)) 157 | { 158 | parentNode.Right = currentNode.Right; 159 | break; 160 | } 161 | else 162 | { 163 | 164 | parentNode.Left = currentNode.Right; 165 | break; 166 | } 167 | 168 | } 169 | 170 | 171 | //Option3: Node to be deleted has two children 172 | if (HasTwoChild(currentNode)) 173 | { 174 | 175 | var nodeLeft = currentNode.Left; 176 | var nodeRigtht = currentNode.Right; 177 | 178 | var currenLeft = currentNode.Right.Left; 179 | var currenLeftParent = currentNode.Right; 180 | 181 | 182 | if (currenLeft == null) 183 | { 184 | if (IsRoot(parentNode)) 185 | { 186 | Root = nodeRigtht; 187 | } 188 | 189 | else if (IsTheRightChildToItsParent(currentNode, parentNode)) 190 | parentNode.Right = nodeRigtht; 191 | else 192 | parentNode.Left = nodeRigtht; 193 | 194 | 195 | nodeRigtht.Left = nodeLeft; 196 | break; 197 | } 198 | 199 | 200 | while (currenLeft != null) 201 | { 202 | 203 | if (currenLeft.Left == null) 204 | { 205 | if (IsRoot(parentNode)) 206 | { 207 | Root = currenLeft; 208 | } 209 | else 210 | if (IsTheRightChildToItsParent(currentNode, parentNode)) 211 | parentNode.Right = currenLeft; 212 | else 213 | parentNode.Left = currenLeft; 214 | 215 | 216 | currenLeft.Left = nodeLeft; 217 | currenLeft.Right = nodeRigtht; 218 | currenLeftParent.Left = null; 219 | return; //Exit from two whiles; 220 | } 221 | 222 | currenLeftParent = currenLeft; 223 | currenLeft = currenLeft.Left; 224 | } 225 | 226 | } 227 | } 228 | } 229 | } 230 | 231 | #region Methods used On Remove Method 232 | private static bool IsRoot(BSTNode parentNode) 233 | { 234 | return parentNode == null; 235 | } 236 | private static bool Isleaf(BSTNode currentNode) 237 | { 238 | return currentNode.Left == null && currentNode.Right == null; 239 | } 240 | 241 | 242 | 243 | private static bool IsTheRightLeaftToItsParent(BSTNode currentNode, BSTNode parentNode) 244 | { 245 | return currentNode.Left == null && currentNode.Right == null && currentNode.Obj.Key > parentNode.Obj.Key; 246 | } 247 | private static bool IsTheLeftLeaftToItsParent(BSTNode currentNode, BSTNode parentNode) 248 | { 249 | return currentNode.Left == null && currentNode.Right == null && currentNode.Obj.Key < parentNode.Obj.Key; 250 | } 251 | 252 | 253 | private static bool HasOnlyRightChild(BSTNode currentNode) 254 | { 255 | return currentNode.Right != null && currentNode.Left == null; 256 | } 257 | private static bool HasOnlyLeftChild(BSTNode currentNode) 258 | { 259 | return currentNode.Left != null && currentNode.Right == null; 260 | } 261 | private static bool HasTwoChild(BSTNode currentNode) 262 | { 263 | return currentNode.Left != null && currentNode.Right != null; 264 | } 265 | 266 | 267 | private static bool IsTheRightChildToItsParent(BSTNode currentNode, BSTNode parentNode) 268 | { 269 | return currentNode.Obj.Key > parentNode.Obj.Key; 270 | } 271 | #endregion 272 | 273 | #endregion 274 | 275 | 276 | 277 | 278 | public void printTree() 279 | { 280 | print2DUtil(Root, 0); 281 | } 282 | 283 | private void print2DUtil(BSTNode root, int space, int COUNT = 5) 284 | { 285 | 286 | if (root == null) 287 | return; 288 | 289 | // Increase distance between levels 290 | space += COUNT; 291 | 292 | // Process right child first 293 | print2DUtil(root.Right, space); 294 | 295 | // Print current BSTNode after space 296 | // count 297 | Console.Write("\n"); 298 | for (int i = COUNT; i < space; i++) 299 | { 300 | Console.Write(" "); 301 | } 302 | Console.Write(root.Obj.Key + "\n"); 303 | 304 | // Process left child 305 | print2DUtil(root.Left, space); 306 | } 307 | } 308 | } 309 | --------------------------------------------------------------------------------