Skip to content

david-castaneda/algorithms

Repository files navigation

Algorithms and data structures collected over time.

Python Examples

Algorithms

Concepts / Data Structures / Patterns

  • Big O
  • Arrays & Strings
  • Hashmaps & Hashsets
  • Two Pointers
  • Binary Search
  • Linked Search
  • Stacks & Queues
  • Sliding Window
  • Recursion
  • Trees
  • Heaps / Priority Queues
  • Backtracking
  • Graphs
  • Dynamic Programming

Cheat sheet

Common numbers

  • 26 - alphabet
  • 52 - alphabet capitalized

Java APIs

Task API Example Notes
Sort an array (ascending) Arrays.sort(...) int[] a = {3,1,2}; Arrays.sort(a); Primitives sort ascending. For objects, you can pass a Comparator.
Binary search in a sorted array Arrays.binarySearch(...) int i = Arrays.binarySearch(a, target); Array must be sorted. Returns index if found, otherwise -(insertionPoint) - 1.
Sort a string (lexicographic) toCharArray(), Arrays.sort(...), new String(...) char[] c = s.toCharArray(); Arrays.sort(c); String t = new String(c); Sorts by Unicode code point. Use s.toLowerCase() first if you want case-insensitive behavior.
Integer min/max value Integer.MIN_VALUE, Integer.MAX_VALUE int lo = Integer.MIN_VALUE, hi = Integer.MAX_VALUE; Useful as sentinels and bounds in algorithms.
Double infinity Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY double inf = Double.POSITIVE_INFINITY; Also: Double.isInfinite(x) to check.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors