├── Codes ├── Python │ ├── Linked lists │ │ ├── Linkedlists.md │ │ └── simple_linked_list.py │ ├── Trees │ │ └── Trees.md │ ├── greedy algorithms │ │ ├── greedy.md │ │ ├── maxProfit.py │ │ ├── isSubsequence.py │ │ ├── Assign_cookies.py │ │ └── lemonade_change.py │ ├── stack and queues │ │ ├── stacks.md │ │ ├── simple_queue.py │ │ └── simple_stack.py │ ├── Hashing Algorithms │ │ ├── hashing.md │ │ ├── given_sum_in_arr.py │ │ ├── most_frequent_element.py │ │ └── subset_of_array.py │ ├── divide and conquer │ │ └── Divideconquer.md │ ├── Searching_algorithms │ │ ├── linear_search.py │ │ └── binary_search.py │ ├── sorting Algorithms │ │ ├── selection_sort.py │ │ ├── insertion_sort.py │ │ ├── bubble_sort.py │ │ ├── quick_sort.py │ │ └── heap-sort.py │ └── Leetcode problems │ │ ├── champagne_tower.py │ │ ├── merge_sorted-array.py │ │ ├── restore_IP_addresses.py │ │ ├── max_points_on_line.py │ │ └── summaryRanges.py ├── README.md └── C++ │ ├── arrays_1.cpp │ ├── search_algorithms │ ├── linear_search.cpp │ └── binary_search.cpp │ └── linked_lists.cpp ├── Images ├── Arrays.png ├── Heap 1.png ├── Heap 2.png ├── Queue.png ├── Stack.png ├── Banner.jpeg ├── HashTable.png └── LinkedList.png ├── .github └── workflows │ └── greetings.yml ├── License ├── Comprehensive_Guides ├── Heap.md ├── HashTable.md ├── Queue.md ├── LinkedList.md ├── Arrays.md ├── Stack.md ├── Graph.md ├── Tree.md └── Algorithm.md └── README.md /Codes/Python/Linked lists/Linkedlists.md: -------------------------------------------------------------------------------- 1 | Linkedlists -------------------------------------------------------------------------------- /Codes/Python/Trees/Trees.md: -------------------------------------------------------------------------------- 1 | All trees related problems -------------------------------------------------------------------------------- /Codes/Python/greedy algorithms/greedy.md: -------------------------------------------------------------------------------- 1 | Greedy Algorithms -------------------------------------------------------------------------------- /Codes/Python/stack and queues/stacks.md: -------------------------------------------------------------------------------- 1 | Stacks and Queues -------------------------------------------------------------------------------- /Codes/Python/Hashing Algorithms/hashing.md: -------------------------------------------------------------------------------- 1 | Hashing Algorithms -------------------------------------------------------------------------------- /Codes/Python/divide and conquer/Divideconquer.md: -------------------------------------------------------------------------------- 1 | Divide and Conquer -------------------------------------------------------------------------------- /Images/Arrays.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-SFIT/Data-Structures-and-Algorithms--A-Comprehensive-Guide/HEAD/Images/Arrays.png -------------------------------------------------------------------------------- /Images/Heap 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-SFIT/Data-Structures-and-Algorithms--A-Comprehensive-Guide/HEAD/Images/Heap 1.png -------------------------------------------------------------------------------- /Images/Heap 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-SFIT/Data-Structures-and-Algorithms--A-Comprehensive-Guide/HEAD/Images/Heap 2.png -------------------------------------------------------------------------------- /Images/Queue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-SFIT/Data-Structures-and-Algorithms--A-Comprehensive-Guide/HEAD/Images/Queue.png -------------------------------------------------------------------------------- /Images/Stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-SFIT/Data-Structures-and-Algorithms--A-Comprehensive-Guide/HEAD/Images/Stack.png -------------------------------------------------------------------------------- /Images/Banner.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-SFIT/Data-Structures-and-Algorithms--A-Comprehensive-Guide/HEAD/Images/Banner.jpeg -------------------------------------------------------------------------------- /Images/HashTable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-SFIT/Data-Structures-and-Algorithms--A-Comprehensive-Guide/HEAD/Images/HashTable.png -------------------------------------------------------------------------------- /Images/LinkedList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-SFIT/Data-Structures-and-Algorithms--A-Comprehensive-Guide/HEAD/Images/LinkedList.png -------------------------------------------------------------------------------- /Codes/README.md: -------------------------------------------------------------------------------- 1 | # Sample Programs 2 | 3 | ## Arrays 4 | 5 | ### C++ 6 | 7 | - [Declaration, Definition and Insertion in Arrays](C++/arrays_1.cpp) 8 | 9 | ## Linked List 10 | 11 | ### C++ 12 | - [Inserting, Printing and Popping values out of a Linked List](C++/linked_lists.cpp) 13 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [pull_request, issues] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/first-interaction@v1 10 | with: 11 | repo-token: ${{ secrets.GITHUB_TOKEN }} 12 | issue-message: 'Thank you for contributing to our project 💜' 13 | pr-message: 'Thank you for your contribution 💜' 14 | -------------------------------------------------------------------------------- /Codes/Python/Searching_algorithms/linear_search.py: -------------------------------------------------------------------------------- 1 | # If you want to implement Linear Search in python 2 | # Linearly search x in arr[] 3 | # If x is present then return its location 4 | # else return -1 5 | 6 | def linear_search(arr, x): 7 | for i in range(len(arr)): 8 | 9 | if arr[i] == x: 10 | return i 11 | 12 | return -1 13 | 14 | # Test array 15 | arr = [43, 55, 34, 343, 4, 3, 4323] 16 | x = 34 17 | result = linear_search(arr, x) 18 | print(result) -------------------------------------------------------------------------------- /Codes/Python/sorting Algorithms/selection_sort.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | A = [64, 25, 12, 22, 11] 4 | 5 | # Traverse through all array elements 6 | for i in range(len(A)): 7 | 8 | # Find the minimum element in remaining 9 | # unsorted array 10 | min_idx = i 11 | for j in range(i + 1, len(A)): 12 | if A[min_idx] > A[j]: 13 | min_idx = j 14 | 15 | # Swap the found minimum element with 16 | # the first element 17 | A[i], A[min_idx] = A[min_idx], A[i] 18 | 19 | #test 20 | print("Sorted array") 21 | for i in range(len(A)): 22 | print("%d" % A[i]) -------------------------------------------------------------------------------- /Codes/Python/Hashing Algorithms/given_sum_in_arr.py: -------------------------------------------------------------------------------- 1 | # Python program to find if there are 2 | # two elements wtih given sum 3 | 4 | # function to check for the given sum 5 | # in the array 6 | def printPairs(arr, arr_size, sum): 7 | # Create an empty hash set 8 | s = set() 9 | 10 | for i in range(0, arr_size): 11 | temp = sum - arr[i] 12 | if (temp in s): 13 | return ("Pair with given sum {} is {} + {}".format(sum, arr[i], temp)) 14 | s.add(arr[i]) 15 | 16 | 17 | # driver code 18 | A = [1, 4, 45, 6, 10, 150, 8] 19 | n = 160 20 | print(printPairs(A, len(A), n)) -------------------------------------------------------------------------------- /Codes/Python/sorting Algorithms/insertion_sort.py: -------------------------------------------------------------------------------- 1 | def insertionSort(arr): 2 | # Traverse through 1 to len(arr) 3 | for i in range(1, len(arr)): 4 | 5 | key = arr[i] 6 | 7 | #Move elements of arr[0..i-1], that are 8 | #greater than key, to one position ahead 9 | #of their current position 10 | j = i - 1 11 | while j >= 0 and key < arr[j]: 12 | arr[j + 1] = arr[j] 13 | j -= 1 14 | arr[j + 1] = key 15 | 16 | 17 | 18 | 19 | arr = [12, 11, 13, 5, 6] 20 | insertionSort(arr) 21 | for i in range(len(arr)): 22 | print("% d" % arr[i]) -------------------------------------------------------------------------------- /Codes/Python/stack and queues/simple_queue.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | # you can initialize a deque with a list 4 | numbers = deque() 5 | 6 | # Use append to add elements 7 | numbers.append(99) 8 | numbers.append(15) 9 | numbers.append(82) 10 | numbers.append(50) 11 | numbers.append(47) 12 | 13 | print(numbers) 14 | 15 | 16 | # The number that entered the queue first gets removed first and so on.. 17 | first_item = numbers.popleft() 18 | print(first_item) # 99 19 | print(numbers) # deque([15, 82, 50]) 20 | 21 | second_item = numbers.popleft() 22 | print(second_item) # 15 23 | print(numbers) # deque([82, 50]) -------------------------------------------------------------------------------- /Codes/Python/greedy algorithms/maxProfit.py: -------------------------------------------------------------------------------- 1 | #Problem link-> https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ 2 | #Leetcode Problem 122. Best Time to Buy and Sell Stock II 3 | 4 | class Solution: 5 | def maxProfit(prices): 6 | profit = 0 7 | buy = 0 8 | sell = 0 9 | 10 | for i in range(len(prices)-1): 11 | if prices[i+1] - prices[i] >=0: 12 | buy = prices[i] 13 | sell = prices[i+1] 14 | profit += sell -buy 15 | return profit 16 | 17 | # test the code 18 | if __name__ == "__main__": 19 | print(maxProfit([7,1,5,6,4])) -------------------------------------------------------------------------------- /Codes/Python/Hashing Algorithms/most_frequent_element.py: -------------------------------------------------------------------------------- 1 | # Python3 program to find the most 2 | # frequent element in an array. 3 | 4 | def mostFrequent(arr, n): 5 | # Insert all elements in Hash. 6 | Hash = dict() 7 | for i in range(n): 8 | if arr[i] in Hash.keys(): 9 | Hash[arr[i]] += 1 10 | else: 11 | Hash[arr[i]] = 1 12 | 13 | # find the max frequency 14 | max_count = 0 15 | res = -1 16 | for i in Hash: 17 | if (max_count < Hash[i]): 18 | res = i 19 | max_count = Hash[i] 20 | 21 | return res 22 | 23 | 24 | # Driver Code 25 | arr = [1, 5, 2, 1, 3, 2, 1] 26 | n = len(arr) 27 | print(mostFrequent(arr, n)) -------------------------------------------------------------------------------- /Codes/Python/greedy algorithms/isSubsequence.py: -------------------------------------------------------------------------------- 1 | #Problem link: https://leetcode.com/problems/is-subsequence/ 2 | #Problem 392: Is Subsequence 3 | 4 | class Solution: 5 | def isSubsequence(s, t): 6 | i=0 7 | #length of substring is 0 then True by-default 8 | if len(s)==0: 9 | return True 10 | 11 | #loop through the main string and check for each element in substring 12 | for _ in range(len(t)): 13 | if t[_]==s[i]: 14 | i+=1 15 | if i==len(s): 16 | return True 17 | return False 18 | 19 | 20 | #test the code 21 | if __name__ == "__main__": 22 | print(isSubsequence('nge', 'nnghte')) 23 | 24 | 25 | -------------------------------------------------------------------------------- /Codes/Python/Hashing Algorithms/subset_of_array.py: -------------------------------------------------------------------------------- 1 | #Python program to check if arr2 is subset of arr1 2 | 3 | def func(arr1, arr2, arr1_size, arr2_size): 4 | 5 | #create a hashtable 6 | hash = {} 7 | for i in arr1: 8 | if i not in hash: 9 | hash[i]=1 10 | else: 11 | hash[i] += 1 12 | 13 | #loop through each element of arr_2 and check if it is in hash 14 | for j in range(arr2_size): 15 | if arr2[j] not in hash: 16 | return False 17 | 18 | return True 19 | 20 | #driver code 21 | arr1 = [1,2,3,49,4,5] 22 | arr2 = [5,3,4] 23 | arr1_size = len(arr1) 24 | arr2_size = len(arr2) 25 | print(func(arr1, arr2, arr1_size, arr2_size)) 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Codes/Python/greedy algorithms/Assign_cookies.py: -------------------------------------------------------------------------------- 1 | #Problem link : https://leetcode.com/problems/assign-cookies 2 | #Leetcode Problem.455 : Assign Cookies 3 | 4 | 5 | class Solution: 6 | def findContentChildren(g, s): 7 | #sort both (children and cookies list) in ascending order 8 | g.sort() 9 | s.sort() 10 | i = 0 11 | j = 0 12 | count = 0 13 | while i < len(g) and j < len(s): 14 | if s[j] >= g[i]: 15 | count += 1 16 | i += 1 17 | j += 1 18 | 19 | return count 20 | # g = [1,2], s = [1,2,3] 21 | 22 | # test the code 23 | if __name__ == "__main__": 24 | print(findContentChildren([1,2], [1,2,3])) 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Codes/C++/arrays_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // funtion to print the elements of an array 6 | void print(int array[5]){ 7 | // iterating using the auto keyword 8 | } 9 | 10 | int main(){ 11 | 12 | // defining and declaring an integer array of 5 elements 13 | int array[5] = {1,2,3,4,5}; 14 | cout << "array = " ; 15 | for(auto element : array) 16 | { 17 | cout << element << " " ; 18 | } 19 | cout << endl << endl; //printing blank lines 20 | 21 | // defining an array and taking user input and inserting into an array 22 | int array2[5]; 23 | cout << "Enter 5 elements" << endl; 24 | for(int i=0; i < 5; i++) 25 | { 26 | cin >> array2[i]; 27 | } 28 | 29 | cout << "array2 = " 30 | for(auto element : array2) 31 | { 32 | cout << element << " " ; 33 | } 34 | cout << endl << endl; //printing blank lines 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Codes/Python/Searching_algorithms/binary_search.py: -------------------------------------------------------------------------------- 1 | # It returns index of n in given array arr if present, 2 | # else returns -1 3 | def binary_search(arr, n): 4 | low = 0 5 | high = len(arr) - 1 6 | mid = 0 7 | 8 | while low <= high: 9 | 10 | mid = (high + low) // 2 11 | 12 | # Check if n is present at mid-pos 13 | if arr[mid] < n: 14 | low = mid + 1 15 | 16 | # If n is greater, remove left half 17 | elif arr[mid] > n: 18 | high = mid - 1 19 | 20 | # If n is smaller, remove right half 21 | else: 22 | return mid 23 | 24 | # If the loop ends, then the element was not found 25 | return -1 26 | 27 | 28 | # Test array 29 | arr = [4,4,34,35,4,324,6,4,3,43,342] 30 | n = 342 31 | 32 | result = binary_search(arr, n) 33 | print(result) -------------------------------------------------------------------------------- /Codes/Python/Leetcode problems/champagne_tower.py: -------------------------------------------------------------------------------- 1 | # Author: Sanket Dalvi 2 | # Question Link: https://leetcode.com/problems/champagne-tower/ 3 | 4 | class Solution: 5 | def champagneTower(self, poured: int, query_row: int, query_glass: int) -> float: 6 | tower = [] 7 | for i in range(1, query_row+2): 8 | tower.append([0]*i) 9 | tower[0][0] = poured 10 | for i in range(len(tower)-1): 11 | noOverflow = True 12 | for j in range(len(tower[i])): 13 | if tower[i][j] > 1: 14 | noOverflow = False 15 | tower[i+1][j] += (tower[i][j]-1)/2 16 | tower[i+1][j+1] += (tower[i][j]-1)/2 17 | tower[i][j] = 1 18 | if noOverflow: break 19 | return min(tower[query_row][query_glass], 1) 20 | 21 | # Testing 22 | print(Solution().champagneTower(1000000000, 29, 0)) -------------------------------------------------------------------------------- /Codes/Python/Leetcode problems/merge_sorted-array.py: -------------------------------------------------------------------------------- 1 | #Problem link: https://leetcode.com/problems/merge-sorted-array/ 2 | 3 | class Solution: 4 | # @param A a list of integers 5 | # @param m an integer, length of A 6 | # @param B a list of integers 7 | # @param n an integer, length of B 8 | # @return nothing 9 | def merge(self, A, m, B, n): 10 | last, i, j = m + n - 1, m - 1, n - 1 11 | 12 | while i >= 0 and j >= 0: 13 | if A[i] > B[j]: 14 | A[last] = A[i] 15 | last, i = last - 1, i - 1 16 | else: 17 | A[last] = B[j] 18 | last, j = last - 1, j - 1 19 | 20 | while j >= 0: 21 | A[last] = B[j] 22 | last, j = last - 1, j - 1 23 | return A 24 | 25 | #Input: 26 | #nums1 = [1,2,3,0,0,0], m = 3 27 | #nums2 = [2,5,6], n = 3 28 | 29 | #Output: [1,2,2,3,5,6] 30 | 31 | print(Solution().merge([1,2,3,0,0,0], 3, [2,5,6],3)) -------------------------------------------------------------------------------- /Codes/C++/search_algorithms/linear_search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // define the size of the array 6 | int N = 10; 7 | 8 | int main(){ 9 | 10 | int arr[N]; 11 | // input 10 elements for the array 12 | cout << "Enter " << N<< " elements of the array: " << endl; 13 | for(int i=0; i> arr[i]; } 14 | 15 | // input the element you want to search 16 | cout << "Enter the element you want to search: " ; 17 | int element; cin >> element; 18 | 19 | // linear search is the most naive approach to search for an element in an array 20 | // the time complexity of the linear search algorithm is O(n) 21 | // This is the most naive search approach and is ususually used when the array is not too huge 22 | // This can simply be achieved by iterating from the the first element to the last or vice versa 23 | 24 | for(int i=0; i collection[j + 1]: 11 | swapped = True 12 | collection[j], collection[j + 1] = collection[j + 1], collection[j] 13 | if not swapped: 14 | break # Stop iteration if the collection is sorted. 15 | return collection 16 | 17 | #test the code 18 | if __name__ == "__main__": 19 | 20 | 21 | doctest.testmod() 22 | #input 23 | user_input = input("Enter numbers separated by a comma:").strip() 24 | unsorted = [int(item) for item in user_input.split(",")] 25 | start = time.process_time() 26 | #the bubble sort function that we defined earlier 27 | print(*bubble_sort(unsorted), sep=",") 28 | print(f"Processing time: {time.process_time() - start}") 29 | -------------------------------------------------------------------------------- /Codes/Python/greedy algorithms/lemonade_change.py: -------------------------------------------------------------------------------- 1 | #Problem link : https://leetcode.com/problems/lemonade-change/ 2 | #Leetcode Problem.860 : Lemonade Change 3 | 4 | 5 | class Solution(object): 6 | def lemonadeChange(bills): 7 | 8 | five = ten = 0 9 | 10 | for bill in bills: 11 | # condition for 5 12 | if bill == 5: 13 | five += 1 14 | # condition for 10 15 | elif bill == 10: 16 | if not five: 17 | return False 18 | five -= 1 19 | ten += 1 20 | # condition for 20 21 | else: 22 | if ten and five: 23 | ten -= 1 24 | five -= 1 25 | elif five >= 3: 26 | five -= 3 27 | else: 28 | return False 29 | return True 30 | 31 | # test the code 32 | if __name__ == "__main__": 33 | print(lemonadeChange([5,5,20])) -------------------------------------------------------------------------------- /License: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 CSI SFIT 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 | -------------------------------------------------------------------------------- /Codes/C++/search_algorithms/binary_search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // size of array 6 | int N = 10; 7 | 8 | int binary_search(int arr[], int low, int up, int x) 9 | { 10 | while (low <= up) { 11 | int middle = low + (up - low) / 2; 12 | 13 | // Check if x is present at mid 14 | if (arr[middle] == x) 15 | return middle; 16 | 17 | // If x greater, ignore left half 18 | if (arr[middle] < x) 19 | low = middle + 1; 20 | 21 | // If x is smaller, ignore right half 22 | else 23 | up = middle - 1; 24 | } 25 | 26 | // if we reach here, then element was 27 | // not present 28 | return -1; 29 | } 30 | 31 | 32 | int main(){ 33 | int arr[N] = {1,2,5,25,35,67,87,88,90,100}; 34 | 35 | 36 | for(auto e: arr){ cout << e << " " ;} 37 | // input the element 38 | cout << endl; 39 | cout << "Enter the element you want to search for: " ; 40 | int element; cin >> element; 41 | int found = binary_search(arr,0,N-1,element); 42 | found!=-1 ? cout << "Element exists" << endl : cout << "Element does not exist in the array" << endl; 43 | } 44 | -------------------------------------------------------------------------------- /Codes/Python/Leetcode problems/restore_IP_addresses.py: -------------------------------------------------------------------------------- 1 | # Author: Sanket Dalvi 2 | # Question Link: https://leetcode.com/problems/restore-ip-addresses/ 3 | 4 | class Solution: 5 | def __init__(self): 6 | super().__init__() 7 | self.ipList = [] 8 | def getList(self, level, A, suffix): 9 | if level > 3: 10 | if len(suffix)-4 == len(A) and suffix[1:] not in self.ipList: 11 | self.ipList.append(suffix[1:]) 12 | return 13 | temp = [] 14 | for i in range(1,min(4, len(A)+level-len(suffix)+1)): 15 | if 0 <= int( 16 | A[len(suffix)-(level):len(suffix)-level+i]) <= 255 and ( 17 | A[len(suffix)-(level):len(suffix)-level+i][0] != "0" or len( 18 | A[len(suffix)-(level):len(suffix)-level+i] 19 | ) == 1 20 | ): 21 | self.getList(level+1, A, suffix+"."+A[len(suffix)-(level):len(suffix)-level+i]) 22 | 23 | def restoreIpAddresses(self, A): 24 | self.getList(0, A, "") 25 | return self.ipList 26 | 27 | # Testing 28 | print(Solution().restoreIpAddresses("0100100")) -------------------------------------------------------------------------------- /Codes/Python/Linked lists/simple_linked_list.py: -------------------------------------------------------------------------------- 1 | # A simple Python program to introduce a linked list 2 | 3 | # Node class 4 | class Node: 5 | 6 | # Function to initialise the node object 7 | def __init__(self, data): 8 | self.data = data # Assign data 9 | self.next = None # Initialize next as null 10 | 11 | 12 | # This linked List class contains a Node object 13 | class LinkedList: 14 | 15 | # a function to initialize head 16 | def __init__(self): 17 | self.head = None 18 | 19 | # This function prints contents of linked list 20 | # starting from head 21 | def printList(self): 22 | temp = self.head 23 | while (temp): 24 | print(temp.data) 25 | temp = temp.next 26 | 27 | 28 | # Code execution starts here 29 | if __name__ == '__main__': 30 | # Start with the empty list 31 | llist = LinkedList() 32 | 33 | llist.head = Node(10) 34 | second = Node(672) 35 | third = Node(983) 36 | 37 | llist.head.next = second # Link first node with second 38 | second.next = third # Link second node with the third node 39 | 40 | llist.printList() -------------------------------------------------------------------------------- /Codes/Python/Leetcode problems/max_points_on_line.py: -------------------------------------------------------------------------------- 1 | # Author: Sanket Dalvi 2 | # Question Link: https://leetcode.com/problems/max-points-on-a-line/ 3 | 4 | from collections import defaultdict 5 | from fractions import Fraction 6 | class Solution: 7 | # @param A : list of integers 8 | # @param B : list of integers 9 | # @return an integer 10 | def maxPoints(self, points): 11 | res = 0 12 | if len(points) <= 2: 13 | return len(points) 14 | for ind, i in enumerate(points): 15 | dp = defaultdict(int) 16 | maxPoint = 0 17 | duplicateCount = 0 18 | for j in points[:ind]+points[ind+1:]: 19 | if i[0] == j[0]: 20 | m = -999 21 | if i[1] == j[1]: 22 | duplicateCount += 1 23 | continue 24 | else: 25 | m = Fraction(i[1]-j[1], i[0]-j[0]) 26 | dp[m] += 1 27 | maxPoint = max(maxPoint, dp[m]) 28 | res = max(res, maxPoint+1+duplicateCount) 29 | return res 30 | 31 | # Testing 32 | # Input: [[1,1],[1,1],[1,1],[2,2],[2,2],[1,2]] 33 | # Expected output: 5 34 | print(Solution().maxPoints([[1,1],[1,1],[1,1],[2,2],[2,2],[1,2]])) -------------------------------------------------------------------------------- /Codes/Python/Leetcode problems/summaryRanges.py: -------------------------------------------------------------------------------- 1 | # Author: Sanket Dalvi 2 | # Question Link: https://leetcode.com/problems/summary-ranges/ 3 | 4 | 5 | from typing import List 6 | 7 | class Solution: 8 | def summaryRanges(self, nums: List[int]) -> List[str]: 9 | # Check if list is empty 10 | if not len(nums): return [] 11 | result = [] 12 | start = 0 13 | difference = 1 14 | while start+difference < len(nums): 15 | if nums[start]+difference==nums[start+difference]: 16 | difference += 1 17 | elif difference==1: 18 | result.append(str(nums[start])) 19 | start += 1 20 | difference = 1 21 | else: 22 | result.append("{}->{}".format(nums[start], nums[start+difference-1])) 23 | start += difference 24 | difference = 1 25 | # Adding the last element 26 | if difference==1: 27 | result.append(str(nums[start])) 28 | else: 29 | result.append("{}->{}".format(nums[start], nums[start+difference-1])) 30 | return result 31 | 32 | 33 | # Test case 1 34 | print(Solution().summaryRanges([0,1,2,4,5,7])) 35 | # Test case 2 36 | print(Solution().summaryRanges([0,2,3,4,6,8,9])) -------------------------------------------------------------------------------- /Codes/Python/stack and queues/simple_stack.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of simple stack 2 | 3 | # import maxsize from sys module 4 | # Used to return -infinite when stack is empty 5 | from sys import maxsize 6 | 7 | 8 | # Function to create a stack. It initializes size of stack as 0 9 | def createStack(): 10 | stack = [] 11 | return stack 12 | 13 | 14 | # Stack is empty when stack size is 0 15 | def isEmpty(stack): 16 | return len(stack) == 0 17 | 18 | 19 | # Function to add an item to stack. It increases size by 1 20 | def push(stack, item): 21 | stack.append(item) 22 | print(item + " pushed to stack ") 23 | 24 | 25 | # Function to remove an item from stack. It decreases size by 1 26 | def pop(stack): 27 | if (isEmpty(stack)): 28 | return str(-maxsize - 1) # return minus infinite 29 | 30 | return stack.pop() + ' popped from stack' 31 | 32 | 33 | # Function to return the top from stack without removing it 34 | def peek(stack): 35 | if (isEmpty(stack)): 36 | return str(-maxsize - 1) # return minus infinite 37 | return stack[len(stack) - 1] + ' is the topmost element' 38 | 39 | 40 | 41 | # Driver program to test above functions 42 | stack = createStack() 43 | push(stack, str(10)) 44 | push(stack, str(20)) 45 | push(stack, str(30)) 46 | print(peek(stack)) 47 | print(pop(stack)) 48 | 49 | print(stack) -------------------------------------------------------------------------------- /Codes/Python/sorting Algorithms/quick_sort.py: -------------------------------------------------------------------------------- 1 | 2 | # This function takes last element as pivot, places 3 | # the pivot element at its correct position in sorted 4 | # array, and places all smaller (smaller than pivot) 5 | # to left of pivot and all greater elements to right 6 | # of pivot 7 | def partition(arr, low, high): 8 | i = (low - 1) # index of smaller element 9 | pivot = arr[high] # pivot 10 | 11 | for j in range(low, high): 12 | 13 | # If current element is smaller than the pivot 14 | if arr[j] < pivot: 15 | # increment index of smaller element 16 | i = i + 1 17 | arr[i], arr[j] = arr[j], arr[i] 18 | 19 | arr[i + 1], arr[high] = arr[high], arr[i + 1] 20 | return (i + 1) 21 | 22 | 23 | # The main function that implements QuickSort 24 | # low --> Starting index 25 | # high --> Ending index 26 | 27 | def quickSort(arr, low, high): 28 | if low < high: 29 | # pi is partitioning index, arr[p] is now 30 | # at right place 31 | pi = partition(arr, low, high) 32 | 33 | # Separately sort elements before 34 | # partition and after partition 35 | quickSort(arr, low, pi - 1) 36 | quickSort(arr, pi + 1, high) 37 | 38 | 39 | #test code 40 | arr = [10, 7, 8, 9, 1, 5] 41 | n = len(arr) 42 | quickSort(arr, 0, n - 1) 43 | print("Sorted array is:") 44 | for i in range(n): 45 | print("%d" % arr[i]) -------------------------------------------------------------------------------- /Codes/Python/sorting Algorithms/heap-sort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of heap Sort 2 | 3 | # To heapify subtree rooted at index i. 4 | # n is size of heap 5 | 6 | def heapify(arr, n, i): 7 | # Initialize largest number as root 8 | 9 | largest = i 10 | # left = 2*i + 1 11 | l = 2 * i + 1 12 | # right = 2*i + 2 13 | r = 2 * i + 2 14 | 15 | # See if left child of root exists and is 16 | # greater than root 17 | if l < n and arr[largest] < arr[l]: 18 | largest = l 19 | 20 | # See if right child of root exists and is 21 | # greater than root 22 | if r < n and arr[largest] < arr[r]: 23 | largest = r 24 | 25 | # Change root, if needed 26 | if largest != i: 27 | # swap 28 | arr[i], arr[largest] = arr[largest], arr[i] 29 | 30 | # Heapify the root. 31 | heapify(arr, n, largest) 32 | 33 | 34 | # The main function to sort an array of given size 35 | 36 | 37 | def heapSort(arr): 38 | n = len(arr) 39 | 40 | # Build a maxheap. 41 | for i in range(n // 2 - 1, -1, -1): 42 | heapify(arr, n, i) 43 | 44 | # One by one extract elements 45 | for i in range(n - 1, 0, -1): 46 | arr[i], arr[0] = arr[0], arr[i] # swap 47 | heapify(arr, i, 0) 48 | 49 | 50 | # Test 51 | arr = [12, 11, 13, 5, 6, 7] 52 | heapSort(arr) 53 | n = len(arr) 54 | print("Sorted array is") 55 | for i in range(n): 56 | print("%d" % arr[i]), -------------------------------------------------------------------------------- /Comprehensive_Guides/Heap.md: -------------------------------------------------------------------------------- 1 |

