Data Structures

Table of contents

  1. Algos and Data Structs for noobs
    1. Arrays
      1. Static Arrays
      2. Dyanamics Arrays

Algos and Data Structs for noobs

Arrays

Static Arrays

Static typed languages: Java, C++, C# (meaning the arrays will need allocated size and type when the array is created)

  1. Properties of static arrays
    • when array is full = no additional element can be added
    • Javascript and Python DO NOT have static arrays
  2. Reading from arrays

A = [1,2,3]
A[i] 

Each element occupies 4 address 1 -> $0 , 1 -> $4 , 1 -> $8

Accessing single element from array is instant Due to the fact that the location of the element stored is MAPPED to an address in RAM. Hence O(1) time complexity.

O(1) is when the number of operations doesn’t grow even when size of data/ input grows

  1. Looping through arrays
[A[element] for element in A]

'''
if A is size 10, then it performs 10 operations
if A is size 69, then it performs 69 operations (during the loop)
'''

  1. Deleting end of array

soft delete = setting the end of array to 0/null/-1. Not really deleting but overwriting it with the new value. This will also reduce the length by 1

  1. Deleting the i-th array

Dyanamics Arrays


Table of contents