Selenium Data Structures & Algorithms 3 ā Questions and Answers
Question 1: A Selenium page object stores element locators as key-value pairs where keys are strings and lookups must be O(1). Which structure is ideal?
- Array
- LinkedList
- HashMap (Correct answer)
- Stack
Correct answer: HashMap
HashMap provides O(1) average-time key-based lookup using hashing, ideal for locator storage.
Question 2: In Selenium Grid, test jobs are dispatched to nodes in the order they arrive. Which data structure models this dispatch queue?
- Stack
- FIFO Queue (Correct answer)
- Priority Queue
- Binary Heap
Correct answer: FIFO Queue
A FIFO Queue processes requests in the order they arrive, matching Selenium Grid's job dispatching behavior.
Question 3: Which traversal of a DOM-like tree structure visits a node before its children, useful for Selenium page hierarchy parsing?
- In-order
- Post-order
- Pre-order (Correct answer)
- Level-order
Correct answer: Pre-order
Pre-order traversal visits the current node first, then recursively visits left and right subtrees, matching top-down DOM parsing.
Question 4: What worst-case time complexity does QuickSort have, and when does it occur?
- O(n log n) on sorted input
- O(n²) on already-sorted or reverse-sorted input (Correct answer)
- O(n) on random input
- O(log n) on any input
Correct answer: O(n²) on already-sorted or reverse-sorted input
QuickSort degrades to O(n²) when the pivot is always the smallest or largest element, as in sorted or reverse-sorted arrays.
Question 5: A Selenium test suite tracks parent-child test dependencies. Which data structure best represents these relationships?
- Array
- Stack
- Directed Acyclic Graph (DAG) (Correct answer)
- Circular Queue
Correct answer: Directed Acyclic Graph (DAG)
A DAG represents dependency relationships without cycles, accurately modeling test prerequisites.
Question 6: Which algorithm would you use to find the shortest test execution path through a Selenium test dependency graph?
- Depth First Search
- Breadth First Search
- Dijkstra's Algorithm (Correct answer)
- Binary Search
Correct answer: Dijkstra's Algorithm
Dijkstra's Algorithm finds the shortest weighted path between nodes, suitable for optimizing test execution order with costs.
Question 7: When flattening a nested list of Selenium test parameters into a single list, which algorithmic technique is most naturally applied?
- Dynamic Programming
- Greedy Algorithm
- Recursion (Correct answer)
- Binary Search
Correct answer: Recursion
Recursion naturally handles nested structures by processing each level and returning flattened sublists up the call stack.
A Selenium page object stores element locators as key-value pairs where keys are strings and lookups must be O(1).
Which structure is ideal?