Heaps


2 | 3 | ## What are Heaps? 4 | 5 | A Heap is a special case of a binary tree where the parent nodes are compared to their children with their values and are arranged accordingly. 6 | Let us see how we can represent heaps. Heaps can be represented using trees as well as arrays. Figures 7 and 8 show how we can represent a binary heap using a binary tree and an array. 7 | 8 | Heap Image 1 9 | Heap Image 2 10 | 11 | ## Types of Heaps 12 | 13 | You should use heap when you require to allocate a large block of memory. For example, you want to create a large size array or big structure to keep that variable around a long time then you should allocate it on the heap. 14 | 15 | - Min Heap — the key of the parent is less than or equal to those of its children. This is called the min-heap property. The root will contain the minimum value of the heap. 16 | - Max Heap — the key of the parent is greater than or equal to those of its children. This is called the max-heap property. The root will contain the maximum value of the heap. 17 | 18 | ## Advantages of Heaps 19 | 20 | - Heap helps you to find the greatest and minimum number 21 | - Garbage collection runs on the heap memory to free the memory used by the object. 22 | - Heap method also used in the Priority Queue. 23 | - It allows you to access variables globally. 24 | - Heap doesn't have any limit on memory size. 25 | 26 | ## Disadvantages of Heaps 27 | 28 | - It can provide the maximum memory an OS can provide 29 | - It takes more time to compute. 30 | - Memory management is more complicated in heap memory as it is used globally. 31 | - It takes too much time in execution compared to the stack. 32 | 33 | ## Resources 34 | 35 | - [Heaps - GeeksForGeeks](https://www.geeksforgeeks.org/heap-data-structure/) 36 | - [Heaps - TutorialsPoint](https://www.tutorialspoint.com/data_structures_algorithms/heap_data_structure.htm) 37 | - [Heaps - HackerEarth](https://www.hackerearth.com/practice/data-structures/trees/heapspriority-queues/tutorial/) 38 | - [Heaps - Interview Cake](https://www.interviewcake.com/concept/java/heap) 39 | - [Heaps - Brilliant.org](https://brilliant.org/wiki/heaps/) 40 | 41 | 42 | - [Heaps - HackerEarth](https://www.youtube.com/watch?v=t0Cq6tVNRBA) 43 | - [Heaps and Heap Sort - Abdul Bari](https://www.youtube.com/watch?v=HqPJF2L5h9U) 44 | - [Heaps - Jenny Lectures](https://www.youtube.com/watch?v=NEtwJASLU8Q) 45 | - [Heaps - Education4You](https://www.youtube.com/watch?v=j6iP4lDTKyI) 46 | - [Heaps and Heap Sort - MIT](https://www.youtube.com/watch?v=B7hVxCmfPtM) 47 | - [Heaps - GATE Lectures](https://www.youtube.com/watch?v=40iljMQmqmY) 48 | -------------------------------------------------------------------------------- /Codes/C++/linked_lists.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | // user defined datatype to store an integer value and the adress of the next node 6 | struct node 7 | { 8 | int value; 9 | node* next = nullptr; 10 | }; 11 | 12 | // start pointer to point to the start of the linked list 13 | node* start = nullptr; 14 | // endd pointer to point to the last element of the linked list 15 | node* endd = nullptr; 16 | 17 | // function to insert a node in a liked list 18 | void push_back(int value) 19 | { 20 | // create a node 21 | node* n1 = new node(); 22 | // assign a value to the node 23 | n1->value = value; 24 | 25 | // if the list is empty create the first node and point start and end to it 26 | if(endd == nullptr){ 27 | start = n1; 28 | endd = n1; 29 | } 30 | // if the list is not empty point the next of the current last node to the new last node, and update end 31 | else{ 32 | endd->next = n1; 33 | endd = n1; 34 | } 35 | } 36 | 37 | //function to add element to the start of the array 38 | void push_front(int value) 39 | { 40 | // create a node 41 | node* n = new node(); 42 | // set the nodes value 43 | n->value = value; 44 | 45 | //update start 46 | n->next = start; 47 | start = n; 48 | } 49 | 50 | // function to delete an element of the linked list 51 | void pop(){ 52 | node* ptr = start; 53 | // if only one element is there then empyt the list 54 | if(start == endd){ 55 | start = endd= nullptr; 56 | } 57 | else{ 58 | while(ptr->next != endd){ 59 | ptr= ptr->next; 60 | } 61 | ptr->next=nullptr; 62 | } 63 | } 64 | 65 | // function to print the elements of a linked list 66 | void print_list(node* list_start){ 67 | node* ptr = start; 68 | cout << "List = "; 69 | while(ptr != nullptr){ 70 | cout << ptr->value << " "; 71 | ptr = ptr->next; 72 | } 73 | cout << endl; 74 | } 75 | 76 | int main(){ 77 | 78 | int value; 79 | 80 | // inserting n elements in a linked list 81 | // lets insert 5 elements 82 | cout << "Enter 5 elements: "; 83 | for(int i = 1; i <= 5; i++) 84 | { 85 | cin >> value; 86 | push_back(value); 87 | } 88 | // view the list 89 | print_list(start); 90 | 91 | // lets add an element to the start of the list 92 | cout << "Enter the value you want to add to the front: "; 93 | cin >> value; 94 | push_front(value); 95 | print_list(start); 96 | 97 | // popping a value from the list 98 | cout << "After Popping from the list: " << endl; 99 | pop(); 100 | print_list(start); 101 | } 102 | -------------------------------------------------------------------------------- /Comprehensive_Guides/HashTable.md: -------------------------------------------------------------------------------- 1 |

