Cards (45)

  • What is an array in computer science?
    An ordered collection
  • In an array, elements are arranged in a specific sequence
  • What is a requirement for the data type of elements in an array?
    Must be the same
  • Elements in an array can be accessed directly using their numerical index.
  • Array elements are the individual values
  • Where are array elements stored in memory?
    Contiguously
  • All elements in an array must be of the same data type.
  • What is the typical starting index of an array?
    0
  • What is the syntax for accessing an array element in most programming languages?
    arrayName[index]arrayName[index]
  • Steps for initializing an array
    1️⃣ Declare the array
    2️⃣ Allocate memory for the array
    3️⃣ Assign initial values to elements
  • Static initialization assigns values at the time of declaration.
  • In dynamic initialization, values are assigned during program execution
  • What are common operations performed on arrays?
    Adding, updating, deleting
  • Adding an element to a full array may require resizing, which has a time complexity of O(n)O(n).
  • What are common array operations?
    Adding, updating, deleting, searching
  • Inserting an element into an array may require resizing
  • Adding an element to an array has a time complexity of O(1)O(1) on average.
  • The time complexity for adding to an array when resizing is needed is O(n)</latex>
  • What does updating an array element involve?
    Modifying its value
  • Updating an array element has a time complexity of O(1)O(1).
  • Deleting an element from an array may involve shifting other elements
  • Deleting an element from an array has a time complexity of O(n)O(n) due to shifting elements.
  • What is the purpose of searching in an array?
    Locating a specific element
  • The time complexity for searching in an array using linear search is O(n)O(n)
  • What are array elements defined as?
    Individual values stored in an array
  • Array elements are stored randomly in memory.
    False
  • Array elements are accessed using their numerical index
  • What is a key constraint regarding the data type of array elements?
    All elements must be of the same type
  • Array indexing begins at 1.
    False
  • Array indexing involves accessing elements using their position
  • What is the syntax for array indexing?
    arrayName[index]</latex>
  • What are the two main methods of array initialization?
    Static and dynamic
  • Static initialization assigns values at the time of declaration
  • Dynamic initialization assigns values during program execution.
  • What is the syntax for static initialization in C++?
    \int numbers[] = {10, 20, 30};</latex>
  • Match the array operation with its description:
    Adding ↔️ Inserts an element into the array
    Updating ↔️ Modifies an existing element
    Deleting ↔️ Removes an element from the array
    Searching ↔️ Locates a specific element
  • Adding an element to an array always takes O(1)O(1) complexity.

    False
  • What is the time complexity of updating an array element?
    O(1)O(1)
  • Deleting an element from an array requires shifting other elements, resulting in a time complexity of O(n)O(n)
  • What is the time complexity of searching for an element in an array?
    O(n)O(n)