As it is told on title, should one have an audio interface to record electric guitar or If I use an adapter and plug into computer directly will it still work?
With adapter I mean something like this
And with audio interface I mean this one:
In short; yes it is necessary.
Firstly, your proposed cable wouldn't work - you'd need one made up specially to go from a regular mono TS jack to whatever socket configuration your laptop uses…
Images from CableChick - Understanding TRRS & Audio Jacks
You would still suffer from mismatched impedance & levels. Mic inputs do not have the same requirements as instrument…
End result: even if you achieve it, it will sound bad.
Your next problem is that if you just use a simple interface like your second example, you will successfully connect one to the other. Joy.
Guitars are not really meant to be run 'clean as a whistle' into an audio system. It will sound thin & flat, nothing like a guitar through an amp, even one set to 'clean'.
So… you need a guitar amp emulator.
You can get a software one, & if your computer is fast enough at processing, you may be able to use it without any perceivable latency [delay] affecting your playing. If it's not fast enough, then the delay might be irritating or confusing.
That sets you up for a third option - an interface with built-in guitar amp emulation; this would mean you get zero latency, as you can feed the sound directly back to yourself without going through the computer [whether simultaneously recording or not].
To do that as economically as possible, I'd be looking at something like the Line 6 UX1 or UX2. You can pick them up pretty cheaply on eBay these days. Software is still available from Line 6, even though they're now out of production.
The main reason that plugging most electric guitars directly into a computer probably won't work well is that the passive pickups found in most electric guitars have high impedance, and the input that you plug in to should have higher impedance than the output to get a reasonable level of signal.
Additionally, if your computer has only a 'line-in', rather than a 'mic in', it might not have enough gain to record at a decent level.
The simplest device you could buy that might get you usable recordings would be a DI (which solves the impedance problem), or a DI & Preamp (which would give you some more level). Any powered guitar pedal might also do these jobs for you too. You do not necessarily need an audio interface.
The reason why it still may be a good move to buy an interface is that assuming it has a guitar or instrument input, it does the job of DI and preamp, and it will likely have drivers and hardware that can achieve lower latency than the built-in audio on the computer, and probably have better audio quality too - plus, you're less likely to need special cables!
It is possible to plug a guitar straight in to a computer and record it. I've done this with an active bass, and with an electroacoustic. However, these guitars both had preamps built in.