added toArray() time complexity