What "algorithm" are carnivorous larvae using when foraging?
I'm going to assume that when you say algorithms, you mean the forms of innate behavior an organism may have relating to their senses (e.g. when sunlight is detected by a worm through the photoreceptors in their skin, it will move towards the opposite direction of the source of light to stay in their preferred environment).
These mentioned species of insects are very different taxonomically, but their number of sensory organs are for most part similar including during larval stages.
Examples of innate behavioural responses seen in invertebrates include taxis and kinesis.
Taxis is a change in movement in response to an environmental stimulus – either towards (positive) or away (negative)
Kinesis is a change in the rate of activity in response to an environmental stimulus
So, when talking about rough algorithms, when a larva detects a particular stimulus (e.g. chemicals of prey via chemoreceptors),  The organism will either have a 1 or a -1 value for Taxis response (e.g. it runs towards or away from the prey), and a rate of activity relative to taxis which represents kinesis (e.g. it gradually moves faster towards the prey as the chemical stimulus becomes stronger (meters per hour for example).
So, you could say that the theoretical formula/algorithm for hunting prey relating to the chemoreceptors as an example would be:
Taxis ('1' or '-1' to symbolize moving towards or away from a prey) multiplied by the number of 'prey' chemicals received by the chemoreceptors equaling the strength of the larva's response which could be (as an example) translated to the velocity of larva
Of course all the other senses such as photoreceptors and the chordotonal organ (vibration sensor) must be considered and I couldn't find any actual algorithm for how these species hunt. This is just a way to percieve how insects both in and past their larval stages respond to stimuli through their innate behaviour.