Visited nodes not taken care

in this question we are just calling the function on north, west ,east and south directions without taking in consideration whether a particular node is visited before or not which is increasing the complexity as multiple nodes are getting transversed various times . it would be better if before calling the function on all four directions we keep a check whether the neighbours are already visited or not.
AM I RIGHT???

Yeah a boolean amtrix of the same size that tells whether a node has been visited previously or not (using true if visited, false otherwise) and only exploring the path from that node if it is not visited(false).