Which LINQ method is used to convert a Dictionary<K,V> to a List<T> of key-value pairs?
Answer: B
ToList() converts the Dictionary's KeyValuePair<K,V> enumeration into a List<KeyValuePair<K,V>>. ToArray() would create an array instead.
Q.282Easy
What is the space complexity of a HashSet<T> with n elements?
Answer: B
HashSet<T> requires O(n) space to store n unique elements in the underlying hash table structure.
Q.283Medium
In a data processing pipeline, if you need FIFO (First-In-First-Out) semantics with O(1) enqueue/dequeue, which collection is best?
Answer: C
Queue<T> provides FIFO semantics with O(1) Enqueue() and Dequeue() operations. Stack<T> is LIFO, and LinkedList operations vary.
Q.284Medium
Which collection maintains elements in sorted order and is backed by a binary search tree?
Answer: B
SortedDictionary<K,V> uses a red-black tree (binary search tree) for O(log n) operations. SortedSet<T> also uses BST but for single values.
Q.285Easy
What does the Peek() method do in a Stack<T>?
Answer: B
Peek() returns the top element without modifying the stack. Pop() removes and returns it. Peek() throws InvalidOperationException if the stack is empty.
Advertisement
Q.286Hard
In a real-time cache system with limited memory, which collection supports automatic eviction of least recently used items?
Answer: B
MemoryCache provides LRU-style eviction and memory management policies. Basic collections don't have built-in LRU functionality.
Q.287Medium
What is the time complexity of Contains() method in a HashSet<T>?
Answer: C
HashSet<T> uses hash-based lookup for Contains(), achieving O(1) average-case time complexity, with O(n) worst-case in case of hash collisions.
Q.288Hard
Which collection should be used when you need both indexed access and automatic sorting?
Answer: C
SortedList<K,V> maintains sorted order by keys and allows O(1) index-based access. SortedSet<T> doesn't support indexing.
Q.289Medium
In a scenario with frequent additions and removals at both ends, which collection is most efficient?
Answer: B
LinkedList<T> provides O(1) AddFirst(), AddLast(), RemoveFirst(), and RemoveLast() operations. List<T> requires O(n) for head removals due to reindexing.
Q.290Hard
In a high-concurrency distributed system, which collection from System.Collections.Concurrent is best for one-to-many relationships?
Answer: C
For one-to-many relationships with concurrent access, combining ConcurrentDictionary with ConcurrentBag (or List) provides thread-safe multi-value storage per key.