• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 6 pages
Other

Multi-Dimensional Arrays: Concepts and Applications

Document preview thumbnail
Preview 2 out of 6 pages

This document explains multi-dimensional arrays, focusing on 2D arrays, 3D arrays, and higher dimensions. Learn how to perform operations like indexing, sorting, and searching in multi-dimensional arrays with practical examples.

Content preview

Multi-Dimensional Arrays
1. Definition
A multi-dimensional array is an array of arrays, where each element of the main
array can itself be an array. It allows you to store data in a table-like structure (2D
array) or even in a higher-dimensional structure (3D, 4D, etc.).

For example:

 A 2D array represents a matrix, where each element is accessed using two
indices: one for the row and one for the column.
 A 3D array represents a cube of data, where you need three indices to
access an element.



2. Two-Dimensional Arrays (2D Arrays)
A 2D array is an array of arrays, commonly used to represent a matrix (a table
with rows and columns). It can be thought of as a grid where each element is
accessible via two indices: one for the row and one for the column.

Declaration and Initialization (Example in Different Languages)
 C/C++: In C and C++, a 2D array is declared with two indices.

int arr[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};

 Java: In Java, 2D arrays are objects and are accessed in a similar way.

int[][] arr = {
{1, 2, 3},
{4, 5, 6},

, {7, 8, 9}
};

 Python: Python doesn't have a built-in 2D array, but you can use lists to
create a 2D structure.

arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]

 JavaScript: JavaScript arrays can hold arrays as elements, so a 2D array is
created similarly.

let arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];

Accessing Elements
To access elements in a 2D array, you use two indices (row and column).

 C/C++:

int value = arr[1][2]; // Access the element at row 1, column 2 (value 6)

 Python:

value = arr[1][2] # Access the element at row 1, column 2 (value 6)

 JavaScript:

let value = arr[1][2]; // Access the element at row 1, column 2 (value 6)

Document information

Uploaded on
January 28, 2025
Number of pages
6
Written in
2024/2025
Type
Other
Person
Unknown
$5.39

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
252
Last sold
-




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions