emily592
emily592 4h ago • 0 views

Multiple Choice Questions on Data Storage Using Arrays and Lists

Hey there, future coders! 👋 Ready to test your knowledge of data storage with arrays and lists? 🤔 Let's dive into a quick study guide and then challenge ourselves with a practice quiz! Good luck!
💻 Computer Science & Technology

1 Answers

✅ Best Answer

📚 Quick Study Guide

  • 💾 Arrays: Arrays store elements of the same data type in contiguous memory locations. They have a fixed size, meaning you need to define the size when you create them. Accessing elements is very fast using their index.
  • Lists: Lists (like ArrayList in Java or lists in Python) are dynamic in size. They can grow or shrink as you add or remove elements. They don't require contiguous memory allocation, offering more flexibility.
  • ⏱️ Time Complexity (Arrays): Accessing an element: $O(1)$. Insertion/Deletion (at the beginning): $O(n)$. Insertion/Deletion (at the end): $O(1)$.
  • ⏱️ Time Complexity (Lists): Accessing an element: $O(n)$. Insertion/Deletion (at the beginning): $O(n)$. Insertion/Deletion (at the end): $O(1)$ (amortized).
  • 💡 When to use Arrays: When you know the size of the data beforehand, and you need fast access to elements.
  • 🧪 When to use Lists: When you don't know the size beforehand, and you need the flexibility to add/remove elements easily.
  • ↔️ Trade-offs: Arrays offer speed but lack flexibility. Lists offer flexibility but can be slower for certain operations.

❓ Practice Quiz

  1. Which of the following data structures has a fixed size?
    1. Array
    2. List
    3. Set
    4. Dictionary
  2. What is the time complexity to access an element in an array by its index?
    1. $O(n)$
    2. $O(log n)$
    3. $O(1)$
    4. $O(n^2)$
  3. Which data structure allows you to dynamically add or remove elements without specifying the size in advance?
    1. Array
    2. Tuple
    3. List
    4. String
  4. What is the typical time complexity to insert an element at the beginning of an array?
    1. $O(1)$
    2. $O(log n)$
    3. $O(n)$
    4. $O(n log n)$
  5. In terms of memory allocation, how are elements stored in an array?
    1. Randomly
    2. Non-contiguously
    3. Contiguously
    4. Based on a hash function
  6. Which of the following is NOT an advantage of using lists over arrays?
    1. Dynamic resizing
    2. Easier insertion/deletion
    3. Faster access to elements by index
    4. Flexibility in memory allocation
  7. Which of the following scenarios is best suited for using an array instead of a list?
    1. Storing a constantly changing to-do list
    2. Storing the scores of a game, where the number of players is known in advance
    3. Storing a collection of unique items
    4. Storing email addresses
Click to see Answers
  1. A
  2. C
  3. C
  4. C
  5. C
  6. C
  7. B

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