Time Complexities
The table below provides an overview of time complexities for various data structures, algorithms, and library functions in popular languages.
Code | Time Complexity | Space Complexity | Language | Comment |
---|---|---|---|---|
strlen() |
~ |
C/C++ | Found in string.h , returns the length of a string. | |
push() |
~ |
JavaScript | Array method, adds a new element to the end of an array. | |
pop() |
~ |
JavaScript | Array method, deletes the last element in an array. | |
shift() |
~ |
JavaScript | Array method, deletes the first element in an array. | |
unshift() |
~ |
JavaScript | Array method, adds one or more elements at the beginning of an array. | |
splice() |
~ |
JavaScript | Removes, adds, or replaces a new element by index (note: not a very well designed library function; code bases using splice tend to be buggy). | |
sort() |
~ |
JavaScript | Modifies the array by calling a compare function. If the compare function is not provided, the default order is by Unicode value. | |
concat() |
~ |
JavaScript | Creates a new array by merging two or more arrays. | |
slice() |
~ |
JavaScript | Returns a copy of a sub-array between two indices, the start and the end. | |
indexOf() |
~ |
JavaScript | Array method, returns the first index of the argument if found, otherwise returns -1 . | |
forEach() |
~ |
JavaScript | Array method, executes a function for each array element. | |
for...of |
~ |
JavaScript | Object method, iterates over an object's keys. | |
map() |
~ |
JavaScript | Array method, creates a new array composed of the result of calling callback function argument on each array element. | |
filter() |
~ |
JavaScript | Array method, creates a new array composed of elements that return the call back function true. | |
reduce() |
~ |
JavaScript | Object array method, returns a single value from applying the reduction function for each element. | |
... (JavaScript spread syntax) |
~ |
JavaScript | Expands an array or object into its individual elements or key-value pairs. Frequently used within the reduce() method, leading to a time complexity of |