6.1 One-Dimensional Arrays

Cards (43)

  • What is a one-dimensional array?
    Contiguous sequence of elements
  • In Java, array indices start at 1.
    False
  • How do you assign a value to an element in a one-dimensional array using its index?
    arrayName[index]=arrayName[index] =value; value;
  • A two-dimensional array has a contiguous rectangular storage layout.
  • To initialize a one-dimensional array, you can assign values using the array index.
  • One-dimensional arrays store elements in a single row.

    True
  • One-dimensional arrays can store elements of different data types.
    False
  • Two-dimensional arrays use a single index to access elements.
    False
  • What is a one-dimensional array?
    Contiguous sequence of elements
  • How do you access an array element using its index?
    Array name followed by index
  • What is an alternative way to initialize a one-dimensional array directly in Java, without using individual indices?
    dataType[]arrayName=dataType[] arrayName =value1,value2,value3,...; {value1, value2, value3, ...};
  • In Java, array indices start at 0
  • What is the time complexity typically associated with sorting algorithms for arrays?
    O(nlogn)O(n \log n)
  • What does it mean for arrays in Java to be passed by reference when used as function parameters?
    Changes modify the original array
  • The memory layout of a one-dimensional array is linear storage.
  • How do you assign the value 10 to the first element of the 'numbers' array in Java?
    numbers[0]=numbers[0] =10; 10;
  • One-dimensional arrays have a rectangular memory layout.
    False
  • How do you declare a one-dimensional array of strings named 'names' with a size of 3 in Java?
    String[] names = new String[3];</latex>
  • How do you declare a one-dimensional array in Java, specifying the data type and array size?
    \text{dataType[] arrayName = new dataType[size];}
  • What does the array index refer to?
    Position of an element
  • How do you traverse a one-dimensional array in Java?
    Using a for loop
  • One-dimensional arrays have rows and columns like two-dimensional arrays.
    False
  • How do you declare a one-dimensional array in Java, including specifying the data type and size?
    dataType[]arrayName=dataType[] arrayName =newdataType[size]; new dataType[size];
  • One-dimensional arrays use a single index, while two-dimensional arrays use row and column indices.
    True
  • Steps to traverse a one-dimensional array using a for loop
    1️⃣ Initialize a for loop with the index starting at 0
    2️⃣ Set the loop condition to iterate until the array length
    3️⃣ Print or process each array element
  • What are common operations performed on arrays, such as searching, sorting, insertion, and deletion?
    Searching, sorting, insertion, deletion
  • Steps to insert a new element into a one-dimensional array
    1️⃣ Create a new array with increased size
    2️⃣ Copy elements before the insertion point
    3️⃣ Insert the new element at the specified index
    4️⃣ Copy remaining elements after the insertion point
  • When an array is modified within a function in Java, the changes are reflected in the original
  • Provide an example of declaring a one-dimensional array of 5 integers in Java.
    int[]numbers=int[] numbers =newint[5]; new int[5];
  • The general syntax for declaring a one-dimensional array in Java is dataType[] arrayName = new dataType[size];
  • What are the key differences between one-dimensional and two-dimensional arrays in terms of dimensions?
    Single row vs. rows and columns
  • You can initialize a one-dimensional array by directly assigning values during declaration.

    True
  • To initialize a one-dimensional array, you assign values to individual elements using the array index
  • What type of memory layout do one-dimensional arrays use?
    Contiguous linear storage
  • The array index starts from 0
  • Steps to traverse a one-dimensional array using a for loop
    1️⃣ Initialize a loop variable to 0
    2️⃣ Check if the loop variable is less than the array length
    3️⃣ Access the array element at the current index
    4️⃣ Increment the loop variable
    5️⃣ Repeat steps 2-4 until the loop variable is no longer less than the array length
  • Alternatively, you can initialize a one-dimensional array directly using curly braces: {value1, value2, value3, ...}
  • One way to initialize a one-dimensional array in Java is by using individual indices
  • How do you access an element in a one-dimensional array using its index?
    arrayName[index]arrayName[index]
  • Traversing a one-dimensional array requires a single loop, while traversing a two-dimensional array requires nested loops.

    True