GithubHelp home page GithubHelp logo

data-structures-and-algorithms-roadmap's Introduction

We'll be adding new stuff here in Nov, 2022

• 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

data-structures-and-algorithms-roadmap's People

Contributors

yuvrajverma01 avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.