Finding the optimal packet size

I have recently started reading the book Computer Networking: A Top-down Approach in hopes to get introduced to computer networks. When attempting one of the questions from the book for practice, I got stuck and spent the whole day today trying to make some progress.

The questions is:

Consider sending a large file of F bits from Host A to Host B. There are three links (and two switches) between A and B, and the links are uncongested (that is, no queuing delays). Host A segments the file into segments of S bits each and adds 80 bits of header to each segment, forming packets of $$L = 80 + S$$ bits. Each link has a transmission rate of $$R$$ bps. Find the value of $$S$$ that minimizes the delay of moving the file from Host A to Host B. Disregard propagation delay.

I was able to identify that the number of packets we have is $$\frac{F}{S}$$, and the delay for the first packet will be $$N \cdot \frac{L}{R} = 3 \cdot \frac{80+S}{R} seconds$$ where $$N$$ is the number of links. This is all I could come up with and I don't know what to do from here. A detailed and newbie-friendly explanation to this question would be greatly appreciated!

You are on the right track. The value of $$S$$ that minimizes the delay of moving the file from host A to host B is $$S = \sqrt{40 F}$$, which can be shown as follows.
The first packet reaches the destination after a delay of $$3 \times d_{trans}$$, where $$d_{trans} = \frac{80+S}{R}$$ is the transmission delay, as you’ve already shown. Each of the subsequent $$\frac{F}{S}-1$$ packets that follow this first packet will take another $$d_{trans}$$ time to reach the destination. Hence, the total delay for all the packets is $$d_{trans} \times \left(3 + \frac{F}{S} - 1\right) = d_{trans} \left( \frac{F}{S} +2\right) = \left(\frac{80+S}{R}\right)\left(\frac{F}{S}+2\right) =: f(S)$$.
We have that $$f(S) = \frac{80F}{RS} + \frac{160}{R} + \frac{F}{R} + \frac{2S}{R}.$$
To find the minimum value of $$f(S)$$, we set the derivative $$f’(S)$$ to equal $$0$$, and we obtain
$$\frac{80F}{R} \left(\frac{-1}{S^2}\right) + \frac{2}{R} = 0,$$ i.e. $$S = \sqrt{40F}.$$ At this value of $$S$$, $$f’’ > 0$$, and so this is a local minimum.