efficient array algorithms