Introduction#
One of the things I really enjoy while writing variations of algorithms is comparing the total run-time between them. I find it rewarding to start with a minimal amount of iterations, say 10 merges, where QuickFind (O(n²)) and WeightedQuickUnion (O(m log n)) look almost the same. Then add more iterations to see the time savings become apparent.
For today’s demo we compare four algorithms from Robert Sedgewick’s Algorithms in Java: QuickFind, QuickUnion, WeightedQuickUnion, and WeightedQuickUnionWithPathCompression.
The architecture: an HTTPTrigger writes a message to a Service Bus Topic with Subscriptions for each algorithm. Each algorithm runs as a ServiceBusTopicTrigger, writes output to Blob Storage and performance data to Table Storage.
Prerequisites#
- Azure ServiceBus (Standard tier, ~$10/month for Topics)
- Source: AzureFunctionsBlogDemos
Adding the Topic#
Create a Service Bus namespace in the Azure Portal, grab the connection string from Shared Access Policies, and add it as AzureWebJobsServiceBus in your Function App settings.






Adding the Code#
The MergeTrigger HTTP Trigger receives the arrays, creates the ServiceBus Topic and Subscriptions (one per algorithm), and sends the message. The refactored MergingArray.cs contains all four algorithms with a Merge() method that dispatches based on an enum.





Conclusion#
Today we set up ServiceBus Topics so one HTTP request fans out to four algorithm subscriptions. Part 2 converts our HTTP Trigger to a ServiceBus Trigger. Part 3 adds the remaining algorithms and analyzes performance.
