Introduction#
This is the third and final part of the series. Part 1 set up ServiceBus Topics. Part 2 converted to ServiceBus Triggers.
Today we add QuickFind, QuickUnion, and WeightedQuickUnion as ServiceBus Topic Triggers and analyze the performance.
A Bug!#
There’s an intriguing bug in the Console App: the Random class uses the CPU clock, so when creating both arrays in quick succession, they get the same seed and produce identical arrays. This means QuickUnion runs at optimal O(n) performance (merging each number to itself), while WeightedQuickUnion and WeightedQuickUnionWithPathCompression run at their worst (linear time with flat trees).
The fix: initialize Random as a static class member.



Analysis#
QuickFind is always the slowest — O(n²) regardless of input. It will never be Usain Bolt.

QuickUnion is better but with random input shows performance closer to quadratic. Worst case is O(n²).
WeightedQuickUnion and WeightedQuickUnionWithPathCompression are the champions — at worst linear time, and with the bug fix showing logarithmic runtimes that are half the best QuickUnion runs.


Conclusion#
We demonstrated four merge algorithms using Azure Functions with ServiceBus Topics. The code has DRY violations between the four triggers — a future post will explore refactoring using Inversion of Control.
Source: AzureFunctionsBlogDemos
