Thanks to visit codestin.com
Credit goes to github.com

Skip to content

veganaiZe/DSA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

📓 Data Structure & Algorithm Notes


🎭 Abstract Data Types (Interfaces)

Array (Abstract Interface)
Collection
List
Queue
Stack
  • Last in, first out (LIFO)
  • Operations
    • push (aka. append)
    • pop
  • Useful for tasks divided into sub-tasks
    • Tracking tokens while parsing
  • Concrete Implementation

🧑‍🏭 Algorithms

  • Comparison-based
    • Determines if "key" is less, equal, or greater than another.
    • Typical sorting algorithm in standard libraries.
    • Most optimal worst-case time complexity: O(n log n)
    • Heapsort
      • In-place; unstable
      • Slower than quicksort in practice.
      • Time complexity
        • Best: O(n) equal keys; O(n log n) distinct keys
        • Average / Worst: O(n log n)
      • Auxiliary space complexity
        • Worst: O(1)
    • Quicksort
      • Divide-and-conquer / recursive algorithm; typically unstable.
      • Ideal pivot point is middle value -- for guaranteed O(n lg n) for sorted data.
      • Time complexity
        • Best / Average: O(n * log n)
        • Worst: O(n^2)
      • Auxiliary space complexity
        • Naive: O(n)
        • In-place: O(log n)

  • An array is a contiguous sequence of the same type.
  • A memory buffer is (pre)allocated for all elements.
  • Random access of any element (via index).
  • Lookup by index: O(1) time
  • Lookup by value: O(n) time
  • Dynamic Array
    • Occasionally resized (copies elements; typically faster than dynamic allocations required by linked list).
    • Typical "array" type for scripting languages (typically with static array(s) utilized internally).
    • Insertion / Deletion: Amortized O(1) | O(n) time
  • Static Array
    • Cannot be resized at runtime; must re-allocate buffer & copy.
  • String
    • Typically a read-only array of characters.
  • Variable-Length Array
    • Length determined at runtime.
    • Not growable; generally preferable to use a dynamic array instead because it's growable.
  • Each element dynamically allocated (typically slower than occasional copies required by dynamic array).
  • Complexities:
    • Lookup: O(n) time
    • Insertion / Deletion: O(1) time

🎨 Design

  • Design code before writing:
    • To have a plan & avoid getting stuck.
    • To collaborate on approach for solution.
    • Because jumping straight into coding, on large projects, is a bad idea.

🗺️ Other Resources

📚 Books

Introduction to Algorithms
Programming Interviews Exposed
Cracking the Coding Interview
Beyond Cracking the Coding Interview

Videos

About

Data Structures & Algorithms

Resources

Stars

Watchers

Forks