Depends on the root cause. If the terrorism comes from a place of desperation for liberation or emancipation, addressing the underlying material conditions would prevent that kind of terrorism. A great example of that is Apartheid South Africa and Ireland. On the other hand, if the terrorism comes from a place of Fascism, like ISIS or the KKK, I think funding progressive and democratic opposition and also education would have the most positive effect. Holding the terrorists responsible for their actions and jailing them accordingly is really important, but to solve the underlying cause is critical to end it entirely. Otherwise, if the root cause isn’t addressed, there is no reason to believe the terrorism will stop.