What is the worst-case runtime complexity of the following …
What is the worst-case runtime complexity of the following addPassword() method, assuming that the problem size N represents the number of elements stored in the array passwords provided as input? /** * Adds a new password to the end of a list of passwords defined by the oversize array (passwords, size) * @param passwords an oversize array which stores a set of users’ passwords * @param size number of elements stored in the array passwords * @param password to add * @return the new size of the list of users’ passwords after adding a new password */ public static int addPassword(String[] passwords, int size, String password) { for(int i = 0; i < passwords.length; i++) { if(passwords[i] == null) { passwords[i] = password; size++; break; } } return size; }
Read Details