Suppose you want to send a spacecraft from Earth to Mars, leaving Earth at time $t_0$ and arriving at Mars at some later time $t_1$. Ignoring the gravitational fields of Earth, Mars, the Moon, and all of the other planets, the only gravitational field of concern is the Sun.
There is always at least one, and oftentimes more than one, Newtonian mechanics conic section that will take the spacecraft from Earth's position at time $t_0$ and Mars position at time $t_1>t_0$. If $t_1$ is $t_0$ plus one second, the Newtonian solution will require traveling faster than the speed of light, but that is not a constraint in Newtonian mechanics. (The $\Delta V$ needed to achieve that faster than light transfer orbit is a bit problematic. It might be better to look for a longer transfer time than one second.)
Solving for the conic sections needed to accomplish the transfer is Lambert's problem. There are lots of articles on the internet and sections in textbooks regarding solving Lambert's problem. The $\Delta V$ needed to accomplish the transfer is the sum of the $\Delta V$ needed to transfer from Earth's orbital velocity at time $t_0$ to the transfer orbit, and the $\Delta V$ needed to transfer from the transfer orbit to Mars's orbital velocity. For shortish transfers, between one second and a bit less than one orbit, there are typically two solutions. (180° degree transfers are problematic as there are an infinite number of solutions.) Ignoring those 180° transfers, one of the two solutions will be better than the other in terms of total $\Delta V$.
There are two variables to play with in this scenario, the Earth departure time and the Mars arrival time. There is a cost associated with this pair of times. A simple cost metric is the total $\Delta V$, $\Delta V_{\text{tot}} = ||\Delta V_0|| + ||\Delta V_1||$, where $\Delta V_0$ is the $\Delta V$ needed to transfer from Earth's orbital velocity to that of the transfer orbit at time $t_0$ and $\Delta V_1$ is is the $\Delta V$ needed to transfer from transfer orbit to Mars's orbital velocity at time $t_1$. More complex cost metrics exist. Whichever cost metric you decide to use, this becomes a "simple" matter of cost minimization for a non-linear two variable problem. (I wrote "simple" because optimizing a non-linear two variable problem that is subject to singularities such as a 180° transfer is not "simple".)
What people at JPL and elsewhere do is to create a pork chop plot. What you'll find for transfers from Earth to Mars is that there is a narrow window in time every other year where the cost is not phenomenal. Two sets of feasible solutions arise, one set involving a shortish transfer time and the other a longish transfer time. When plotted graphically as contour lines that depict cost, with departure time on one axis and arrival time on the other axis, the result looks a bit like a pork chop, hence the name pork chop plot.
There are several questions at this site and at the Physics.SE sister site regarding pork chop plots. I suggest you look into these and come back with more specific questions.