Hash Table


2 | 3 | ## What are Hash Tables? 4 | 5 | A Hash Table is a data structure that stores values which have keys associated with each of them. Furthermore, it supports lookup efficiently if we know the key associated with the value. Hence it is very efficient in inserting and searching, irrespective of the size of the data. 6 | Direct Addressing uses the one-to-one mapping between the values and keys when storing in a table. However, there is a problem with this approach when there is a large number of key-value pairs. The table will be huge with so many records and may be impractical or even impossible to be stored, given the memory available on a typical computer. To avoid this issue we use hash tables. 7 | 8 | ## Hash Function 9 | 10 | A special function named as the hash function (h) is used to overcome the aforementioned problem in direct addressing. 11 | In direct accessing, a value with key k is stored in the slot k. Using the hash function, we calculate the index of the table (slot) to which each value goes. The value calculated using the hash function for a given key is called the hash value which indicates the index of the table to which the value is mapped. 12 | ### h(k)=k%m 13 | - h: Hash function 14 | - k: Key of which the hash value should be determined 15 | - m: Size of the hash table (number of slots available). A prime value that is not close to an exact power of 2 is a good choice for m. 16 | 17 | Hash Table Image 18 | 19 | Consider the hash function h(k) = k % 20, where the size of the hash table is 20. Given a set of keys, we want to calculate the hash value of each to determine the index where it should go in the hash table. Consider we have the following keys, the hash and the hash table index. 20 | 21 | - 1 → 1%20 → 1 22 | - 5 → 5%20 → 5 23 | - 23 → 23%20 → 3 24 | - 63 → 63%20 → 3 25 | 26 | From the last two examples given above, we can see that collision can arise when the hash function generates the same index for more than one key. We can resolve collisions by selecting a suitable hash function h and use techniques such as chaining and open addressing. 27 | 28 | ## Applications of Hash Tables 29 | 30 | - Used to implement database indexes. 31 | - Used to implement associative arrays. 32 | - Used to implement the “set” data structure. 33 | 34 | ## Resources 35 | 36 | - [Hash Table - TutorialsPoint](https://www.tutorialspoint.com/data_structures_algorithms/hash_data_structure.htm) 37 | - [Basics of Hash Tables - HackerEarth](https://www.hackerearth.com/practice/data-structures/hash-tables/basics-of-hash-tables/tutorial/) 38 | - [Hash Tables Explained - Your Basic](https://yourbasic.org/algorithms/hash-tables-explained/) 39 | - [Hash Tabels - Educative](https://www.educative.io/edpresso/what-is-a-hash-table) 40 | - [Hash Tables - Programiz](https://www.programiz.com/dsa/hash-table) 41 |

