0
0
Computer Networksknowledge~5 mins

FTP and SFTP for file transfer in Computer Networks - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: FTP and SFTP for file transfer
O(n)
Understanding Time Complexity

When transferring files using FTP or SFTP, it's important to understand how the time taken grows as the file size increases.

We want to know how the transfer time changes when files get bigger or when many files are sent.

Scenario Under Consideration

Analyze the time complexity of this simplified file transfer process.


function transferFiles(files) {
  for (let file of files) {
    openConnection();
    sendFile(file);  // sends file data byte by byte
    closeConnection();
  }
}
    

This code sends each file one after another, opening and closing the connection each time, sending data byte by byte.

Identify Repeating Operations

Look at what repeats in this process:

  • Primary operation: Sending each byte of every file.
  • How many times: For each file, the number of bytes in that file.

The main time cost comes from sending all bytes one by one.

How Execution Grows With Input

As file sizes grow, the time to send them grows too.

Input Size (total bytes)Approx. Operations (bytes sent)
10 KB10,240
100 KB102,400
1 MB1,048,576

Pattern observation: The time grows roughly in direct proportion to the total number of bytes sent.

Final Time Complexity

Time Complexity: O(n)

This means the time to transfer files grows linearly with the total size of the files.

Common Mistake

[X] Wrong: "Opening and closing the connection each time doesn't affect the total time much."

[OK] Correct: Opening and closing connections add extra time for each file, so doing it repeatedly can slow down the overall transfer significantly.

Interview Connect

Understanding how file transfer time grows helps you explain network performance and design better transfer methods.

Self-Check

What if we kept the connection open for all files instead of opening and closing it each time? How would the time complexity change?