Calculation of d'prime in forced choice experiment I am working on psychtoolbox and in my experiment I have given two images containing two roads (one is shortcut and other is longer way). In one image, the longest way is safe and in the other the shortcut way is safer. The images appear randomly. Students have to press left arrow key of laptop if longest is safe and right key for shortcut way.

I am confused in this whether it come under forced choice or 2AFC (alternative forced choice)?
It sounds like you are struggling with the terminology. The terminology is not particularly clear.

As it sounds like you are forcing them to respond with either the left or right arrow key, I would describe the task as forced choice. If you ask subjects to rate how likely the longest path is safe with the 0-9 keys, I would describe it as a rating, despite them being forced to give an answer on every trial. If you allowed them to skip trials with the space bar, some people would not call this a forced choice task. Things are messy though since you could think of the left arrow as 0, the space as 5, and the right as 9. In terms of $d'$, what matters is that there are two choices.

The two most common paradigms with exactly two response choices are typically called the yes/no paradigm and the 2AFC paradigm. Despite it's name, the yes/no paradigm can have any response labels, including left arrow and right arrow. In the typical setup, in addition to both paradigm having 2 responses, both paradigms have exactly two stimulus classes (e.g., signal and noise, or in your case long and short). The defining characteristic that differentiates a yes/no paradigm from a 2AFC paradigm is that in a yes/no paradigm each trial (and hence response) is based on a single presentation of one of the stimulus classes while in the 2AFc paradigm there is a single presentation of both stimuli classes (either concurrently or sequentially). This difference is critical for calculating $d'$ and a $\sqrt{2}/2$ scale factor is needed to correct for the fact that in the 2AFC paradigm there is more information.

So to answer your question, it is not clear from your description if you need to scale $d'$ by $\sqrt{2}/2$.