how come the 3rd for loop complexity is O(nlogn) ??
Firstly its O(logn) and not O(nlogn) assuming loop body is O(1). Now coming to how it is O(logn). You can think of it as a loop starting from 2^0 to 2^j such that 2^j>=n and value of j is being incremented by 1. Now loop will terminate when j>=log(n)[Base 2], hence it is O(logn).
one might help himself with understanding of logarithms
2^x = n
log(n) = x*log(2)
x = log(n) with base 2