Selenium Data Structures & Algorithms 2 — Questions and Answers
Question 1: In Selenium test automation, which data structure is most efficient for storing a unique set of browser session IDs to avoid duplicate sessions?
- ArrayList
- HashSet (Correct answer)
- LinkedList
- TreeMap
Correct answer: HashSet
HashSet ensures uniqueness and provides O(1) average-time lookup, making it ideal for storing unique session IDs.
Question 2: You need to execute Selenium test cases in a specific priority order. Which data structure best supports this requirement?
- Stack
- Queue
- PriorityQueue (Correct answer)
- HashMap
Correct answer: PriorityQueue
A PriorityQueue dequeues elements based on their priority, allowing test cases to execute in the desired order.
Question 3: What is the time complexity of searching for an element in a balanced Binary Search Tree (BST)?
- O(1)
- O(log n) (Correct answer)
- O(n)
- O(n²)
Correct answer: O(log n)
In a balanced BST, each comparison halves the search space, resulting in O(log n) search time.
Question 4: A Selenium framework stores locators in a Map<String, By>. Which Map implementation maintains insertion order?
- HashMap
- TreeMap
- LinkedHashMap (Correct answer)
- ConcurrentHashMap
Correct answer: LinkedHashMap
LinkedHashMap maintains the order in which key-value pairs were inserted, unlike HashMap which offers no order guarantee.
Question 5: Which sorting algorithm is most efficient for nearly-sorted test result arrays in Selenium reporting?
- Quick Sort
- Merge Sort
- Insertion Sort (Correct answer)
- Heap Sort
Correct answer: Insertion Sort
Insertion Sort performs at O(n) on nearly-sorted data, making it optimal when the array is already mostly ordered.
Question 6: When implementing a Selenium test retry mechanism that processes failures in last-in-first-out order, which structure should you use?
- Queue
- Stack (Correct answer)
- Deque used as a queue
- LinkedList traversed forward
Correct answer: Stack
A Stack follows LIFO order, so the most recently failed test is retried first.
Question 7: What is the space complexity of Merge Sort?
- O(1)
- O(log n)
- O(n) (Correct answer)
- O(n log n)
Correct answer: O(n)
Merge Sort requires O(n) auxiliary space for the temporary arrays used during the merge step.
In Selenium test automation, which data structure is most efficient for storing a unique set of browser session IDs to avoid duplicate sessions?