You must refer to both reasons when explaining your answer.
There are many examples of imperialism before world war one that contributed to the outbreak of war. An example we can look at is Kaiser Wilhelm II’s foreign policy. ‘A place in the sun’ is the name that is given to his desire to have a large overseas empire by taking over other countries, and this drove the Kaiser to get involved in many other imperialistic incidents that led to war. One incident is the naval race. To get this empire Wilhelm wanted, Germany required a large and powerful navy which led him to rapidly develop his navy. In fear that Germany was doing this to prepare for war, they created the Dreadnought battleship in 1906, which Germany replicated for herself, renaming it ‘Rheinland’. By 1914, Britain had 29 Dreadnought ships and Germany 17. Germany had now prepared her navy for war and successfully created tension between herself and Britain, making the naval race a cause that would contribute to war. Austria-Hungary also annexed Bosnia in 1908 due to imperialism and noticing the Ottoman Empire that ruled the Balkans was declining. This infuriated Serbia who believed they should rule Bosnia due to their geographical and ethnical similarities. After the assassination of Franz Ferdinand in 1914, and Serbia refusing the part of Austria-Hungary’s ultimatum that insisted they get to handle how the Black Hand gang (the terrorist group responsible for the assassination) were punished, Austria-Hungary declared war on Serbia which then dragged in the rest of the alliances. Because of the Kaiser and Austria-Hungary’s imperialistic beliefs, the two got involved in incidents that contributed to the outbreak of war.
Nationalism also contributed to the outbreak of war. An example of a cause of war fuelled by nationalism could be the Black Hand Gang and the assassination of Franz Ferdinand. Serbia and the Serbs of Bosnia were infuriated with Austria-Hungary’s annexation of Bosnia in 1908, because Serbia wished to rule Bosnia. Their hate of being ruled by Austria-Hungary led to the formation of the ‘Black Hand’ gang in 1911, founded and lead by Dragutin Dimitrijevic. The gang had the aim to free all Serbs under Austria-Hungary’s rule, and saw Franz Ferdinand’s (heir to the Austro-Hungarian throne) visit to Sarajevo in 1914 as a threat. He was later assassinated by Gavrilo Princip, a member of the Black Hand. Infuriated with the loss of their heir, Austria-Hungary issues an ultimatum to Serbia, who refused to accept the 6th rule which demanded Austria-Hungary punish the assassins. Annoyed with Serbia and feeling reckless from Germany’s Blank Cheque (an agreement that Austria-Hungary would always have unconditional support from Germany), war was declared between the two and this lead onto all the alliances being dragged into full on war. This assassination, fuelled by the Serbs’ nationalism and wishes to be ruled by Serbia, played a major part in the outbreak of war.
The naval race and annexation of Bosnia, both examples of situations fuelled by imperialistic beliefs, did create a lot of tension between Germany and Britain and Austria-Hungary and Serbia. The incidents did certainly make war more likely to break out, and they did alienate countries from one another, but the assassination of Franz Ferdinand was what actually pushed Austria-Hungary over the edge and convince them that they had to declare war, and this situation was created due to the nationalism of the Serbs. Therefore, I agree that nationalism was the most important cause of war.