Letters from Readers

Reader Feedback: The C# Priority Queue

Readers share opinions about Priority Queues and the Surface tablet.

The Microsoft .NET Framework doesn't contain a priority queue class. Dr. James McCaffrey offered a C# implementation in his November article, "Priority Queues in C#". One reader wondered why items did not appear in an ordered manner:

I thoroughly enjoyed your article on priority queues, but there's one point that confuses me. In my opinion, a priority queue (PQ) should be ordered by default. In Figure 2, the item with priority 3 comes before the item with priority 2. The reason for this seems to be that when we're adding items, we compare them to their parents to determine if we need to switch them with their parents, but we don't compare them to their siblings. Of course, if we switch an item with its sibling, then we'll need to check the whole tree starting at the sibling node to ensure that we haven't created an inconsistency. There's also the possibility that there's an alternate way of traversing the binary heap. What's the best way of ensuring that when we traverse a PQ, we always obtain an ordered list?

Carlos
Atlanta, Ga.

Dr. McCaffrey responds:
It turns out that a priority queue is only partially ordered by definition, and so traversing a PQ won't generate data in order. The intent of a PQ is that only the very front node is "ordered," in a sense. The remaining nodes are not ordered. If you look closely at the screenshot in the article, you'll see that this is the case.

PQs are used in algorithms where only the one element with the highest priority is needed at any time. By not having to order the remaining nodes, PQs have better performance than binary trees. You're correct that a PQ could be implemented as a binary tree -- the root node would be the one with the highest priority, and all remaining nodes would, in fact, be ordered.

ARMed with Windows 8
Several readers questioned On VB columnist Joe Kunk about his reasoning in "Why I Pre-Ordered a Surface Tablet".:

So for $740, why not buy a laptop? Isn't that what you bought: a very low-end, 10-inch touchscreen laptop?

Paul
Iowa

Proprietary port and $40 for an adaptor ... that's [sliminess] of truly Apple proportions.

Dave Granger
United Kingdom

Joe Kunk responds:
The Surface is not a laptop replacement. I can't run Visual Studio or VMware on it. So my computing platform is a triad of Windows Phone, Surface tablet and Quad-Core i7 laptop. Each has its own important place in keeping me connected and productive.

Visual Studio Magazine wants to hear from you! Send us your thoughts about recent stories, technology updates or whatever's on your mind.

About the Author

This story was written or compiled based on feedback from the readers of Visual Studio Magazine.

comments powered by Disqus

Featured

  • Microsoft Revamps Fledgling AutoGen Framework for Agentic AI

    Only at v0.4, Microsoft's AutoGen framework for agentic AI -- the hottest new trend in AI development -- has already undergone a complete revamp, going to an asynchronous, event-driven architecture.

  • IDE Irony: Coding Errors Cause 'Critical' Vulnerability in Visual Studio

    In a larger-than-normal Patch Tuesday, Microsoft warned of a "critical" vulnerability in Visual Studio that should be fixed immediately if automatic patching isn't enabled, ironically caused by coding errors.

  • Building Blazor Applications

    A trio of Blazor experts will conduct a full-day workshop for devs to learn everything about the tech a a March developer conference in Las Vegas keynoted by Microsoft execs and featuring many Microsoft devs.

  • Gradient Boosting Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the gradient boosting regression technique, where the goal is to predict a single numeric value. Compared to existing library implementations of gradient boosting regression, a from-scratch implementation allows much easier customization and integration with other .NET systems.

  • Microsoft Execs to Tackle AI and Cloud in Dev Conference Keynotes

    AI unsurprisingly is all over keynotes that Microsoft execs will helm to kick off the Visual Studio Live! developer conference in Las Vegas, March 10-14, which the company described as "a must-attend event."

Subscribe on YouTube