Postman collection organization in Rest API - Time & Space Complexity
When organizing Postman collections, it's important to understand how the time to find or run requests grows as the collection gets bigger.
We want to know how the effort changes when we add more requests or folders.
Analyze the time complexity of searching for a request in a Postman collection organized with folders and requests.
// Pseudocode for searching a request by name in a Postman collection
function findRequest(collection, name) {
for (const folder of collection.folders) {
for (const request of folder.requests) {
if (request.name === name) {
return request;
}
}
}
return null;
}
This code looks through each folder and each request inside to find a request by its name.
Look for loops or repeated steps in the code.
- Primary operation: Looping through all folders and then all requests inside each folder.
- How many times: The inner loop runs once for each request in every folder, so total requests count.
As the number of folders and requests grows, the search takes longer.
| Input Size (total requests) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The time grows directly with the number of requests; doubling requests doubles the work.
Time Complexity: O(n)
This means the time to find a request grows in a straight line with the number of requests in the collection.
[X] Wrong: "Adding folders makes searching faster because it narrows down the search."
[OK] Correct: Even with folders, if you have to check every request inside, the total work depends on all requests, so folders alone don't reduce search time.
Understanding how organizing API requests affects search time helps you design better tools and workflows, a useful skill in many software roles.
"What if we added an index or map from request names to requests? How would the time complexity change?"