18The majority of insect species have a clearly defined larval stage during development. Larval 19 nutrition is crucial for individuals' growth and development, and larval foraging success 20 often depends on both resource availability and competition for those resources. To date, 21 however, little is known about how these factors interact to shape larval development and 22 behaviour. Here we manipulated the density of larvae of the polyphagous fruit fly pest 23Bactrocera tryoni ('Queensland fruit fly'), and the diet concentration of patches in a foraging 24 arena to address this gap. Using advanced statistical methods of machine learning and linear 25 regression models, we showed that high larval density results in increased larval aggregation 26 across all diets except in extreme diet dilutions. Larval aggregation was positively associated 27 with larval body mass across all diet concentrations except in extreme diet dilutions where 28 this relationship was reversed. Larvae in low-density arenas also tended to aggregate while 29 those in high-density arenas tended to disperse, an effect that was observed for all diet 30concentrations. Furthermore, larvae in high-density arenas displayed significant avoidance of 31 low concentration dietsa behaviour that was not observed amongst larvae in low-density 32 arenas. Thus, aggregation can help, rather than hinder, larval growth in high-density 33 environments, and larvae may be better able to explore available nutrition when at high-34 density than when at low density. 35 36 37 38 110 Predictions 1111) Previous studies in other species have shown that larvae prefer to occupy patches that 112 are shared with conspecifics [e.g., 45 ]. Thus, we predicted that an increase in larval 113 density should increase aggregation formation as well as aggregation size amongst 114 diet patches. However, this effect could be diet-dependent, whereby macronutrient-115 poor diets could support smaller aggregations whereas macronutrient-rich diets would 116 support larger aggregations. As a result, we predicted that aggregates should be 117 smaller in macronutrient-poor diets than in macronutrient-rich diets; 1182) In other insects, larval aggregation can facilitate feeding [e.g., 40 ]. We therefore 119 predicted that treatments with high larval aggregations should have larvae with higher 120 body mass. However, macronutrient-poor diet is known to reduce larval body mass 121 (see 'Introduction'). As a result, we predicted that larval body mass should be lower 122 in macronutrient-poor diets compared with macronutrient-rich diets; 123 124
Materials and Methods 125
Fly stock and egg collection 126We collected eggs from a laboratory-adapted stock of B. tryoni (>17 generations-old). The 127 colony has been maintained in non-overlapping generations in a controlled environment room 128(humidity 65 ± 5%, temperature 25 ± 0.5 o C) with light cycle of 12h light: 0.5h dusk:11h 129 dark: 0.5h dawn). Adults were provided a free-choice diet of hydrolysed yeast (MP 130 Biomedicals, Cat. n o 0210330...