












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













a b c d e
a b c d e
d e a b c
a b c d e
a g b c d e
Increasing Array Length Length of array element[] is 6. a b c d e f newArray = new Object[15]; First create a new and larger array
Increasing Array Length Now copy elements from old array to new one. a b c d e f a b c d e f
public static Object [] changeLength(Object [] a, int newLength) { Object [] newArray = new Object [newLength]; System.arrayCopy(โฆ); return newArray; } Integer [] a = new Integer [10]; โฆ. a = (Integer []) changeLength(a, 100); // erroneous
Space Complexity newArray = new char[7]; space needed = 2 * newLength โ 1 = 2 * maxListSize โ 1 element[6] a b c d e f
Array Doubling Double the array length. a b c d e f newArray = new char[12]; a b c d e f Time for n adds goes up by Theta(n). Space needed = 1.5newLength. Space needed <= 3maxListSize โ 3
How Big Should The New Array Be? Resizing by an additive constant c requires at most (maxListSize โ 1) + (maxListSize โ 1 + c) = 2 * (maxListSize โ 1) + c space. Resizing by any constant factor new length = c * old length requires at most (1+c) * (maxListSize -1) space_._