What is a database management system in DBMS Theory - Complexity Analysis
When we use a database management system, it handles many tasks like storing and finding data.
We want to understand how the time it takes to do these tasks changes as the amount of data grows.
Analyze the time complexity of the following SQL query to find a record by ID.
SELECT * FROM Employees WHERE EmployeeID = 12345;
This query searches for one employee by their unique ID in the Employees table.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Searching through the table rows to find a matching EmployeeID.
- How many times: Depends on the number of rows; could check many rows if no index is used.
As the number of employees grows, the search may take longer if the system checks each row one by one.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Up to 10 checks |
| 100 | Up to 100 checks |
| 1000 | Up to 1000 checks |
Pattern observation: The number of checks grows roughly in direct proportion to the number of rows.
Time Complexity: O(n)
This means the time to find a record grows linearly as the number of records increases.
[X] Wrong: "Searching a record always takes the same time no matter how big the table is."
[OK] Correct: Without special structures like indexes, the system may need to check many rows, so more data means more time.
Understanding how database queries scale with data size helps you explain how systems handle large amounts of information efficiently.
"What if we added an index on EmployeeID? How would the time complexity change?"