Sign up and login workflows in No-Code - Time & Space Complexity
When users sign up or log in, the system performs several steps to process their information.
We want to understand how the time taken grows as more users or data are involved.
Analyze the time complexity of the following workflow steps.
1. Receive user input (username, password)
2. Check if username exists in database
3. If signing up, add new user record
4. If logging in, verify password matches stored hash
5. Return success or error message
This workflow handles both sign up and login by checking and updating user data.
Look for steps that repeat or scale with input size.
- Primary operation: Searching the database for the username.
- How many times: Once per sign up or login attempt.
As the number of users grows, searching the database takes longer if not optimized.
| Input Size (n users) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The time to find a user grows roughly in direct proportion to the number of users if searching is simple.
Time Complexity: O(n)
This means the time to process sign up or login grows linearly with the number of users in the database.
[X] Wrong: "Checking if a username exists always takes the same time no matter how many users there are."
[OK] Correct: Without special data structures, searching through more users takes more time because the system may check each user one by one.
Understanding how user lookup time grows helps you design better systems and explain your reasoning clearly in interviews.
"What if the database used an index or hash table to find usernames? How would the time complexity change?"