Skip to content

ArraysΒΆ

Arrays are fundamental data structures used to store elements in contiguous memory locations.

CharacteristicsΒΆ

  • Fast index-based access (constant time)
  • Static size (fixed at creation time)
  • Elements must be of the same type (in many languages)
  • Memory efficient for random access operations

Common OperationsΒΆ

Operation Description Time Complexity
Access Retrieve element at index O(1)
Insert Add element at specific position O(n)
Delete Remove element at specific position O(n)
Search Find element by value O(n)
Update Change value at specified index O(1)

Visual RepresentationΒΆ

β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”
β”‚ 10 β”‚ 20 β”‚ 30 β”‚ 40 β”‚ 50 β”‚
β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”˜
  0    1    2    3    4    ← Indices

ImplementationΒΆ

Python's Array class provides an implementation with fixed capacity and common array operations.

# Example usage:
arr = Array(5)  # Create array with capacity 5
arr.insert_at(0, 10)
arr.insert_at(1, 20)
element = arr.get(0)  # Returns 10

ApplicationsΒΆ

  • Storing and accessing sequential data
  • Matrix operations
  • Lookup tables and hash tables
  • Image processing
  • Buffer implementations

Example NotebookΒΆ

πŸ‘‰ See Array Example Notebook