HomeSubjectsUniversityBlogAbout

Arrays & Collections

Topic in Programming

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

An array is a fixed-size, indexed sequence of same-type elements, while collections are library structures such as lists, sets, maps and queues. MCQs test zero-based indexing, bounds errors, multidimensional arrays and iterating with loops or iterators. Comparisons between arrays and linked lists focus on contiguous memory, random access and insertion cost. You should know the amortised O(1) append of dynamic arrays like ArrayList, how hash maps and sets handle duplicates, and shallow versus deep copies. Advanced items describe probabilistic and specialised structures, including Bloom filters, treaps and consistent hashing for spreading keys across servers.

Below are 30 practice questions from a pool of 210 Arrays & Collections MCQs, one of 16 topics in Programming. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.

Practice Questions

Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.

Arrays & CollectionsEasy

Q1. What is a list in Python?

  1. A.A dictionary mapping keys to their associated values
  2. B.An immutable sequence that cannot be modified at all
  3. C.A fixed-size array of uniform typed elements
  4. D.An ordered mutable collection of any element types✓ Correct

Explanation

A Python list is an ordered, mutable collection that can store elements of any type and dynamically resize.

Report an error in this question

Arrays & CollectionsEasy

Q2. What is an array?

  1. A.A loop construct that iterates over data elements
  2. B.A collection of same-type elements in contiguous memory✓ Correct
  3. C.A reusable function that performs a specific task
  4. D.A single variable holding one data value

Explanation

An array stores a fixed-size collection of elements of the same type in contiguous memory locations.

Report an error in this question

Arrays & CollectionsEasy

Q3. What is an ArrayList in Java?

  1. A.A doubly linked list of elements
  2. B.A key-value pair mapping structure
  3. C.A fixed-size array that cannot change
  4. D.A dynamic array that grows and shrinks✓ Correct

Explanation

ArrayList is a resizable array implementation of the List interface that automatically manages its size.

Report an error in this question

Arrays & CollectionsEasy

Q4. What is the index of the first element in an array in C/Java?

  1. A.0✓ Correct
  2. B.-1
  3. C.2
  4. D.1

Explanation

In C and Java, array indexing starts at 0, so the first element is at index 0.

Report an error in this question

Arrays & CollectionsEasy

Q5. What happens when you access an array index out of bounds?

  1. A.It returns zero as the default value for any position
  2. B.It returns null as the default value for the position
  3. C.It throws an exception or causes undefined behavior✓ Correct
  4. D.It automatically resizes the array to fit the index

Explanation

Accessing an index outside the array's valid range causes an exception in managed languages or undefined behavior in C/C++.

Report an error in this question

Arrays & CollectionsEasy

Q6. What is a dictionary/map?

  1. A.An ordered array with indexed elements
  2. B.A list of words in alphabetical order
  3. C.A string type for storing text values
  4. D.A collection of key-value pair entries✓ Correct

Explanation

A dictionary/map stores data as key-value pairs, allowing efficient lookup by key.

Report an error in this question

Arrays & CollectionsMedium

Q7. What is the time complexity of accessing an element by index in an array?

  1. A.O(n^2)
  2. B.O(1)✓ Correct
  3. C.O(n)
  4. D.O(log n)

Explanation

Array access by index is O(1) because the memory address is calculated directly from the base address and index.

Report an error in this question

Arrays & CollectionsMedium

Q8. What is a tuple?

  1. A.A mutable list that can change its elements
  2. B.A key-value map for looking up data by key
  3. C.An immutable ordered collection of mixed types✓ Correct
  4. D.A sorted set that maintains element ordering

Explanation

A tuple is an immutable, ordered sequence of elements that can be of different types, used to group related values.

Report an error in this question

Arrays & CollectionsHard

Q9. What is a concurrent hash map?

  1. A.A hash map using multiple hash functions per key
  2. B.A thread-safe hash map without full map locking✓ Correct
  3. C.A distributed database across network nodes only
  4. D.A regular hash map with no special properties

Explanation

ConcurrentHashMap allows concurrent reads and partitioned writes without locking the entire structure.

Report an error in this question

Arrays & CollectionsHard

Q10. What is a lock-free data structure?

  1. A.An unprotected array that any thread can freely modify
  2. B.A concurrent structure using atomic operations not locks✓ Correct
  3. C.A structure with no synchronization protection at all
  4. D.A read-only data structure that cannot be changed ever

