# Data Structure

Data structure is way in which we store data and the relationship among them and the functions or operations that can be applied to. In this tutorial, we will see each data structure one by one. Will solve few problems for the same.

## Array

Array can be accessed with index based mechanism, where 0 pointing to first element and n-1 pointing to the last element, n being the size of array. Lets call this array as "myfirst", so myfirst of 0 will be 10, myfirst of 1 will be 11. Where 0 and 1 are index positions.

• Elements in array are stored sequentially.
• Element in array can be accessed randomly based on index.
• Array store similar type of value, either it will be number array, text array or object array etc.

### Time Complexity Now lets see how to create an array in java and python and access it's element.

` package com.gauraw.learning.array; /** * Example shows how to create an array and access its element randomly * @author gaurawkumarsingh * */public class Example1 {     public static void main(String ...ars) {         // one way of declaring         int [] myfirst = { 10, 11, 12, 13, 14, 15, 16, 17, 18};        System.out.println( "Value at first position ->"+myfirst);         // another way of creating array         int []test1 = new int;         for ( int i =0 ; i < test1.length ;i++) {            test1[i] = i;        }         System.out.println("The second error ");        for ( int i=0 ;i < test1.length ;i++) {            System.out.println(test1[i]);        }     }}`

Lets see now multi dimensional array

` package com.gauraw.learning.array; /** * Class help in  learning multi diemensinal array * @author gaurawkumarsingh * */public class Example2 {     public static void main(String ...strings ) {         /**         * Create an array of 2*3 where number of rows is 2 and number of columns is 3         */         int [][] multi = new int;         /**         * Insert element into multi dimensinal array         */         for ( int i =0 ;i < multi.length ; i++ )        {            for ( int j =0 ; j< multi[i].length ; j++) {                multi[i][j]= i+j;            }        }         /**         * Print multi diemensinal array         * Note how we are iterating the columns         */         for ( int i =0 ;i < multi.length; i++) {            for ( int j =0 ; j < multi[i].length;j++) {                System.out.print(multi[i][j]+" ");            }            System.out.println();        }    } }`

`package com.gauraw.learning.array; /** * Access Element based on index * @author gaurawkumarsingh * */public class Example3 {     public static void main(String ...strings) {         /**         * Create the array         */         int array[] = {1,2,3,4,5};         //Accessing the first element in array         System.out.println(array);     }}`