Tuples, Arrays and Lists

Cards (19)

  • What does contiguous mean?

    • means all the data stored together, one element after the other
  • What is an array?
    • a data structure that can contain many elements of the same data type
  • What is a record
    a collection of related fields. A field is a variable, and each field in a record can have a different data type
  • What is a list
    a one-dimensional data structure that can store more than one data type
  • How can an array be defined?
    As a variable containing multiple data items
  • What is the memory allocation for arrays?
    Arrays store data contiguously in memory
  • What is the difference between lists and arrays in Python?
    Lists are not contiguous, arrays are
  • What is a record data structure?
    A collection of related fields
  • What is the difference between lists and tuples in Python?
    Lists are mutable, tuples are immutable
  • How do you add an item to a list in Python?
    Use the append method
  • What happens if you try to change a tuple in Python?
    An error occurs due to immutability
  • What are the key differences between arrays, lists, and tuples?
    • Arrays: Contiguous, static size, single data type
    • Lists: Non-contiguous, dynamic size, mutable
    • Tuples: Non-contiguous, fixed size, immutable
  • What are the characteristics of a record data structure?
    • Collection of related fields
    • Each field can have different data types
    • Used to group related variables
  • Static structure
    structure size cannot change at runtime
  • Dynamic structure
    structure size can change at runtime
  • Advantages of a static data structure:
    • Memory allocation is fixed, which means there will be no issue with adding and removing items for a data structure
    • Easier to program, as there is no need to check the size of the data structure at any point before accessing it
  • Disadvantages of a static data structure
    • Can be very inefficient as memory for the data structure is set aside at the start of the program but might not be utilised
  • Advantage of a dynamic data structure
    • Makes efficient use of memory because the data structure only uses as much memory as it needs
  • Disadvantages of a dynamic data structure:
    • Overflow can occur if it exceeds its allowed limit as well as undeflow if it is empty