Explanation

Lock-free data structures use atomic operations (compare-and-swap) instead of locks, ensuring that at least one thread always makes progress.

Report an error in this question

Arrays & CollectionsEasy

Q11. What is the difference between an array and a linked list?

  1. A.Arrays can dynamically grow and shrink in size without any overhead
  2. B.Arrays use contiguous memory with O(1) access; linked lists use nodes✓ Correct
  3. C.They are functionally identical data structures with no differences
  4. D.Linked lists are always faster than arrays for every type of operation

Explanation

Arrays store elements contiguously enabling O(1) random access; linked lists use nodes connected by pointers enabling O(1) insertion/deletion but O(n) access.

Report an error in this question

Arrays & CollectionsMedium

Q12. What is a deque (double-ended queue)?

  1. A.A regular first-in first-out queue
  2. B.A queue allowing insertion at both ends✓ Correct
  3. C.A sorted list with binary search access
  4. D.A stack variant for ordered elements

Explanation

A deque supports insertion and removal of elements from both the front and the rear.

Report an error in this question

Arrays & CollectionsHard

Q13. What is a skip list?

  1. A.A filtered array that excludes elements matching a condition
  2. B.A probabilistic multi-layer linked list for O(log n) search✓ Correct
  3. C.A list that skips over certain elements during iteration
  4. D.A type of priority queue that maintains sorted element order

Explanation

A skip list uses multiple levels of forward pointers to skip over elements, providing O(log n) average search, insertion, and deletion.

Report an error in this question

Arrays & CollectionsHard

Q14. What is the difference between external and internal iterators?

  1. A.Internal iterators always consume more memory than external iterators
  2. B.External iterators are always faster than internal iterators in practice
  3. C.There is no meaningful difference between the two iterator types
  4. D.External iterators are client-controlled; internal are collection-controlled✓ Correct

Explanation

External iterators let the client control iteration; internal iterators let the collection control iteration by applying a function to each element.

Report an error in this question

Arrays & CollectionsHard

Q15. What is a disjoint set (union-find) data structure?

  1. A.A structure tracking element partitions with union and find✓ Correct
  2. B.A sorted set that maintains elements in order
  3. C.A hash set variant that uses separate chaining for entries
  4. D.A set that has no intersections with any other set at all

Explanation

Union-Find tracks elements partitioned into disjoint sets, supporting near O(1) union and find operations with path compression and union by rank.

Report an error in this question

Arrays & CollectionsMedium

Q16. What is the difference between a shallow copy and a deep copy of a collection?

  1. A.They are the same operation with identical results in every case
  2. B.Shallow copy shares element references; deep copy duplicates all✓ Correct
  3. C.Shallow copy is always slower than deep copy for all collections
  4. D.Deep copy shares references while shallow copy duplicates objects

Explanation

A shallow copy creates a new collection with references to the same objects; a deep copy recursively duplicates all nested objects.

Report an error in this question

Arrays & CollectionsHard

Q17. What is consistent hashing?

  1. A.A type of encryption used for securing sensitive data values
  2. B.A collision resolution method for hash table bucket overflow
  3. C.A hashing scheme that minimally redistributes keys on change✓ Correct
  4. D.Regular hashing with standard hash function methods

Explanation

Consistent hashing maps both keys and nodes onto a ring, so adding or removing a node only redistributes keys to/from adjacent nodes.

Report an error in this question

Arrays & CollectionsMedium

Q18. What is an iterator?

  1. A.An array index used for element access
  2. B.An object for traversing a collection sequentially✓ Correct
  3. C.A sorting algorithm for ordering collections
  4. D.A type of loop construct for repeating code

Explanation

An iterator provides a standard interface for traversing elements of a collection sequentially without exposing its internal structure.

Report an error in this question

Arrays & CollectionsEasy

Q19. What is a set in programming?

  1. A.A sorted array of ordered elements
  2. B.A specialized type of key-value map
  3. C.A collection with only unique elements✓ Correct
  4. D.An array that allows duplicate elements

Explanation

A set is a collection that contains no duplicate elements, useful for membership testing and removing duplicates.

Report an error in this question

Arrays & CollectionsMedium

Q20. What is a collision in a hash table?

  1. A.A runtime error in the hash function code
  2. B.When a requested key is not found in map
  3. C.When the hash table is completely full up
  4. D.When two keys hash to the same index slot✓ Correct

Explanation

