Static arrays are contiguous blocks of memory with a fixed size.
Each element has an index, starting from 0.
Accessing or modifying elements by index is O(1) (constant time).
Checking if a value exists, inserting, or deleting (except at the end) takes O(n) time because you may need to scan or shift all elements.
Size can’t be changed after creation; insertions/deletions that require resizing or shifting are inefficient.
Dynamic Arrays (Python Lists):
Dynamic arrays can change size, unlike static arrays.
Usually implemented under the hood by using static arrays and resizing (copying to a larger static array when full).
Appending at the end is mostly O(1); when the underlying static array is full, resizing takes O(n), but it happens rarely enough that the average time (amortized) is still O(1).
Inserting or deleting anywhere except at the end requires shifting elements, which is O(n).
Most operations are efficient, but constantly resizing or inserting/deleting in the middle is less so.
Strings in Python:
They are similar to arrays, but are immutable (cannot be changed).
To modify them (like appending), you need to create a new string, which takes O(n).
Accessing an element by index is O(1).
Operations like insertion, deletion, or searching take O(n).
#np.fromiter()- create numpy array object from iterable object iterable= (a*a for a in range(8)) np_iterable= np.fromiter(iterable,dtype= float) print('np.fromiter() is:\n',np_iterable)
#np.arange()- return space value within given interval == np.arange([start, ]stop, [step, ]dtype=None) print('np.arange():\n',np.arange(1,20 ,2 ,dtype=int))
#np.linspace()- evenly spaced number over 2 limits == np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0) print('np.linspace:\n',np.linspace(3.5,10,3))
#np.empty()- create array with type and shape without value == np.empty(shape, dtype=float, order=’C’) print('np.empty() with order C:\n',np.empty([3,3],dtype= int, order='C')) print('np.empty() with order F:\n',np.empty([3,3],dtype= int, order='F'))
#np.ones()- create new array filled with ones print('np.ones() is:\n',np.ones([4,3],dtype=float))
#np.zeros()- create new array filled with zeros print('np.zeros() is:\n',np.zeros([4,3],dtype=float))
#copy array from another array org_array = np.array([1.54, 2.99, 3.42, 4.87, 6.94, 8.21, 7.65, 10.50, 77.5]) print('Copy array from another array:\n',np.copy(org_array)) Array traversal problems fall into 5 main categories:
Here is example for more details regarding Array and String.