0
0
Rest APIprogramming~5 mins

DELETE for removing resources in Rest API - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: DELETE for removing resources
O(n)
Understanding Time Complexity

When we use DELETE requests in REST APIs, we want to know how long it takes to remove data as the amount of data grows.

We ask: How does the time to delete change when there are more resources?

Scenario Under Consideration

Analyze the time complexity of the following code snippet.

DELETE /items/{id}

// Server receives DELETE request
// Finds item by id
// Removes item from database
// Sends response confirming deletion

This code deletes one item identified by its unique id from the database.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Searching for the item by its id in the database.
  • How many times: This happens once per DELETE request.
How Execution Grows With Input

Explain the growth pattern intuitively.

Input Size (n)Approx. Operations
10About 10 steps to find the item
100About 100 steps to find the item
1000About 1000 steps to find the item

Pattern observation: The time to find and delete grows roughly in direct proportion to the number of items.

Final Time Complexity

Time Complexity: O(n)

This means the time to delete an item grows linearly with the number of items in the database.

Common Mistake

[X] Wrong: "Deleting one item always takes the same time, no matter how many items exist."

[OK] Correct: If the database searches items by scanning all entries, more items mean more time to find the one to delete.

Interview Connect

Understanding how DELETE requests scale helps you explain backend performance clearly and shows you know how data size affects response time.

Self-Check

"What if the database used an index to find items by id? How would the time complexity change?"