Skip to content

UPEISMCSCCC/Code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code

This repo contains various bits of code that can be used for competitive programming. Some relatively difficult problems can only be solved using these data structures or algorithms. Readability is a concern, but reducing lines of code is prioritized for use in cheat sheets / team notebooks.

C++ is the default language used here. This choice here is that C++ is usually the fastest language in common use for competitive programming, and that usually C++ can be translated into other languages while the opposite is not necessarily true. Sometimes unique features of C++ is used, but generally it can be converted to other languages without much hassle.

Included is an ICPC style team notebook using the snippets, as well as some benchmarks and test cases for the snippets.

How to Contribute

  • create new snippets
  • improve existing snippets
  • write tests for existing snippets
  • add links to problems solvable by snippets
  • benchmark snippets against other methods

Information

Algorithms

  • Binary Search - Find the position of a target value within a sorted array.
  • Golden Section Search - Find the minima or maxima of a function inside an interval.
  • Min/Max Subarray - Find the maximum subarray given an array of integers. Same with minimum subarray.
  • QuickSelect - Search for an element in an unsorted array, similar to a binary search but without the sorted restriction. Effectively performs quicksort, but only on the relevant subsections of the array. This does swap elements within the array and will alter the array's ordering.
  • Saddleback Search - Given a 2D array sorted on both axis, find if a value exists and return its location.
  • Ternary Search - Given a function, search for the minimum or maximum (or any other unimodal function) of a range. Will do so in O(log3 n) where n is the range being used.

Data Structures

  • Fenwick Tree - efficient structure for keeping track of and updating cumulative sums. Updates sums in O(log n)
  • Hash Table - faster version of std::unordered_map
  • Ordered Set - version of std::set with array-like access methods, including map variant
  • Rope - version of string, optimized for insertions/deletions at arbitrary points within the string.
  • Segment Tree - A tree for storing intervals, and allows for quick queries to find which interval contains a given point.
  • Sparse Table - Fast lookups for range min/max queries.
  • Trie - prefix tree, or a tree that stores strings based on common prefixes.
  • Wavelet Tree - Store strings or suffix arrays in a compressed way

Graph

  • Dijkstra's Algorithm - Find the shortest path between two nodes in a graph.
  • Eulerian Path - Find a path that visits each node exactly once, if it exists.
  • Floyd Warshall - all-pairs shortest path / transitive closure / negative cycle detection.
  • Grid Shortcuts - utilities to make grid problems easier to tackle
  • Minimum Spanning Tree - Primm's algorithm for generating the minimum spanning tree of a given graph and its weight
  • Union Find - determine subsets that nodes belong to

Math

String

  • Number Converter - convert an integer into its english equivalent
  • Find Substrings - algorithms for finding occurences of a substring within a larger string
    • Aho-Corasick - search for multiple patterns/keywords at once, using automata
    • Boyer-Moore - suited for larger sets like english text, slightly less common than kmp
    • Knuth-Morris-Pratt - suited for small sets like numbers / DNA, common and popular substring search algorithm for competitive programming
  • Longest Common Prefix - sort-based method of determining the longest prefix shared among all elements in an array
  • Longest Common Subsequence - dynamic programming solution for finding the longest subsequence shared between two strings
  • Longest Palindrome Substring - Manacher's algorithm for finding the palindrome length of every substring of a given string
  • Subsequence Count - dynamic programming solution for counting the number of times a string appears as a subsequence in a larger string

2D Geometry

3D Geometry

  • Basics - basic declarations of various shapes and methods

About

Code snippets and common structures

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •