What is the difference between one-dimensional and two-dimensional matrix?

Asked

Viewed 4,632 times

3

In high school we usually study about the concept of Matrix, which consists of a row table and columns forming a set of numbers or elements.

In mathematics, programming and other areas we use Matrices so I would like to know the difference between one-dimensional and two-dimensional matrix?

How to declare a one-dimensional and a two-dimensional matrix?

I would like examples in some languages, e.g.: java, php, c++ if possible.

3 answers

7

One-dimensional matrix has only one dimension. It is also called a vector. In pseudolanguage:

var vetor = inteiro[10];

In Java:

int[] vetor = new int[10];

In C++:

int vetor[10];

Two-dimensional matrix has two dimensions. In pseudolanguage:

var matriz = inteiro[10, 10];

In Java:

int[][] vetor = new int[10][10];

In C++:

int vetor[10][10];
  • 3

    You do not ask this in your question. The answer answers what has been asked. If you need more details, put this clearly in your question.

4

One-dimensional matrix, also treated as "vector", stores data sequentially, and each data is stored and retrieved by means of an integer representing its "position" in this "row". By representing a "straight line", it can be said that the data is stored in a single dimension.

The statement will depend on the language, usually:

Dim Vetor(15)

In this example, a vector (named "Vector") was created that has 16 elements (distinct data), because every vector starts from 0 (zero).

The two-dimensional matrix stores data by means of two integers, which represent the "position" of each data in the matrix, as in a Cartesian axis where, for example, one can consider points to values of integers and positives (including zeros). Thus, each pair of values indicates a distinct datum. As they represent two axes, which form a "plane" (x and y in geometry), it represents values in two dimensions.

Usually the statement would be:

Dim Matriz(5; 4)

In this example, a matrix (named "Matrix") was created that has 30 elements (distinct data), because since the values 0 (zero) must be considered, the amount of items that this matrix can store is calculated by: 6 X 5 = 30.

2

Well the answers are above, I just wanted to put a drawing I think will contribute to understanding.

Imagine I’m wanting to store people’s data.

One-dimensional matrix:

João | Vitor | Pedro | Adriana

As you can see above it would be difficult to store the age, gender, etc of the same person, because I only have one row in the matrix. The two-dimensional matrix solves this too, because now every row of the matrix will have data from one person.

Two-dimensional matrix:

So it stays that way:

João | 18 | Masculino | Desenvolvedor

Vitor | 22 | Masculino | Analista

Pedro | 35 | Masculino | Arquiteto

Adriana | 24 | Feminino | Web Design

The difference is that the one-dimensional matrix has only one dimension, only one line.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.