42 | - [Hashing and Hash Tables - SaurabhSchool](https://www.youtube.com/playlist?list=PLTZbNwgO5ebqw1v0ODk8cPLW9dQ99Te8f) 43 | - [Hashing And Hash Tables - GeeksForGeeks](https://www.youtube.com/playlist?list=PLqM7alHXFySGwXaessYMemAnITqlZdZVE) 44 | - [Hash Tables - Abdul Bari](https://www.youtube.com/watch?v=mFY0J5W8Udk) 45 | - [Hash Tables - Hackerrank](https://www.youtube.com/watch?v=shs0KM3wKv8) 46 | - [Hash Tables - Paul Programming](https://www.youtube.com/watch?v=MfhjkfocRR0) 47 | - [Hash Map - Codebasics](https://youtu.be/ea8BRGxGmlA) 48 | -------------------------------------------------------------------------------- /Comprehensive_Guides/Queue.md: -------------------------------------------------------------------------------- 1 |

Queues


2 | 3 | ## What is a Queue? 4 | 5 | A Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first. The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added. 6 | 7 | Queues Image 8 | 9 | ## Queue Implementations 10 | 11 | - Array representation : Queues have 2 pointers. FRONT and REAR. Initially both are null. When an element is added both are 0. Enqueuing is done from the REAR. It is incremented when another element is added. 12 | 13 | - Linked list representation : In Linked List, 2 pointers FRONT and REAR are there which point to them. 14 | 15 | ## Queue Operations 16 | 17 | 1. Enqueue(Inserion) : In Array representation, REAR is incremented and at READ the variable is assigned. 18 |
In Linked List, a new node is created with the value and the REAR element's pointer is assigned to new node and REAR is pointed to new node. 19 | 2. Dequeue(Deletion) : In Array representation, Front is incremented. 20 |
In Linked List, the FRONT node is freed/deleted, FRONT is pointed to the next node of the original FRONT node. 21 | 22 | ## Types of Queues 23 | 24 | - Linear Queue: Basic queue with FRONT and REAR as previously told 25 | - Circular Queue: For linked list, Circular Linked List is used. For Array, as soon as FRONT or REAR exceed MAX, they are assigned to 0(if front is not 0) 26 | - Double Ended Queue(Deque - not same as Dequeue): In it enqueuing and dequeuing can be don't from both ends. There are 2 types : 27 | - Input Restricted Deque - Enqueuing is allowed only from rear. Dequeuing can be done from both front and rear 28 | - Output Restricted Deque - Dequeuing is allowed only from front. Enqueuing is allowed from both front and rear. 29 | - Priority Queue: Each element in Priority Queue has a priority level. It is used in OS for scheduling tasks. 30 | 31 | ## Application of Queues 32 | 33 | - Serving requests on a single shared resource, like a printer, CPU task scheduling etc. 34 | - In real life scenario, Call Center phone systems uses Queues to hold people calling them in an order, until a service representative is free. 35 | - Handling of interrupts in real-time systems. The interrupts are handled in the same order as they arrive i.e First come first served 36 | 37 | ## Resources 38 | 39 | - [Queue - GeeksForGeeks](https://www.geeksforgeeks.org/queue-data-structure/) 40 | - [Queue - TutorialsPoint](https://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm) 41 | - [Queue - Programiz](https://www.programiz.com/dsa/queue) 42 | - [Queue - StudyTonight](https://www.studytonight.com/data-structures/queue-data-structure) 43 | - [Queue - Python Docs](https://docs.python.org/3/library/queue.html)

44 | 45 | - [Queue Video Lecture - Jenny Lectures](https://www.youtube.com/watch?v=zp6pBNbUB2U) 46 | - [Queue in C](https://www.youtube.com/watch?v=gnYM_G1ILm0) 47 | - [Queue - MyCodeSchool](https://www.youtube.com/watch?v=okr-XE8yTO8) 48 | - [Queue - Esucation4You](https://www.youtube.com/watch?v=HI34Oytjjb4) 49 | - [Queue - Abdul Bari(Follow Suggested Videos for more)](https://www.youtube.com/watch?v=nNnGh0N9P48) 50 | - [Queues - CodeWithHarry](https://www.youtube.com/watch?v=JlZX7xIBjl0) 51 | - [Stacks, Queues And Priority Queues](https://drive.google.com/file/d/0B4AmxgIIrh_SUjN2VXE0NU5Benc/view) 52 | - [Stacks And Queues - Princeton](https://introcs.cs.princeton.edu/java/43stack/) 53 | - [Stacks And Queues In Python](https://stackabuse.com/stacks-and-queues-in-python/) 54 | 55 | ## Popular Practice Problems 56 | 57 | - [Problem 1 - LeetCode](https://leetcode.com/problems/design-circular-deque/) 58 | -------------------------------------------------------------------------------- /Comprehensive_Guides/LinkedList.md: -------------------------------------------------------------------------------- 1 |

Linked Lists


2 | 3 | ## What is a Linked List? 4 | A linked list is a linear data structure where each element is a separate object.
5 | Linked list elements are not stored at contiguous location; the elements are linked using pointers. 6 | 7 | Each node of a list is made up of two items - the data and a reference to the next node. The last node has a reference to null. The entry point into a linked list is called the head of the list. It should be noted that head is not a separate node, but the reference to the first node. If the list is empty then the head is a null reference. 8 | 9 | Linked List Image 10 | 11 | ## Types of Linked Lists 12 | 13 | - Singly Linked List : Basic Linked list consists of a node that has 1 data and 1 pointer. The pointer points to the next node and so on. The last node points to null. 14 | 15 | - Circular Linked List : Similar to Singly linked list but the last node points to the first one forming a circle. 16 | 17 | - Doubly linked List : Each node has 1 data and 2 pointers. Usually, the left pointer points to last node and right pointer points to the next node. Circular Doubly Linked List also exist where the right pointer of last node points to first node and left pointer of first node points to last node. 18 | 19 | ## Linked List Operations 20 | 21 | 1) Traversal 22 | 23 | 2) Insert 24 | - Insert at start 25 | - Insert at Beginning 26 | - Insert After an element 27 | - Insert Before an element 28 | 29 | 3) Delete : (Algorithms are listed in Resources Section) 30 | - Delete at start 31 | - Delete at Beginning 32 | - Delete After an element 33 | - Delete Before an element 34 | 35 | 4) Search for element : Similar algos as that for Arrays 36 | 37 | ## Advantages of Linked Lists 38 | 39 | 1. They are a dynamic in nature which allocates the memory when required. 40 | 2. Insertion and deletion operations can be easily implemented. 41 | 3. Stacks and queues can be easily executed. 42 | 4. Linked List reduces the access time. 43 | 44 | ## Disadvantages of Linked Lists 45 | 46 | 1. The memory is wasted as pointers require extra memory for storage. 47 | 2. No element can be accessed randomly; it has to access each node sequentially. 48 | 3. Reverse Traversing is difficult in linked list. 49 | 50 | ## Applications of Linked Lists 51 | 52 | - Linked lists are used to implement stacks, queues, graphs, etc. 53 | - Linked lists let you insert elements at the beginning and end of the list. 54 | - In Linked Lists we don't need to know the size in advance. 55 | 56 | ## Resources 57 | 58 | You can find the Algorithms for each Operation and Many more types of Linked Lists Here: 59 | 60 | - [GeeksForGeeks Linked List](https://www.geeksforgeeks.org/data-structures/linked-list/) 61 | - [TutorialsPoint Linked List](https://www.tutorialspoint.com/data_structures_algorithms/linked_list_algorithms.htm) 62 | - [Linked List - StudyTonight](https://www.studytonight.com/data-structures/introduction-to-linked-list) 63 | 64 | 65 | - [Linked List HackerRank Course](https://www.youtube.com/watch?v=njTh_OwMljA) 66 | - [Linked List Introduction CS Dojo](https://youtu.be/WwfhLC16bis) 67 | - [Linked List - Abdul Bari(After this follow the suggested videos)](https://youtu.be/5C6JSsmbBoo) 68 | - [Linked Lists in C](https://youtu.be/eGnlKPCkAFY) 69 | - [Linked Lists Course - MU Syllabus](https://www.youtube.com/playlist?list=PLCbbVSS5VBbvh_L7DfZPN7XPXNJLq8vkE) 70 | - [Linked Lists - CodeWhoop](https://www.youtube.com/playlist?list=PLZgR0futJAU3fCGJn2UvRWbkLqmEje_cd) 71 | - [Linked Lists Introduction - CodeWithHarry](https://youtu.be/TWMCMvfEAv4) 72 | - [Linked List in Python - CodeBasics](https://youtu.be/qp8u-frRAnU) 73 | - [Linked Lists In C++ - BitDegree](https://www.bitdegree.org/learn/linked-list-c-plus-plus) 74 | - [Linked Lists in Java](https://beginnersbook.com/2013/12/linkedlist-in-java-with-example/) 75 | - [Linked In Python - TutorialsPoint](https://www.tutorialspoint.com/python_data_structure/python_linked_lists.htm) 76 | 77 | ## Popular Practice Problems 78 | 79 | - [Problem 1 - LeetCode](https://leetcode.com/problems/merge-two-sorted-lists/) 80 | - [Problem 2 - LeetCode](https://leetcode.com/problems/reverse-linked-list-ii/) 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # ⚡ Data Structures & Algorithms - A Comprehensive Guide 3 | 4 | Banner Image 5 | 6 |

7 | A Comprehensive Guide on Data Structures & Algorithms 8 |

9 | 10 | ## Table of Contents 11 | * Traditional Method 12 | * Unconventional Method 13 | * Test Your Knowledge! 14 | 15 | --- 16 | ### Traditional Method 17 | *The solid easy route to go down the data structures and algorithms hill, risk free and widely used, follow through:* 18 | 1. [Arrays](Comprehensive_Guides/Arrays.md) 19 | 2. [Linked List](Comprehensive_Guides/LinkedList.md) 20 | 3. [Stacks](Comprehensive_Guides/Stack.md) 21 | 4. [Queues](Comprehensive_Guides/Queue.md) 22 | 5. [Hash Tables](Comprehensive_Guides/HashTable.md) 23 | 6. [Trees](Comprehensive_Guides/Tree.md) 24 | 7. [Heaps](Comprehensive_Guides/Heap.md) 25 | 8. [Graphs](Comprehensive_Guides/Graph.md) 26 | 27 | [Also Check Out some Popular Algorithms And Practice Problems](Comprehensive_Guides/Algorithm.md) 28 |
29 | **! Make sure you go through each of these in detail, the explanation is also provided in each individual link!** 30 |
31 |
32 | [Also Check out the Sample Codes for each Data Structures](Codes/README.md) 33 | 34 | ### Unconventional Method 35 | *If you are not interested in going down the traditional route of learning each type, There are courses that cover entirety of Data Structures:* 36 | 37 | - [All Data Structures 8 hour course by William Fiset](https://youtu.be/RBSGKlAvoiM) 38 | - [In Depth Algorithms Playlist by Abdul Bari](https://www.youtube.com/playlist?list=PLDN4rrl48XKpZkf03iYFl-O29szjTrs_O) 39 | - [Data Structures And Algorithms course for GATE](https://www.youtube.com/playlist?list=PLEVDNf7p-wYyh712BgmW9UGrAc88bl3OF) 40 | - [Stanford Algorithms Course](https://www.youtube.com/playlist?list=PLXFMmlk03Dt7Q0xr1PIAriY5623cKiH7V) 41 | - [Algorithms MIT Course](https://www.youtube.com/playlist?list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb) 42 | 43 | ### Test Your Knowledge! 44 | *After learning all this to gain an edge over others, you need to practice and keep practicing. There are some websites to learn and practice daily:* 45 | 46 | - [Leet Code](https://leetcode.com/) 47 | - [InterviewBit](https://www.interviewbit.com/) 48 | - [Hackerrank](https://www.hackerrank.com/) 49 | - [CodeWars](https://www.codewars.com/) 50 | - [CodinGame (A fun way to code with games)](https://www.codingame.com/start) 51 | --- 52 | 53 | **How to Contribute** 54 | --- 55 | 1. Clone repo and create a new branch: `$ git checkout https://github.com/CSI-SFIT/Data-Structures-and-Algorithms--A-Comprehensive-Guide.git -b name_for_new_branch`. 56 | 2. Make changes and test. 57 | 3. Submit Pull Request with comprehensive description of changes. 58 | 59 | **Acknowledgements** 60 | --- 61 | 62 | **CSI SFIT Tech Team 2020 - 2021 :** 63 | + Tech Executive : [@Varun-Patkar](https://github.com/Varun-Patkar) 64 | + Tech Executive : [@EktaMasrani](https://github.com/ekta18) 65 | 66 |

67 | 68 | csi_logo 70 | 71 |

72 | 73 |
74 | 75 | 76 | 77 | 78 | 79 | 80 |
81 | -------------------------------------------------------------------------------- /Comprehensive_Guides/Arrays.md: -------------------------------------------------------------------------------- 1 |

Arrays


2 | 3 | ## What are Arrays? 4 | 5 | An array is a structure of fixed-size, which can hold items of the same data type. It can be an array of integers, an array of floating-point numbers, an array of strings or even an array of arrays (such as 2-dimensional arrays). Arrays are indexed, meaning that random access is possible. 6 | 7 | Arrays Image 8 | 9 | ## Array Operations 10 | 11 | Arrays have 5 types of operations: 12 | 13 | - Traversal - Going through the array once 14 | - Searching - Searching the array for a specific value 15 | - Update - Updating the array at a given index 16 | - Insertion - This cannot be done simply as size of arrays is immutable(can't be changed). So you need to define another array with length = len(orig_arr)+1 17 | - Deletion - This cannot be done simply as size of arrays is immutable. So you need to define another array with length = len(orig_arr)-1 18 | 19 | ## Array Applications 20 | 21 | - They are used to implement higher level of data structures like ArrayLists, Heaps, Hash Tables, etc. 22 | 23 | ## Array Algorithms 24 | 25 | #### 1) Traversal Algorithm: 26 | 27 | There is only one algorithms for traversal. You can go front to back or back to front. You set a counter to 0 and go on till it is less than len(arr). Then you access each entry for that using the pointer and do the operation and then reassign it.
In some languages like Java and Python, instead of referring by indices to each, we can loop over the array using enhanced for loops and directly do traversal without a counter. 28 | 29 | #### 2) Insertion Algorithm: 30 | 31 | Insertion uses another array with length len(arr)+1. It copies all the elements till the one to be inserted then we insert the value to be inserted and then insert the rest of the array. Then we delete overwrite the original array with the new one. 32 | 33 | #### 3) Deletion Algorithm: 34 | 35 | Deletion uses another array with length len(arr)-1. We copy all the elements except the element to be deleted and then overwrite the original array with the new one. 36 | 37 | #### 4) Searching Algorithms: 38 | 39 | There are many Searching algorithms famous in the Coding community. The most prominent are: 40 | 41 | - Linear Search 42 | - Binary Search 43 | 44 | There are many more like Jump Search, Interpolation Search, Exponential Search, etc. 45 | 46 | ## Resources 47 | 48 | Links to Searching Algorithms: 49 | 50 | - [GeeksForGeeks Searching Algorithms](https://www.geeksforgeeks.org/searching-algorithms/) 51 | 52 | - [TutorialsPoint Page for Searching Algorithms](https://www.tutorialspoint.com/data_structures_algorithms/) 53 | 54 | To learn more about Arrays visit the sites below: 55 | 56 | - [Oracle Tutorial for Arrays in Java](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) 57 | 58 | - [Arrays in C - TutorialsPoint](https://www.tutorialspoint.com/cprogramming/c_arrays.htm) 59 | 60 | - [Arrays in JavaScript - W3Schools](https://www.w3schools.com/js/js_arrays.asp) 61 | 62 | - [Arrays Data Structure - GeeksForGeeks](https://www.geeksforgeeks.org/array-data-structure/) 63 | 64 | Some Courses on Arrays are: 65 | 66 | - [Arrays Course on CodeAcademy](https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-arrays) 67 | 68 | - [Search for MOOCs on Arrays](https://www.mooc-list.com/tags/arrays) 69 | 70 | - [Java Arrays - Telusko](https://youtu.be/fuDNAKStpq0) 71 | 72 | - [Complete Arrays Path - Abdul Bari](https://youtu.be/WlHUobpwxo8) 73 | 74 | - [Arrays - CodeWithHarry](https://youtu.be/p5TDnxAYAZY) 75 | 76 | - [Arrays - CS Dojo](https://youtu.be/pmN9ExDf3yQ) 77 | 78 | - [Arrays in Processing - CodingTrain(Follow Suggested Videos for more)](https://youtu.be/NptnmWvkbTw) 79 | 80 | 81 | 82 | 83 | - [Arrays In C++ - BitDegree](https://www.bitdegree.org/learn/c-plus-plus-vector) 84 | 85 | - [Vectors in C++ - ReelLearning](https://youtu.be/SGyutdso6_c) 86 | 87 | - [Java Array List With Examples - HowToDOInJava](https://howtodoinjava.com/java-arraylist/) 88 | 89 | - [Lists In Python - W3Schools](https://www.w3schools.com/python/python_lists.asp) 90 | 91 | ## Popular Practice Problems 92 | 93 | - [Problem 1 - CodeChef](https://www.codechef.com/LRNDSA01/problems/FLOW007) 94 | - [Problem 2 - CodeChef](https://www.codechef.com/LRNDSA01/problems/ZCO14003) 95 | - [Problem 3 - CodeChef](https://www.codechef.com/LRNDSA05/problems/BINXOR) 96 | - [Problem 4 - LeetCode](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) 97 | - [Problem 5 - LeetCode](https://leetcode.com/problems/container-with-most-water/) 98 | -------------------------------------------------------------------------------- /Comprehensive_Guides/Stack.md: -------------------------------------------------------------------------------- 1 |

Stack


2 | 3 | ## What is a Stack? 4 | 5 | Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). 6 | 7 | There are many real-life examples of a stack. Consider an example of plates stacked over one another in the canteen. The plate which is at the top is the first one to be removed, i.e. the plate which has been placed at the bottommost position remains in the stack for the longest period of time. So, it can be simply seen to follow LIFO(Last In First Out)/FILO(First In Last Out) order. 8 | 9 | Stack Image 10 | 11 | ## Stack Implementations 12 | 13 | 1.Array: There is a TOP pointer that always points to the top element. Initially it is NULL. On adding 1 element is becomes 0 and so on. It also has a MAX variable which contains the size of the array at time of declaration. If TOP is MAX-1 and we try to add another element we give OVERFLOW ERROR(can't add anymore) and if we try to delete when TOP=NULL then we give UNDERFLOW ERROR(can't delete from empty stack). 14 | 15 | 2.Linked List: There is a TOP pointer that points to top node. Initially is NULL. if TOP is NULL and we try to delete we give UNDERFLOW. There is no OVERFLOW as Linked List is dynamic and can have as many nodes as possible. 16 | 17 | ## Stack Operations 18 | 19 | 1. Push(Insertion) : If implementing Array, we initialize the TOP+1 position as the value and increment TOP. We check the conditions written in Implementation. 20 |
If implementing as a Linked List, we check condition, point TOP node's pointer to new node, append value to the list and point TOP to the new node. 21 | 22 | 2. Pop(Deletion) : If implementing Array, we check the conditions and decrement TOP.
23 | If implementing as a Linked List, we check condition, point the second to last node's pointer to null, point TOP to second to last element and free/delete last node. 24 | 25 | There are other operations too like peek, etc. but they use the same logic as Push and Pop. 26 | 27 | ## Advantages of Stack 28 | 29 | - Helps you to manage the data in a Last In First Out(LIFO) method which is not possible with Linked list and array. 30 | - When a function is called the local variables are stored in a stack, and it is automatically destroyed once returned. 31 | - A stack is used when a variable is not used outside that function. 32 | - It allows you to control how memory is allocated and deallocated. 33 | - Stack automatically cleans up the object. 34 | - Not easily corrupted 35 | - Variables cannot be resized. 36 | 37 | ## Disadvantages of Stack 38 | 39 | - Stack memory is very limited. 40 | - Creating too many objects on the stack can increase the risk of stack overflow. 41 | - Random access is not possible. 42 | - Variable storage will be overwritten, which sometimes leads to undefined behavior of the function or program. 43 | - The stack will fall outside of the memory area, which might lead to an abnormal termination. 44 | 45 | ## Application of Stack 46 | 47 | - It is used in expression parsing, to check format in commands, etc. 48 | - They are used in Backtracking algorithms. 49 | 50 | ## Resources 51 | 52 | - [Stack - GeeksForGeeks](https://www.geeksforgeeks.org/stack-data-structure/) 53 | - [Stack - Programiz](https://www.programiz.com/dsa/stack) 54 | - [Stack - TutorialsPoint](https://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm) 55 | - [Stack - JavaDocs](https://docs.oracle.com/javase/7/docs/api/java/util/Stack.html) 56 | - [Stack - StudyTonight](https://www.studytonight.com/data-structures/stack-data-structure) 57 |

58 | - [Stack Video Course- GeeksForGeeks](https://www.youtube.com/playlist?list=PLqM7alHXFySF7Lap-wi5qlaD8OEBx9RMV) 59 | - [Stack in C](https://youtu.be/BrVZZZkkGGI) 60 | - [Stack - Jenny's Lectures](https://youtu.be/bxRVz8zklWM) 61 | - [Introduction to Stacks - Abdul Bari(Follow Suggested Videos for more)](https://youtu.be/HXE1arB8NNs) 62 | - [Stacks - CodeWithHarry](https://youtu.be/-n2rVJE4vto) 63 | - [Stacks - Aditya Verma](https://www.youtube.com/playlist?list=PL_z_8CaSLPWdeOezg68SKkeLN4-T_jNHd) 64 | - [Stacks, Queues And Priority Queues](https://drive.google.com/file/d/0B4AmxgIIrh_SUjN2VXE0NU5Benc/view) 65 | - [Stacks And Queues - Princeton](https://introcs.cs.princeton.edu/java/43stack/) 66 | - [Stacks And Queues In Python](https://stackabuse.com/stacks-and-queues-in-python/) 67 | 68 | ## Popular Practice Problems 69 | 70 | - [Problem 1 - CodeChef](https://www.codechef.com/problems/MULHANOI) 71 | - [Problem 2 - CodeChef](https://www.codechef.com/LRNDSA02/problems/ZCO12001) 72 | - [Problem 3 - LeetCode](https://leetcode.com/problems/simplify-path/) 73 | -------------------------------------------------------------------------------- /Comprehensive_Guides/Graph.md: -------------------------------------------------------------------------------- 1 |

Graphs


2 | 3 | ## What are Graphs? 4 | 5 | A graph consists of a finite set of vertices or nodes and a set of edges connecting these vertices. 6 | The order of a graph is the number of vertices in the graph. The size of a graph is the number of edges in the graph. 7 | Two nodes are said to be adjacent if they are connected to each other by the same edge. 8 | 9 | ## Types Of Graphs 10 | 11 | There area lot of types for graphs. I'm listing the top ones. Check out the resources for many many more. 12 | 13 | 1. Directed Graphs 14 | 2. Undirected Graphs 15 | 3. Tree(Tree is a graph with no cycles) 16 | 4. Bipartite Graphs 17 | 5. Complete Graphs 18 | 19 | ## Representing Graphs 20 | 21 | 1. Adjacency Matrix: It is used to represent directed graphs. It contains of a matrix with each element representing the weight of the connection between those 2 nodes 22 | 23 | 2. Adjacency List: It consists of a list where each element is the weight of path between the connection of that element and all other elements 24 | 25 | 3. Edge List: It consists of elements in format (x,y,z) where x is 1 node and y is another node and z is the weight between x and y 26 | 27 | 28 | ## Common Problems in Graphs 29 | 30 | - Shortest Path Problem 31 | - Continuity 32 | - Number of Negative Cycles 33 | - Finding Strongly Connected Components 34 | - Travelling Salesman Problem 35 | - Finding Bridges between 2 nodes 36 | - Finding Articulation Points 37 | - Finding Minimum Spanning Trees 38 | - Finding Network Flow 39 | 40 | ## Algorithms 41 | 42 | - DFS(Depth First Search) 43 | - BFS(Breadth First Search) 44 | - A* Search 45 | - Djikstra's Algorithm, etc. 46 | 47 | ## Uses of Graphs 48 | 49 | - In Computer science graphs are used to represent the flow of computation. 50 | - Google maps uses graphs for building transportation systems, where intersection of two(or more) roads are considered to be a vertex and the road connecting two vertices is considered to be an edge, thus their navigation system is based on the algorithm to calculate the shortest path between two vertices. 51 | - In Facebook, users are considered to be the vertices and if they are friends then there is an edge running between them. Facebook’s Friend suggestion algorithm uses graph theory. Facebook is an example of undirected graph. 52 | - In World Wide Web, web pages are considered to be the vertices. There is an edge from a page u to other page v if there is a link of page v on page u. This is an example of Directed graph. It was the basic idea behind Google Page Ranking Algorithm. 53 | - In Operating System, we come across the Resource Allocation Graph where each process and resources are considered to be vertices. Edges are drawn from resources to the allocated process, or from requesting process to the requested resource. If this leads to any formation of a cycle then a deadlock will occur. 54 | 55 | ## Resources 56 | 57 | - [Graphs - GeeksForGeeks](https://www.geeksforgeeks.org/graph-data-structure-and-algorithms/) 58 | - [Graphs - TutorialsPoint](https://www.tutorialspoint.com/data_structures_algorithms/graph_data_structure.htm) 59 | - [Graphs - Programiz](https://www.programiz.com/dsa/graph) 60 | - [Graphs - HackerEarth](https://www.hackerearth.com/practice/algorithms/graphs/graph-representation/tutorial/) 61 | - [Graphs - Educative](https://www.educative.io/edpresso/what-is-a-graph-data-structure) 62 | - [Graphs JavatPoint](https://www.javatpoint.com/ds-graph) 63 | 64 | 65 | - [Graphs - MyCodeSchool](https://www.youtube.com/watch?v=gXgEDyodOJU&t=154s) 66 | - [Graphs - Jenny's Lectures](https://www.youtube.com/watch?v=5hPfm_uqXmw) 67 | - [Graphs - GeeksForGeeks](https://www.youtube.com/playlist?list=PLqM7alHXFySEaZgcg7uRYJFBnYMLti-nh) 68 | - [Graphs - Abdul Bari](https://www.youtube.com/watch?v=pcKY4hjDrxk) 69 | 70 | ## Special Algorithms and Practice Problems 71 | ### BFS and DFS 72 | - Algorithms 73 | - [BFS and DFS - HackerRank](https://youtu.be/zaBhtODEL0w) 74 | - [BFS and DFS - Abdul Bari](https://youtu.be/pcKY4hjDrxk) 75 | 76 | - Practice Problems 77 | - [Problem 1 - SPOJ](http://www.spoj.com/problems/PPATH/) 78 | - [Problem 2 - CodeForces](https://codeforces.com/problemset/problem/910/A) 79 | - [Problem 3 - Codechef](https://www.codechef.com/problems/FIRESC) 80 | - [Problem 4 - SPOJ](http://www.spoj.com/problems/BUGLIFE/) 81 | - [Problem 5 - SPOJ](http://www.spoj.com/problems/KFSTB/) 82 | - [Problem 6 - CodeForces](https://codeforces.com/problemset/problem/500/A) 83 | - [Problem 7 - CodeForces](https://codeforces.com/problemset/problem/727/A) 84 | - [Problem 8 - SPOJ](http://www.spoj.com/problems/ELEVTRBL/) 85 | - [Problem 9 - SPOJ](http://www.spoj.com/problems/ROBOTGRI/) 86 | - [Problem 10 - CodeForces](https://codeforces.com/problemset/problem/129/B) 87 | - [Problem 11 - SPOJ](http://www.spoj.com/problems/LABYR1/) 88 | - [Problem 12 - SPOJ](http://www.spoj.com/problems/QUEEN/) 89 | 90 | 91 | ### DFS 92 | - Algorithms 93 | - [DFS - CP Algorithms](https://cp-algorithms.com/graph/depth-first-search.html) 94 | - [DFS - 95 | Sundeep Saradhi Kanthety](https://youtu.be/xwlRWdAHMBg) 96 | - [DFS - Gate Smashers](https://youtu.be/f8luGFRtshY) 97 | 98 | ### BFS 99 | - Algorithms 100 | - [BFS - CP Algorithms](https://cp-algorithms.com/graph/breadth-first-search.html) 101 | - [BFS - Sundeep Saradhi Kanthety](https://youtu.be/cMELxr5hKYU) 102 | - [BFS - Gate Smashers](https://youtu.be/qul0f79gxGs) 103 | 104 | 105 | ### Kruskal's Algorithm to find Minimum Spanning Tree 106 | - Algorithms 107 | - [Kruskal's Algorithm - CP Algorithms](https://cp-algorithms.com/graph/mst_kruskal.html) 108 | - [Kruskal's Algorithm - Abdul Bari](https://youtu.be/4ZlRH0eK-qQ) 109 | - [Kruskal's Algorithm - Gate Smashers](https://youtu.be/huQojf2tevI) 110 | 111 | - Practice Problems 112 | - [Problem 1 - SPOJ](https://www.spoj.com/problems/MST/) 113 | - [Problem 2 - CodeChef](https://www.codechef.com/problems/MSTQS) 114 | - [Problem 3 - SPOJ](http://www.spoj.com/problems/NITTROAD/) 115 | - [Problem 4 - CodeChef](https://www.codechef.com/problems/GALACTIK) 116 | - [Problem 5 - SPOJ](http://www.spoj.com/problems/KOICOST/) 117 | - [Problem 6 - SPOJ](http://www.spoj.com/problems/CSTREET/) 118 | - [Problem 7 - SPOJ](http://www.spoj.com/problems/BLINNET/) 119 | - [Problem 8 - CodeChef](https://www.codechef.com/problems/GOOGOL03) 120 | - [Problem 9 - SPOJ](http://www.spoj.com/problems/HIGHWAYS/) 121 | - [Problem 10- SPOJ](http://www.spoj.com/problems/IITWPC4I/) 122 | 123 | 124 | ### Dijkstra's Algorithm(Pathfinding in Graph) 125 | - Algorithms 126 | - [Dijkstra's Algorithm - CP Algorithms](https://cp-algorithms.com/graph/dijkstra.html) 127 | - [Dijkstra's Algorithm - GeeksForGeeks](https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/) 128 | - [Dijkstra's Algorithm - Programiz](https://www.programiz.com/dsa/dijkstra-algorithm) 129 | - [Dijkstra's Algorithm - Abdul Bari](https://youtu.be/XB4MIexjvY0) 130 | - [Dijkstra's Algorithm - Computer Science](https://youtu.be/pVfj6mxhdMw) 131 | 132 | - Practice Problems 133 | - [Problem 1 - CodeChef](https://www.codechef.com/problems/HW3G) 134 | - [Problem 2 - CodeForces](https://codeforces.com/contest/715/problem/B) 135 | - [Problem 3 - CodeChef](https://www.codechef.com/problems/STRGRA) 136 | - [Problem 4 - SPOJ](https://www.spoj.com/problems/EZDIJKST/) 137 | - [Problem 5 - CodeChef](https://www.codechef.com/problems/INLO33) 138 | - [Problem 6 - CodeForces](https://codeforces.com/contest/59/problem/E) 139 | - [Problem 7 - CodeChef](https://www.codechef.com/problems/KNGPRB) 140 | - [Problem 8 - CodeChef](https://www.codechef.com/problems/PAIRCLST) 141 | - [Problem 9 - CodeForces](https://codeforces.com/contest/449/problem/B) 142 | - [Problem 10 - CodeChef](https://www.codechef.com/problems/DIGJUMP) 143 | 144 | 145 | 146 | ### Prim's Algorithm to find Minimum Spanning Tree 147 | - Algorithms 148 | - [Prim's Algorithm - CP Algorithms](https://cp-algorithms.com/graph/mst_prim.html) 149 | - [Prim's Algorithm - GeeksForGeeks](https://www.geeksforgeeks.org/prims-minimum-spanning-tree-mst-greedy-algo-5/) 150 | - [Prim's Algorithm - TutorialsPoint](https://www.tutorialspoint.com/data_structures_algorithms/prims_spanning_tree_algorithm.htm) 151 | - [Prim's Algorithm - Jenny's Lectures](https://youtu.be/ZtZaR7EcI5Y) 152 | - [Prim's Algorithm - GeeksForGeeksYT](https://youtu.be/eB61LXLZVqs) 153 | -------------------------------------------------------------------------------- /Comprehensive_Guides/Tree.md: -------------------------------------------------------------------------------- 1 |

Trees


2 | 3 | ## What is a Tree? 4 | 5 | A tree is recursively defined as a set of one or more 6 | nodes where one node is designated as the root of the 7 | tree and all the remaining nodes can be partitioned into 8 | non-empty sets each of which is a sub-tree of the root. This structure is different than a linked list whereas, in a linked list, items are linked in a linear order. 9 | 10 | Various types of trees have been developed throughout the past decades, in order to suit certain applications and meet certain constraints. Some examples are binary search tree, B tree, treap, red-black tree, splay tree, AVL tree and n-ary tree. 11 | 12 | ## Terminology 13 | 14 | - Root node: The root node R is the topmost node in the tree. If R = NULL, then it means the tree is empty. 15 | 16 | - Sub-trees: If the root node R is not NULL, then the trees T1 , 17 | T2 , and T3 are called the sub-trees of R. 18 | 19 | - Leaf: node A node that has no children is called the leaf node 20 | or the terminal node. 21 | 22 | - Path: A sequence of consecutive edges is called a path. For 23 | example, in Fig. 9.1, the path from the root node A to node I 24 | is given as: A, D, and I. 25 | 26 | - Ancestor node: An ancestor of a node is any predecessor node on the 27 | path from root to that node. The root node does not have any 28 | ancestors. In the tree given in Fig. 9.1, nodes A, C, and G are the 29 | ancestors of node K. 30 | 31 | - Descendant node: A descendant node is any successor node on any 32 | path from the node to a leaf node. Leaf nodes do not have any 33 | descendants. In the tree given in Fig. 9.1, nodes C, G, J, and K are the 34 | descendants of node A. 35 | 36 | - Level number: Every node in the tree is assigned a level number in such 37 | a way that the root node is at level 0, children of the root node are at 38 | level number 1. Thus, every node is at one level higher than its parent. 39 | So, all child nodes have a level number given by parent’s level number+ 1. 40 | 41 | - Degree: Degree of a node is equal to the number of children 42 | that a node has. The degree of a leaf node is zero. 43 | 44 | - In-degree: In-degree of a node is the number of edges 45 | arriving at that node. 46 | 47 | - Out-degree: Out-degree of a node is the number of edges 48 | leaving that node 49 | 50 | ## Types of Trees 51 | 52 | 1. General trees 53 | 2. Forests: A set of disjoint trees (or forests) is obtained by deleting the root and the edges connecting the root node to nodes at level 1. 54 | 3. Binary trees: Each Node has only 2 children. 55 | 4. Binary search trees: BST with ordered data 56 | 5. Expression trees 57 | 6. Tournament trees 58 | 7. AVL Tree 59 | 8. B Tree 60 | 9. Multi Way tree 61 | 10. B+ Tree 62 | 11. Digital Search Tree 63 | 12. Game Tree 64 | 13. Decision Tree 65 | 66 | ## Tree Operations 67 | 68 | Each tree has different algorithms for each operation. Check out the resources or search the internet dor each algorithm 69 | 70 | 1. Traversal: 71 | - Inorder Traversal(LVR) 72 | - Preorder Traversal(VLR) 73 | - Postorder Traversal(LRV) 74 | 75 | 2. Insertion 76 | 3. Deletion 77 | 78 | ## Applications of Trees 79 | 80 | - Store hierarchical data, like folder structure, organization structure, XML/HTML data. 81 | - Binary Search Tree is a tree that allows fast search, insert, delete on a sorted data. It also allows finding closest item 82 | - Heap is a tree data structure which is implemented using arrays and used to implement priority queues. 83 | - B-Tree and B+ Tree : They are used to implement indexing in databases. 84 | - Syntax Tree: Used in Compilers. 85 | - K-D Tree: A space partitioning tree used to organize points in K dimensional space. 86 | - Trie : Used to implement dictionaries with prefix lookup. 87 | Suffix Tree : For quick pattern searching in a fixed text. 88 | - Spanning Trees and shortest path trees are used in routers and bridges respectively in computer networks 89 | - As a workflow for compositing digital images for visual effects. 90 | ## Resources 91 | 92 | - [Decision Tree GeeksForGeeks](https://www.geeksforgeeks.org/decision-tree/) 93 | - [Binary Tree GeeksForGeeks](https://www.geeksforgeeks.org/binary-tree-data-structure/) 94 | - [AVL Tree - Wikipedia](https://en.wikipedia.org/wiki/AVL_tree) 95 | - [Trees - TutorialsPoint](https://www.tutorialspoint.com/data_structures_algorithms/avl_tree_algorithm.htm) 96 | - [Trees - Programiz](https://www.programiz.com/dsa/trees) 97 | - [Trees - JavatPoint](https://www.javatpoint.com/tree) 98 | - [Trees - TutorialRide](https://www.tutorialride.com/data-structures/trees-in-data-structure.htm) 99 |

100 | - [Trees - Hackerrank](https://www.youtube.com/watch?v=oSWTXtMglKE) 101 | - [Trees - MyCodeSchool](https://www.youtube.com/watch?v=qH6yxkw0u78) 102 | - [Trees - Arnab Sen](https://www.youtube.com/playlist?list=PL-pUjcDnciX3Z5AEE8HHRrcfj-987Ia94) 103 | - [Trees - Jenny Lectures](https://www.youtube.com/playlist?list=PL9LqbynX3r56pZA9Y1tx_ROnsNcshDAIJ) 104 | - [Trees - Abdul Bari](https://www.youtube.com/watch?v=EWCgpVUZaB0) 105 | - [Trees CodeBasics](https://www.youtube.com/watch?v=4r_XR9fUPhQ) 106 | 107 | ## Special Algorithms and Practice Problems 108 | 109 | ### Segment Tree : 110 | - Algorithms 111 | - [Segment Tree - CPAlgorithms](https://cp-algorithms.com/data_structures/segment_tree.html) 112 | - [Segment Tree - Rachit Jain](https://youtu.be/Ic7OO3Uw6J0) 113 | - [Segment Tree - Tushar Roy](https://youtu.be/ZBHKZF5w4YU) 114 | - Practice Problems 115 | - [Problem 1 - CodeForces](https://codeforces.com/contest/356/problem/A) 116 | - [Problem 2 - CodeForces](https://codeforces.com/problemset/problem/895/E) 117 | - [Problem 3 - SPOJ](http://www.spoj.com/problems/KQUERY/) 118 | - [Problem 4 - CodeForces](https://codeforces.com/problemset/problem/1234/D) 119 | - [Problem 5 - CodeForces](https://codeforces.com/contest/121/problem/E) 120 | - [Problem 6 - OnlineJudge](https://oj.uz/problem/view/COCI17_deda) 121 | 122 | 123 | ### Disjoint Set Union : 124 | - Algorithms 125 | - [Disjoint Set Union - CPAlgorithms](https://cp-algorithms.com/data_structures/disjoint_set_union.html) 126 | - [Disjoint Set Union - GeeksForGeeks](https://www.geeksforgeeks.org/union-find/) 127 | - [Disjoint Set Union - Abdul Bari](https://youtu.be/wU6udHRIkcc) 128 | - [Disjoint Set Union - Tushar Roy](https://youtu.be/ID00PMy0-vE) 129 | - Practice Problems 130 | - [Problem 1 - CodeChef](https://www.codechef.com/problems/GALACTIK) 131 | - [Problem 2 - CodeChef](https://www.codechef.com/problems/DISHOWN) 132 | - [Problem 3 - CodeForces](http://codeforces.com/problemset/problem/547/B) 133 | - [Problem 4 - CodeChef](https://www.codechef.com/problems/JABO) 134 | - [Problem 5 - CodeChef](https://www.codechef.com/problems/PARITREE) 135 | - [Problem 6 - CodeForces](http://codeforces.com/contest/151/problem/D) 136 | - [Problem 7 - CodeChef](https://www.codechef.com/problems/MAGICSTR) 137 | - [Problem 8 - CodeChef](https://www.codechef.com/problems/BIGOF01) 138 | - [Problem 9 - CodeChef](https://www.codechef.com/problems/FIRESC) 139 | 140 | 141 | ### Fenwick Tree : 142 | - Algorithms 143 | - [Fenwick Tree - CPAlgorithms](https://cp-algorithms.com/data_structures/fenwick.html) 144 | - [Fenwick Tree - VisualGo](https://visualgo.net/en/fenwicktree) 145 | - [Fenwick Tree - Tushar Roy](https://youtu.be/CWDQJGaN1gY) 146 | - [Fenwick Tree - TakeUForward](https://youtu.be/9uaXG62Y8Uw) 147 | - Practice Problems 148 | - [Problem 1 - OnlineJudge](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3238) 149 | - [Problem 2 - CodeForces](http://codeforces.com/contest/777/problem/E) 150 | - [Problem 3 - SPOJ](http://www.spoj.com/problems/CTRICK/) 151 | - [Problem 4 - SPOJ](http://www.spoj.com/problems/DQUERY/) 152 | - [Problem 5 - CodeForces](http://codeforces.com/contest/669/problem/E) 153 | - [Problem 6 - SPOJ](http://www.spoj.com/problems/YODANESS/) 154 | - [Problem 7 - SPOJ](http://www.spoj.com/problems/SUMSUM/) 155 | - [Problem 8 - SPOJ](http://www.spoj.com/problems/ADACABAA/) 156 | 157 | 158 | ### Sqrt Decomposition : 159 | - Algorithms 160 | - [Sqrt Decomposition - CPAlgorithms](https://cp-algorithms.com/data_structures/sqrt_decomposition.html) 161 | - [Sqrt Decomposition - GeeksForGeeks](https://www.geeksforgeeks.org/sqrt-square-root-decomposition-technique-set-1-introduction/) 162 | - [Sqrt Decomposition - Gaurav Sen](https://youtu.be/gWbDocYhwDA) 163 | - [Sqrt Decomposition - CodeNCode](https://youtu.be/o7278rPg_9I) 164 | 165 | - Practice Problems 166 | - [Problem 1 - SPOJ](http://www.spoj.com/problems/GIVEAWAY/) 167 | - [Problem 2 - OnlineJudge](https://uva.onlinejudge.org/-index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3141) 168 | - [Problem 3 - CodeForces](http://codeforces.com/contest/786/problem/C) 169 | - [Problem 4 - CodeForces](http://codeforces.com/contest/840/problem/D) 170 | - [Problem 5 - SPOJ](https://www.spoj.com/problems/DQUERY) 171 | - [Problem 6 - CodeForces](https://codeforces.com/problemset/problem/617/E) 172 | -------------------------------------------------------------------------------- /Comprehensive_Guides/Algorithm.md: -------------------------------------------------------------------------------- 1 |

Popular Algorithms And Practice Problems


2 | 3 | ## Complexity Analysis 4 | 5 | - Algorithms 6 | 7 | - [Asymptotic Analysis - GeeksForGeeks](https://www.geeksforgeeks.org/analysis-of-algorithms-set-1-asymptotic-analysis/?ref=lbp) 8 | - [Complexity Analysis - GATE Lectures](https://youtu.be/aGjL7YXI31Q) 9 | - [Big O Notation - Michael Sombol](https://www.youtube.com/watch?v=__vX2sjlpXU) 10 | 11 | 12 | ## Binary Exponentiation 13 | 14 | - Algorithms 15 | 16 | - [Binary Exponentiation - CPAlgorithms](https://cp-algorithms.com/algebra/binary-exp.html) 17 | - [Binary Exponentiation -Errichto](https://youtu.be/L-Wzglnm4dM) 18 | 19 | - Practice Problems 20 | 21 | - [Problem 1 - SPOJ](https://www.spoj.com/problems/LASTDIG/) 22 | - [Problem 2 - SPOJ](https://www.spoj.com/problems/ZSUM/) 23 | - [Problem 3 - OnlineJudge](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3671) 24 | 25 | ## Euclidean Algorithms(For GCD) 26 | 27 | - Algorithms 28 | 29 | - [Euclidean Algorithms - CPAlgorithms](https://cp-algorithms.com/algebra/euclid-algorithm.html) 30 | - [Euclid's Algorithms - Coding Blocks](https://youtu.be/VWOUh4w_zVI) 31 | 32 | - Practice Problems 33 | 34 | - [Problem 1 - CodeChef](https://www.codechef.com/problems/FLOW016) 35 | 36 | ## Linear Diophantine Equations 37 | 38 | - Algorithms 39 | 40 | - [Linear Diophantine Equations - CPAlgorithms](https://cp-algorithms.com/algebra/linear-diophantine-equation.html) 41 | - [Linear Diophantine Equations - GeeksForGeeks](https://www.geeksforgeeks.org/linear-diophantine-equations) 42 | 43 | - Practice Problems 44 | 45 | - [Problem 1 - SPOJ](http://www.spoj.com/problems/CEQU/) 46 | - [Problem 2 - CodeForces](http://codeforces.com/contest/633/problem/A) 47 | - [Problem 3 - CodeChef](https://www.codechef.com/problems/COPR16G) 48 | 49 | ## Bit Manipulation/Bit Masking 50 | 51 | - Algorithms 52 | 53 | - [Bit Manipulation](https://www.youtube.com/watch?v=uUtb0BaeosQ&list=PLJse9iV6ReqgcI4tec2jcyOZkaUKuGoHN) 54 | - [Bit Masking - CodinBlocks](https://youtu.be/wEZfc6cPC4w) 55 | 56 | - Practice Problems 57 | 58 | - [Problem 1 - CodeChef](https://www.codechef.com/BITM2017/problems/BITMASK5) 59 | - [Problem 2 - LeetCode](https://leetcode.com/problems/missing-number/) 60 | - [Problem 3 - CodeChef](https://www.codechef.com/BITM2017/problems/BITMASK3) 61 | - [Problem 4 - LeetCode](https://leetcode.com/problems/single-number/) 62 | 63 | 64 | ## String Problems 65 | 66 | - Algorithms 67 | 68 | - String Hashing 69 | - [String Hashing - CPAlgorithms](https://cp-algorithms.com/string/string-hashing.html) 70 | - [String Hashing - RobEdwards](https://youtu.be/jtMwp0FqEcg) 71 | - [String Hashing - Ashish Kumar](https://youtu.be/aMDHGZhwL1Q) 72 | 73 | - Prefix Function 74 | - [Prefix Algorithm - CPAlgorithms](https://cp-algorithms.com/string/prefix-function.html) 75 | - [Prefix Algorithm - Fluent Algorithms](https://youtu.be/nJbNe0Yzjhw) 76 | 77 | - Suffix Array 78 | - [Suffix Array - CPAlgorithms](https://cp-algorithms.com/string/suffix-array.html) 79 | - [Suffix Array - William Fiset](https://www.youtube.com/playlist?list=PLDV1Zeh2NRsCQ_Educ7GCNs3mvzpXhHW5) 80 | - [Suffix Array 1 - GeeksForGeeks](https://youtu.be/uxA__b23t2w) 81 | - [Suffix Array 2 - GeeksForGeeks](https://youtu.be/86cQgXnN4WI) 82 | 83 | - Searching 84 | - [Linear Search - Jenny Lectures](https://youtu.be/C46QfTjVCNU) 85 | - [Binary Search - HackerRank](https://youtu.be/P3YID7liBug) 86 | 87 | - Sorting 88 | - [Sorting - MyCodeSchool](https://www.youtube.com/playlist?list=PL2_aWCzGMAwKedT2KfDMB9YA5DgASZb3U) 89 | 90 | - Practice Problems 91 | 92 | - String Hashing : 93 | 94 | - [Problem 1 - SPOJ](http://www.spoj.com/problems/NHAY/) 95 | - [Problem 2 - CodeForces](http://codeforces.com/problemset/problem/154/C) 96 | - [Problem 3 - CodeForces](http://codeforces.com/problemset/problem/126/B) 97 | - [Problem 4 - SPOJ](http://www.spoj.com/problems/SUB_PROB/) 98 | - [Problem 5 - CodeForces](http://codeforces.com/contest/19/problem/C) 99 | - [Problem 6 - CodeForces](http://codeforces.com/contest/7/problem/D) 100 | 101 | - Prefix function : 102 | - [Problem 1 - SPOJ](http://www.spoj.com/problems/NAJPF/) 103 | - [Problem 2 - CodeForces](http://codeforces.com/contest/808/problem/G) 104 | - [Problem 3 - CodeForces](http://codeforces.com/problemset/problem/471/D) 105 | - [Problem 4 - CodeForces](https://codeforces.com/contest/432/problem/D) 106 | 107 | 108 | - Suffix Array : 109 | - [Problem 1 - SPOJ](http://www.spoj.com/problems/LONGCS/) 110 | - [Problem 2 - SPOJ](http://www.spoj.com/problems/SUBLEX/) 111 | - [Problem 3 - CodeForces](http://codeforces.com/contest/873/problem/F) 112 | - [Problem 4 - CodeForces](http://codeforces.com/contest/30/problem/E) 113 | - [Problem 5 - CodeChef](https://www.codechef.com/problems/ANUSAR) 114 | 115 | - Linear Search : 116 | - [Problem 1 - HackerEarth](https://www.hackerearth.com/practice/algorithms/searching/linear-search/practice-problems/algorithm/rest-in-peace-21-1/) 117 | - [Problem 2- HackerEarth](https://www.hackerearth.com/practice/algorithms/searching/linear-search/practice-problems/algorithm/breakup-app/) 118 | - [Problem 3 - CodeChef](https://www.codechef.com/problems/HW2B) 119 | - [Problem 4 - CodeChef](https://www.codechef.com/problems/CHEFARRB) 120 | - [Problem 5 - CodeChef](https://www.codechef.com/problems/SEGM01) 121 | 122 | 123 | - Binary Search : 124 | - [Problem 1 LeetCode](https://leetcode.com/explore/learn/card/binary-search/146/more-practices-ii/1042/) 125 | - [Problem 2 HackerEarth](https://www.hackerearth.com/practice/algorithms/searching/binary-search/practice-problems/algorithm/to-do-b9cfd3e3/) 126 | - [Problem 3 CodeChef](https://www.codechef.com/problems/GRUSH) 127 | - [Problem 4 CodeChef](https://www.codechef.com/problems/EQSBSTR2) 128 | - [Problem 5 CodeChef](https://www.codechef.com/problems/COMAPR04) 129 | 130 | - Sorting Problems : 131 | - [Problem 1 - LeetCode](https://leetcode.com/problems/valid-anagram/) 132 | - [Problem 2 - LeetCode](https://leetcode.com/problems/insertion-sort-list/) 133 | - [Problem 3 - LeetCode](https://leetcode.com/problems/h-index/) 134 | - [Problem 4 - HackerEarth](https://www.hackerearth.com/practice/algorithms/sorting/bubble-sort/practice-problems/algorithm/pizza-confusion/) 135 | - [Problem 5 - CodeChef](https://www.codechef.com/problems/QM6P5B) 136 | - [Problem 6 - CodeChef](https://www.codechef.com/problems/COMAPR04) 137 | 138 | 139 | ## Ad Hoc Problems 140 | 141 | - Practice Problems 142 | 143 | - [Problem 1 - CodeForces](https://codeforces.com/contest/1409/problem/A) 144 | - [Problem 2 - CodeChef](https://www.codechef.com/problems/CF220) 145 | - [Problem 3 - CodeForces](https://codeforces.com/contest/1409/problem/B) 146 | - [Problem 4 - LeetCode](https://leetcode.com/problems/perfect-squares/) 147 | 148 | ## Sieve Of Eratosthenes 149 | - Algorithms 150 | - [Sieve Of Eratosthenes - CP Algorithms](https://cp-algorithms.com/algebra/sieve-of-eratosthenes.html) 151 | - [Sieve Of Eratosthenes - MyCodeSchool](https://youtu.be/eKp56OLhoQs) 152 | - [Sieve Of Eratosthenes - Region 10 ESC](https://youtu.be/V08g_lkKj6Q) 153 | - Practice Problems 154 | - [Problem 1 - SPOJ](http://www.spoj.com/problems/TDPRIMES/) 155 | - [Problem 2 - CodeForces](http://codeforces.com/contest/26/problem/A) 156 | - [Problem 3 - SPOJ](http://www.spoj.com/problems/HS08PAUL/) 157 | - [Problem 4 - SPOJ](http://www.spoj.com/problems/DCEPC505/) 158 | - [Problem 5 - CodeForces](https://codeforces.com/problemset/problem/17/A) 159 | 160 | ## Combination Generation 161 | - Algorithms 162 | - [Combination Generation - CP Algorithms](https://cp-algorithms.com/combinatorics/generating_combinations.html) 163 | - [Combination Generation - PyBear](https://youtu.be/LF4Z7Trn7yE) 164 | - Practice Problems 165 | - [Problem 1 - TutorialHorizon](https://algorithms.tutorialhorizon.com/print-all-combinations-of-subset-of-size-k-from-given-array/) 166 | - [Problem 2 - LeetCode](https://leetcode.com/problems/combinations/description/) 167 | 168 | 169 | 170 | ## Rabin-Karp Algorithm 171 | - Algorithms 172 | - [Rabin-Karp Algorithm - CP Algorithms](https://cp-algorithms.com/string/rabin-karp.html) 173 | - [Rabin-Karp Algorithm - GeeksForGeeks](https://youtu.be/oxd_Z1osgCk) 174 | - [Rabin-Karp Algorithm - Abdul Bari](https://youtu.be/qQ8vS2btsxI) 175 | - Practice Problems 176 | - [Problem 1 - SPOJ](http://www.spoj.com/problems/NAJPF/) 177 | - [Problem 2 - CodeForces](http://codeforces.com/problemset/problem/271/D) 178 | - [Problem 3 - CodeForces](https://codeforces.com/problemset/problem/835/D) 179 | 180 | 181 | 182 | ## Adv. DS (Trees, Graph, Pair, Map, Set) : 183 | - Algorithms 184 | - [Adv. DS - MyCodeSchool](https://www.youtube.com/playlist?list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P) 185 | 186 | ## Greedy Approach : 187 | - Algorithms 188 | - [Greedy Approach - GeeksForGeeks](https://www.youtube.com/playlist?list=PLqM7alHXFySESatj68JKWHRVhoJ1BxtLW) 189 | 190 | - Practice Problems 191 | - [Problem 1 - Codechef](https://www.codechef.com/problems/TACHSTCK) 192 | - [Problem 2 - Codechef](https://www.codechef.com/problems/CIELRCPT) 193 | - [Problem 3 - Codechef](https://www.codechef.com/problems/MAXDIFF) 194 | - [Problem 4 - SPOJ](http://www.spoj.com/problems/BAISED/) 195 | - [Problem 5 - SPOJ](http://www.spoj.com/problems/GCJ101BB/) 196 | - [Problem 6 - SPOJ](http://www.spoj.com/problems/ARRANGE/) 197 | - [Problem 7 - Codechef](https://www.codechef.com/problems/TADELIVE) 198 | 199 | 200 | ## Dynamic Programming : 201 | - Algorithms 202 | - [Dynamic Programming - FreeCodeCamp](https://www.freecodecamp.org/news/demystifying-dynamic-programming-3efafb8d4296/) 203 | - [Dynamic Programming - TopCoder](https://www.topcoder.com/community/competitive-programming/tutorials/dynamic-programming-from-novice-to-advanced/) 204 | - [Dynamic Programming - GeeksForGeeks](https://www.geeksforgeeks.org/dynamic-programming/) 205 | - [Dynamic Programming - TutorialsPoint](https://www.tutorialspoint.com/data_structures_algorithms/dynamic_programming.htm) 206 | - [Dynamic Programming - CS Dojo](https://youtu.be/vYquumk4nWw) 207 | - [Dynamic Programming - Aditya Verma](https://youtu.be/nqowUJzG-iM) 208 | - [Dynamic Programming - GeeksForGeeksYT](https://www.youtube.com/playlist?list=PLqM7alHXFySGbXhWx7sBJEwY2DnhDjmxm) 209 | 210 | - Practice Problems 211 | - [Problem 1 - Codechef](https://www.codechef.com/problems/ALTARAY) 212 | - [Problem 2 - CodeForces](https://codeforces.com/problemset/problem/711/C) 213 | - [Problem 3- SPOJ](https://www.spoj.com/problems/MDOLLS/) 214 | - [Problem 4 - Codechef](https://www.codechef.com/problems/GRID) 215 | - [Problem 5 - Codechef](https://www.codechef.com/problems/DBOY) 216 | - [Problem 6 - SPOJ](https://www.spoj.com/problems/MSTICK/) 217 | - [Problem 7 - Codechef](https://www.codechef.com/problems/DELISH) 218 | - [Problem 8 - SPOJ](https://www.spoj.com/problems/MIXTURES/) 219 | - [Problem 9 - CodeForces](https://codeforces.com/problemset/problem/35/D) 220 | - [Problem 10 - Codechef](https://www.codechef.com/problems/AMSGAME2) 221 | - [Problem 11 - SPOJ](https://www.spoj.com/problems/AIBOHP/) 222 | - [Problem 12 - SPOJ](https://www.spoj.com/problems/SAMER08D/) 223 | - [Problem 13 - CodeForces](https://codeforces.com/problemset/problem/1061/C) 224 | --------------------------------------------------------------------------------