I. Piperidine is the most basic. The
N lone pair is in an
sp3 hybrid orbital and there is no resonance and due to
+I effect of alkyl group attached, it becomes more basic than
sp3 hybridised ammonia.
II. In pyridine, lonepair is in a
sp2 hybridised orbital but does not get involved in delocalisation. The
sp2 hybrid is smaller than
sp3, so there is a stronger attraction to nucleus, so less basic.
III.
NH3 is more basic as in ammonia, lone pair is localised and easily available for donation. Basic character is determined by ability to donate lone pair.
IV. The basicity of aniline is lower than basicity of ammonia as in aniline, the lone pair of electrons on
N is involved in resonance with benzene ring. So, correct order of basic strength is
‌ I > III > II > IV. ‌