Declaration of Matrix Data Structure
Declaration of a Matrix or two-dimensional array is very much similar to that of a one-dimensional array, given as follows.
#include <iostream>
using namespace std;
int main()
{
// Defining number of rows and columns in matrix
int number_of_rows = 3, number_of_columns = 3;
// Array Declaration
int arr[number_of_rows][number_of_columns];
return 0;
}
#include <stdio.h>
int main() {
// Defining number of rows and columns in matrix
int number_of_rows = 3, number_of_columns = 3;
// Array Declaration
int arr[number_of_rows][number_of_columns];
return 0;
}
/*package whatever //do not write package name here */
import java.io.*;
class GFG {
public static void main(String[] args)
{
// Defining number of rows and columns in matrix
int number_of_rows = 3, number_of_columns = 3;
// Array Declaration
int[][] arr
= new int[number_of_rows][number_of_columns];
}
}
# Defining number of rows and columns in matrix
number_of_rows = 3
number_of_columns = 3
# Declaring a matrix of size 3 X 3, and initializing it with value zero
rows, cols = (3, 3)
arr = [[0]*cols]*rows
print(arr)
using System;
public class GFG {
static public void Main()
{
// Defining number of rows and columns in matrix
int number_of_rows = 3, number_of_columns = 3;
// Array Declaration
int[, ] arr
= new int[number_of_rows, number_of_columns];
}
}
// Defining number of rows and columns in matrix
number_of_rows = 3,
number_of_columns = 3;
// Declare a 2D array using array constructor
let arr = new Array(3);
// Python declaration
for (let i = 0; i < arr.length; i++) {
arr[i] = new Array(3); // Each row has 3 columns
}
Introduction to Matrix or Grid Data Structure – Two Dimensional Array
Matrix or Grid is a two-dimensional array mostly used in mathematical and scientific calculations. It is also considered as an array of arrays, where array at each index has the same size. In this article, we will cover all the basics of Matrix, the Operations on Matrix, its implementation, advantages, disadvantages which will help you solve all the problems based on Matrix Data Structure.
Table of Content
- What is a Matrix Data Structure?
- Representation of Matrix Data Structure
- Declaration of Matrix Data Structure
- Initializing Matrix Data Structure
- Operations on Matrix Data Structure
- Access elements of Matrix Data Structure
- Traversal of a Matrix Data Structure
- Searching in a Matrix Data Structure
- Sorting Matrix Data Structure
- Applications of Matrix Data Structure
- Advantages of Matrix Data Structure
- Disadvantages of Matrix Data Structure
- More Practice problems on Matrix Data Structure
Contact Us