A collision occurs when two different keys produce the same hash value, mapping to the same bucket.

Report an error in this question

Arrays & CollectionsHard

Q21. What is the amortized time complexity of adding an element to a dynamic array?

  1. A.O(1) amortized✓ Correct
  2. B.Always O(n)
  3. C.O(log n) each
  4. D.O(n log n) each

Explanation

While occasional resizing costs O(n), the cost is spread over many insertions, making the amortized cost O(1) per insertion.

Report an error in this question

Arrays & CollectionsEasy

Q22. What is a queue?

  1. A.A LIFO (Last-In First-Out) structure
  2. B.A sorted array with indexed elements
  3. C.A FIFO (First-In First-Out) structure✓ Correct
  4. D.A hierarchical tree data structure

Explanation

A queue is a FIFO data structure where the first element added is the first one removed.

Report an error in this question

Arrays & CollectionsHard

Q23. What is a bloom filter?

  1. A.A comparison-based sorting algorithm for arrays
  2. B.A space-efficient probabilistic set membership tester✓ Correct
  3. C.An image processing filter for visual enhancement
  4. D.A standard hash table with separate chaining buckets

Explanation

A bloom filter uses multiple hash functions and a bit array to test membership with possible false positives but no false negatives.

Report an error in this question

Arrays & CollectionsMedium

Q24. What is a priority queue?

  1. A.A sorted array with indexed element access only
  2. B.A queue where higher-priority elements dequeue first✓ Correct
  3. C.A stack with last-in first-out element ordering
  4. D.A regular first-in first-out queue structure

Explanation

A priority queue serves elements based on their priority rather than insertion order, typically implemented using a heap.

Report an error in this question

Arrays & CollectionsHard

Q25. What is a persistent data structure?

  1. A.An immutable structure that can never be accessed again
  2. B.A structure preserving previous versions on modification✓ Correct
  3. C.A relational database schema structure for queries
  4. D.A structure saved to persistent disk storage

Explanation

A persistent data structure retains all previous versions of itself when modified, enabling access to any historical state.

Report an error in this question

Arrays & CollectionsMedium

Q26. What is the difference between a singly linked list and a doubly linked list?

  1. A.Singly linked lists always use more memory than doubly linked
  2. B.There is no meaningful difference between the two list types
  3. C.Singly linked has next pointer; doubly linked has next and prev✓ Correct
  4. D.Doubly linked lists are always slower than singly linked lists

Explanation

A singly linked list node has a pointer to the next node; a doubly linked list node has pointers to both next and previous nodes.

Report an error in this question

Arrays & CollectionsEasy

Q27. What is a stack?

  1. A.A LIFO (Last-In First-Out) structure✓ Correct
  2. B.A sorted list of ordered elements
  3. C.A random access data structure
  4. D.A FIFO (First-In First-Out) structure

Explanation

A stack is a LIFO data structure where the last element added is the first one removed.

Report an error in this question

Arrays & CollectionsMedium

Q28. What is a hash table?

  1. A.A balanced binary tree for hierarchical storage
  2. B.A sorted array of ordered elements in memory
  3. C.A structure mapping keys to values via hashing✓ Correct
  4. D.A stack variant that allows random element access

Explanation

A hash table uses a hash function to compute an index into an array of buckets, enabling average O(1) lookup, insertion, and deletion.

Report an error in this question

Arrays & CollectionsMedium

Q29. What is the difference between HashMap and TreeMap in Java?

  1. A.They are exactly the same data structure implementation
  2. B.HashMap maintains the insertion order of all its entries
  3. C.TreeMap is always faster than HashMap for all operations
  4. D.HashMap is unordered O(1); TreeMap is sorted O(log n)✓ Correct

Explanation

HashMap uses hashing for O(1) average operations but no ordering; TreeMap uses a red-black tree for O(log n) operations with keys in sorted order.

Report an error in this question

Arrays & CollectionsHard

Q30. What is a B-tree and where is it commonly used?

  1. A.A self-balancing tree with multiple keys per node for databases✓ Correct
  2. B.A hash table variant that uses tree-based collision resolution
  3. C.A standard binary tree with two children per node
  4. D.A linked list type that organizes data in sequential node chains

Explanation

A B-tree is a self-balancing tree where nodes can have multiple keys and children, optimized for disk access and widely used in databases.

Report an error in this question

Ready to test yourself on Arrays & Collections?

Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.

Start Arrays & Collections Quiz