Skip to content

Instantly share code, notes, and snippets.

@MohamedK1
MohamedK1 / Runtime_Complexity.java
Last active July 11, 2018 03:25 — forked from psayre23/gist:c30a821239f4818b0709
Runtime Complexity of Java Collections
Below are the Big O performance of common functions of different Java Collections.
List | Add | Remove | Get | Contains | Next | Data Structure
---------------------|------|--------|------|----------|------|---------------
ArrayList | O(1) | O(n) | O(1) | O(n) | O(1) | Array
LinkedList | O(1) | O(1) | O(n) | O(n) | O(1) | Linked List
CopyOnWriteArrayList | O(n) | O(n) | O(1) | O(n) | O(1) | Array
@MohamedK1
MohamedK1 / ArrayListMerge.java
Created July 11, 2018 03:21 — forked from adrianlee/ArrayListMerge.java
An ArrayList, or a dynamically resizing array, is an array that resizes itself as needed while still providing O(1) access. A typical implementation is that when a vector is full, the array doubles in size. Each doubling takes O(n) time, but happens so rarely that its amortized time is still O(1).
/*
An ArrayList, or a dynamically resizing array, is an array that resizes itself as
needed while still providing O(1) access. A typical implementation is that when a
vector is full, the array doubles in size. Each doubling takes O(n) time, but
happens so rarely that its amortized time is still O(1).
public ArrayList<String> merge(String[] words, String[] more) {
ArrayList<String> sentence = new ArrayList<String>();
for (String w : words) sentence.add(w);
for (String w : more) sentence.add(w);