Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Array Data Structure | List and Array
Algorithms and Data Structures Overview
course content

Contenido del Curso

Algorithms and Data Structures Overview

Algorithms and Data Structures Overview

1. Introduction to ADS
2. List and Array
3. Advanced Data Structures
4. Graphs

Array Data Structure

An array is a fundamental data structure in computer science used to store a collection of elements, such as numbers, characters, or objects, of the same data type. Arrays offer a way to organize and access data efficiently by storing elements in contiguous memory locations and providing indexed access to each element.

Each element can be accessed using its index in an array. Since computers operate with memory addresses, knowing the index of an element allows us to calculate its address using the following formula:
begin_of_array_address + index_of_element * size_of_element.

  • begin_of_array_address: This represents the memory address of the beginning of the array. It indicates the starting point in memory where the array is stored;
  • index_of_element: This variable represents the index or position of the element we are interested in within the array. It denotes the element's location relative to the array's beginning;
  • size_of_element: This variable signifies the size or length of each element in the array, typically measured in bytes. It indicates the amount of memory occupied by each element in the array.

The time complexity of this operation is O(1), and this is the main feature of arrays that if we know the index, we can access the given element in contrast time.

In Python, real arrays aren't implemented natively. To use this data structure we have to import NumPy library:

123456789101112
import numpy as np from lolviz import * # Assuming this library is for visualization of Python objects from IPython.display import display_png # Importing display_png function for displaying PNG images # Generate a random array of integers between 0 and 100 with a size of 10 real_array = np.random.randint(0, 100, size=(10)) # Print the data type of the array values print("Array data type is: ", real_array.dtype) # Display a visual representation of the array using the objviz function from the lolviz library display_png(objviz(real_array))
copy

An array can store different types of objects.

Selecciona la respuesta correcta

¿Todo estuvo claro?

Sección 2. Capítulo 1
We're sorry to hear that something went wrong. What happened?
some-alt