CP

Naming Convention

Maintaining a consistent naming system is key to optimizing solving time. Some benefits include:

  • reduced overhead
  • reduced confusion
  • chunking

Below is the naming convention I use for commonly used variables

  • e.g. I always call my arrays/lists, A, 99% of the time so I never have to think about what my array is called because it will always, most certainly, be A.
variable namedescription
Aarray
vvalue in an array
n, sizearray size
Mmatrix
mnumber of row in a matrix
nnumber of columns in a matrix
i, jindices to element M[i][j]
y, xindices to element M[y][x]
ii, jjneighbors of (i, j)
dy, dxchange in y and change in x
#character used to mark visited elements in matrix
offsetsstores changes in (dy, dx)
Ggraph
a, bedge a and b
neineighbor of a graph node
qqueue
heap, hheap
d, hmdictionary
stackstack
left, rightleft and right pointers
midmiddle
prefix, suffixprefix/suffix sum/product or values
head, tail, dummypointer to a list node
tmptemporary variable
ccharacter in string
s, estart, end
ps, peprevious start, previous end
slow, fastslow, fast pointers
preprevious list node
curcurrent list node
nxtnext list node
p, q, nodepointer to tree nodes
ufunion find
visitedvisited elements
seenseen elements
haveelements that are available for use
dp, cache, memodynamic programming, caching computed values
helper(), fn()helper functions
dfs(), bfs()depth/breadth first search
dft(), bft()depth/breadth first traversal
resultresult