Skip to content

168aziz/Data-Structures-And-Algorithms-Roadmap

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 

Repository files navigation

Data Structures And Algorithms Roadmap

• Arrays & Strings

  • Basic Array & Strings Implementation
  • Kadane's Algorithm (Max sum of continuous sub-array)
  • Dutch National Flag Algorithm
  • Sliding Window
  • Two Pointers
  • Traversal based problems
  • Rotation Based Problems

• Recursion & Backtracking

  • Understanding Recursion
  • Basic Recursion Questions
  • Understanding Backtracking
  • Divide & Conquer Algorithm

• Sorting Algorithms

  • Insertion Sort
  • Binary Insertion Sort
  • Selection Sort
  • Bubble Sort
  • Merge Sort
  • Quick Sort
  • Radix Sort

• Binary Search Applications

  • Binary Search Algorithm
  • Binary Search On Arrays
  • Binary Search On Matrix

• Linked Lists

  • Linked List Implementation
  • Reversal Problems
  • Sorting Linked Lists
  • Slow and fast Pointers
  • Modifying Linked Lists

• Stacks (LIFO)

  • Implementation
  • Prefix, Postfix, Infix problems
  • Applications/Problems

• Queues (FIFO)

  • Implementation
  • Priority Queue
  • Circular Queue
  • Applications/Problems

• Binary Trees

  • Tree Traversals
  • Construction Of Trees
  • Tree Views
  • Standard Problem

• BST

  • Construction Of BST
  • Conversion Based Problems
  • Modification in BST
  • Standard Problems
  • Priority Queues And Heaps
  • Implementation Based problems
  • Conversion based problems
  • K Based Problems

• Graphs

  • Graph Traversals - BFS And DFS
  • MST
  • Shortest Path Algorithms
  • Topological Sort
  • Graphs in Matrix

• Dynamic Programming

  • DP with Arrays
  • DP With Strings
  • DP With Maths
  • DP With Trees
  • Breaking And Partition Based Problems
  • Counting Based Problems
  • Hard Recursion And Backtracking Questions

• Other Topics

  • Hashmaps
  • Tries
  • Bit Manipulation
  • Greedy
  • Circular Queues
  • Deques - Hot Topic
  • Doubly And Circular LL
  • String Algorithms like KMP and Z

Algorithms

Kadane's Algorithm

Time Complexity: O(n)

Algo's Objective: Maximum Sum of Contiguous Subarray

def kadanealgo(arr):
    maximum = min(arr)
    cur = 0
    for i in range(len(arr)):
        cur = cur + arr[i]
        if cur > maximum:
            maximum = cur
        if cur < 0:
            cur = 0
    return

arr = [-2, -3, 4, -1, -2, 1, 5, -3]
print(kadanealgo(arr))

Dutch National Flag Algorithm

Time Complexity: O(n)

Algo's Objective: Sort an array of 0s, 1s and 2s

def dutchflagalgo(arr):
    low = 0
    mid = 0
    high = len(arr) - 1
    while mid<=high:
        if arr[mid] == 0:   #Swap low with mid
            arr[low], arr[mid] = arr[mid], arr[low]
            low = low + 1
            mid = mid + 1
        elif arr[mid] == 1: #Increment the mid counter i.e. 1's
            mid = mid + 1
        else:   #Swap mid with high
            arr[mid], arr[high] = arr[high], arr[mid]
            high = high - 1
    return arr

     #low
arr = [0, 1, 1, 0, 1, 2, 1, 2, 0, 0, 0, 1]
     #mid                              #high
print(dutchflagalgo(arr))

Sliding Window Algorithm

Time Complexity: O(n)

Algo's Objective: Maximum/Minimum Sum of K size subarray

"""
1. windowsum: Store the sum of elements of current window
2. maximum: Store the maximum sum while iterating through windows
3. While running the for loop, we are removing the 1st element of the current window and adding the rightmost element (not included) of the window.

"""

def slidingwindow(arr, k):
    windowsum = sum(arr[:k])
    maximum = windowsum
    n = len(arr)

    for i in range(n-k):
        windowsum = windowsum - arr[i] + arr[i+k]
        maximum = max(windowsum, maximum)
    return maximum

arr = [1, 4, 2, 10, 2, 3, 1, 0, 20]
k = 3
print(slidingwindow(arr, k))

Time Complexity: O(n²)

Algo's Objective: Smallest subarray with given Sum

def slidingwindow(arr, target):
    windowsum = 0              #Current window sum
    j = 0                      #Window Start
    jsize = max(arr)           #Current Window Size

    for i in range(len(arr)):
        windowsum = windowsum + arr[i]

        while windowsum >= target:
            jsize = min(jsize, i - j + 1)
            windowsum = windowsum - arr[j]
            j = j + 1
    return jsize


arr = [4, 2, 2, 7, 8, 1, 2, 8, 1, 0]
target = 8
print(slidingwindow(arr, target))

Two Pointer Algorithm

Time Complexity: O(n)

Algo's Objective: Find pairs in an array with a sum equal to k

def twopointeralgo(arr, k):
    i = 0              #represents first pointer
    j = len(arr) - 1   #represents second pointer
 
    while i<j:
        if (arr[i] + arr[j] == k):   #If we find a pair
            return 1
        elif(arr[i] + arr[j] < k):
            i = i + 1
        else:
            j -= 1
    return 0
 
arr = [3, 5, 9, 2, 8, 10, 11]
k = 17
print(twopointeralgo(arr, k))

Three Pointer Algorithm

Time Complexity: O(n)

Algo's Objective: Find triplets in an array with a sum equal to k

Time Complexity: O()

Algo's Objective: ****

Questions/Practice

• Arrays

• Arrays [MATRIX Problems]

• String

• Searching and Sorting

• Linked List

• Binary Trees

• Binary Search Trees

• Greedy

• Backtracking

• Stacks and Queues

• Heap

• Graph

• Trie

• Dynamic Programming

• Bits Manipulation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published