terminal

codeando_simple

terminal

menu

terminal

search_module

guest@codeandosimple: ~/system/search $ grep -r "" .

Press [ENTER] to execute search

Status

Engine: Ready

Database: Online

Index: V2.1.0_LATEST

bash -- cat logica-arrays.md
guest@codeandosimple: ~/blog/logic $ cat arrays.md

Logic - Arrays_

// "Skill is only developed with hours and hours of work" - Usain Bolt

In this article, we are going to look at ARRAYS - VECTORS - MATRICES, a structure that allows us to store a set of elements. Discover how to use these powerful tools to manipulate groups of data efficiently.

Video thumbnail

# Arrays

An array is a structure that stores a fixed number of elements, all identified with the same name. Generally, we must specify the number of elements at the time of creation.

Conceptual diagram of arrays

# One Dimension: Vector

The vector is the simplest array. It has N elements, identified with indices from 0 to N-1.

Structure of a vector

// Technical definition:

data_type name[N]

Example: INTEGER numbers[3] (Indices: 0, 1, 2)

# Initialization and Traversal

Vector loaded with data

To process large volumes of data, we traverse the vector sequentially using cyclic structures:

Vector traversal

# Length Property

Most languages provide the length property to know the size of the vector, avoiding "hardcoding" values in the code.

FOR index = 0 TO myvector.length - 1
    myvector[index] = 0

# Two Dimensions: Matrix

Visually it is like a chessboard or an Excel sheet. It is accessed using two indices: [row, column].

Matrix representation

Row-wise traversal vs Column-wise traversal:

Row-wise traversal

# Practice Exercises

In the next article, we will see records, a tool that proposes encapsulating data within a variable.

Resources used