@ayushsomani

The total number of seeks will be ($b_r+n_r$) - Wikipedia Link **Because -**

Lets assume we have two memory blocks available in the main memory, now seek time is the time taken to move the read/write head of the disk to the position from where a block is to be read and written to the main memory from the disk.

Now all the blocks of a relation are contiguously stored in the disk so if you seek to a certain block of a relation, then you don't need further seeks to access the subsequent blocks as all are contiguous.

Coming to nested loop join, For every tuple in **R **all the tuples of **S **has to be scanned.

So as said earlier we have two blocks(B1,B2 (Suppose)) available in main memory, then first seek to a block of **R **and transfer it to B1.So number of seeks =** 1**

Now for the first tuple of **R **in **B1 **seek to a block of **S** and bring the block to **B2**. number of seeks = 1+**1**=2.Then compare the $1^{st}$ tuple of **R **with the first tuple of **S.**

Next we have to compare $1^{st}$ tuple of **R **with **second **tuple of **S, **so transfer the same block again (assuming the second tuple of S is in that block only) in B2 (This is the disadvantage of nested loop join.Check Block Nested Loop Join) .But now no more seek is required, in-fact for comparing the $1^{st}$ tuple of **R **with **all** the other tuples of **S , **we don't need anymore seeks as all blocks are contiguous and can be accessed directly.

After we are done comparing all records of **S **to the **first **record of **R** .We have to compare **second **record of **R **with all the records of **S **.**No seek needed** as 2nd tuple of **R** already present in **B1.**But now the read/write head of disk is at last block of **S,**hence **a seek is needed** to move it to the first block of **S.** Thus number of seeks=2+**1**=3.

Thus we can see we **need a seek for every tuple of R and we also need a seek if we have to access a block of R,** like here if we are done comparing all the records of **R **in **B1 , **a **seek is needed **to move the read/write head to next block of **R **as now it is at the last block of **S. **

Therefore total no. of seeks needed= $n_r+b_r$