Click here to Skip to main content
6,632,966 members and growing! (19,086 online)
Email Password   helpLost your password?
General Programming » Algorithms & Recipes » Algorithms     Intermediate License: The Code Project Open License (CPOL)

Big O Algorithm Analyzer for .NET

By dawright, TheArchitectmc

A heurisitc graphing tool to help discover 'Big O Notation' function thru infinite asymptotic's and instrumentation.
C#, XML, SQL, JScript .NET, Forth.NET, XSLT, F#, Windows (WinXP, Vista, Win2008, Win 7), .NET CF, .NET (.NET 1.0, .NET 1.1, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0), All Topics, Architect, Dev, QA, Design
Version:8 (See All)
Posted:12 Jul 2009
Updated:21 Jul 2009
Views:8,744
Bookmarked:22 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
5 votes for this article.
Popularity: 3.49 Rating: 5.00 out of 5

1

2

3

4
5 votes, 100.0%
5
This Developer centered article with an index rating 5 out of 5

Article Index Rating:
Developer - Developer            (5)     of 5      (Intermediate)
Architect - Architect             (1.67) of 5     (Beginner)
Graphic Designer - Graphic Designer   (3.33) of 5     (Intermediate)

Download Article_Demo.zip - 64.83 KB

Download Article_Src.zip - 110.18 KB

 Article2.PNG

Table of Contents

Introduction

   After doing some research on 'Big O Notation' I read some posts from some developers explaining that you have to do 'Big O Equations' in your head.  Perhaps they were pulling some ones leg?  I don't know.  But it gave me the idea to create this tool, which can help to find the 'Big O function' for a given algorithm.  The application uses C# Reflections to gain access to the target .net assembly.  Infinite asymptotic's and instrumentation are used to graph the function in relationship to time.  When using infinite asymptotic's it is necessary to create a method or property which takes an integer as input.  The integer value is the infinity point, the point at which the function evaluates to an infinite quantity.  This point can be time, value, etc.  In the examples Fibonacci functions are evaluated.  Here is a graph of Two linear recursive Fib's: Article1.PNG

Here is the original prototype graphing an exponential recursive Fib:

ExponentialFib.PNG

I used Derek Bartram's WPFGraph in the Demo which is not licensed for commercial or non profit.  If you need to use this tool for commercial or non profit, you can extend the functionality of the prototype.  There are a few minor glitches with my implementation of Derek's WPFGraph.  Major problem is with the performance scaling.  In my prototype I use modulus scaling which is very exacting.  I tried to use the same scaling with Derek's graph, however the performance grid lines don't exactly match the points on the grid.  If you need exact grid lines and fast performance extend the prototype.

Article3.PNG

  The application is broiler plate, this should give you the ability to extend the features to your own specification.  Here is the same graph using Derek's graph:

Article.PNG

Another minor glitch is the time base jump at the start of the graph line.  Graphing with high infinity values improves this, however a threading fix is probably necessary.  I have a request into MSDN for a fix.  I will post the fix once I get it.

The tool uses heurstics to find the 'best guess' Big O Function:

Article5.PNG 

And allows the user to review the details:

Article4.PNG

Special thanks to Derek for all his hard work!  Great Graph!

About the Code:

The application uses the Model, Viewer, Presenter; Factory, and Publisher / Subscriber patterns. The viewer is the XAML Window which allows for easy design by designers, the presenter is implemented in the xaml.cs of the window. The factory and publisher-subscriber pattern is implemented in the AnalysisFactory. The MVP pattern is a good stepping stone in prototype development as it is easy to make custom abstractions with out sacrificing code base.

Points of Interest:

I really don't totally understand the magic of modulus.  I do value it's power though.  I had to tinker with the modulus equations to get the scaling functions to work in the prototype.  Perhaps I need to brush up on modulus.  Here are the modulus functions for scaling:

((dm.Point[1] * PointScale % infinityPoint) / 10) * PointRullerDivision; //Gets the vertical scaling.

(aggT * TimeScale % totTime) / 10 * TimeScaleDivision; //Gets the horizontal scaling.

PointScale is calculated by dividing 100 by infinityPoint (this is an inverse function), making the function 100 base. PointRullerDivision is calculated by dividing the graph Canvas by 100 (compliment to inverse function). The horizontal (x axis, time) is caculate the same way, however the aggregate time ; aggT, is used in place of the point index dm.Point[1]. Total time is calculated using a LINQ to Object lambda function (also pure magic as far as I know).

Math.Round(dms.Sum(p => p.Point[0]),0)

I thought it was interesting that after refactoring the prototype to use Derek's graph the modulus functions still worked.  Derek's scaling calculates the scale by dividing sections of the scale in a recursive loop.  I did run into a small problem with a rounding error after refactoring.  Sometimes it's the little things that make a big difference.  Rounding the totTime to Zero decimal places and not rounding the aggT causes a displacement in the performance graph where the x axis grid lines do not match a point on the graph, but will not work with Derek's graph unless the total time is rounded.  The prototype works perfectly.

Another point of interest is Derek's grid points.  If you get the rendered geometry of one of his grid points, the bounds evaluates to infinity.  I tried all methods of getting the position to correct the rounding error.  Nothing worked!  Must be magic.  So the featured application has many workarounds for the integration of the WPFGraph.  

External Links:

Prototype Research

Graphic Designer - Graphic Designer (3.33) Developer - Developer (5) Architect - Architect (1.67)

Revision History:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Authors

dawright


Member
I am a .NET developer who works daily on enterprise-scale applications using C#, SQL, XML, ASP.NET, and myriad other technologies. My academic background is in physics and economics.

I am the original architect of Sandcastle managed reference documentation engine and of the Meta.Numerics library for scientific computation.
Location: United States United States

TheArchitectmc


Member
I’m a self learned wiz kid turned Architect. Stared with an Apple IIe, using AppleSoft Basic, ProDos and Begal Basic at age 10.

Picked up LPC in college before the Dot Com Explosion. Wrote some Object C in the USAF for one of my instructors. Got a break from a booming computer manufacture testing server software. Left the Boom and went to work for a Dot Com built from the ashes of Sun Micro in CS. Mentoring in Java solidified me as a professional developer. Danced in the light of the sun for 13 years, before turning to the dark side. An evil MVP mentored me in the ways of C# .NET. I have not looked back since.

Interests include:

~ Parallel Programming
~ Instruction Set Simulation and Virtualization
~ CPU to GPU code conversion
~ Performance Optimizations
~ Mathematics and Number Theory
~ Domain Specific Languages
~ Virtual Machine Design and Optimization
~ Graphics Development
~ Compiler Theory and Assembler Conversion Methodology

IEEE Fellow Member 2000
Occupation: Architect
Company: Retired - I just do R&D and write articles now.
Location: United States United States

Other popular Algorithms & Recipes articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 21 of 21 (Total in Forum: 21) (Refresh)FirstPrevNext
NewsDid you create a new Big O Function Heuristic (Share um' here) PinmemberTheArchitectmc15:51 21 Jul '09  
NewsBugs in the Tool (Report um' here) PinmemberTheArchitectmc15:21 21 Jul '09  
QuestionWhat are your thoughts? How can I improve this article? PinmemberTheArchitectualizer5:10 12 Jul '09  
AnswerRe: What are your thoughts? How can I improve this article? PinmemberS. Senthil Kumar5:48 12 Jul '09  
AnswerRe: Big O function finding has not been implemented yet. PinmemberTheArchitectualizer6:42 12 Jul '09  
GeneralRe: Big O function finding has not been implimented yet. PinmemberS. Senthil Kumar7:09 12 Jul '09  
GeneralRe: Big O function finding has not been implemented yet. PinmemberTheArchitectualizer7:50 12 Jul '09  
GeneralRe: Big O function finding has not been implimented yet. PinmemberS. Senthil Kumar9:04 12 Jul '09  
AnswerRe: Big O function finding has not been implimented yet. [modified] PinmemberTheArchitectualizer9:36 12 Jul '09  
NewsRe: Big O function finding has not been implemented yet. (Add Heuristics) PinmemberTheArchitectmc14:38 21 Jul '09  
AnswerRe: What are your thoughts? How can I improve this article? PinmvpPete O'Hanlon3:47 13 Jul '09  
GeneralRe: What are your thoughts? How can I improve this article? PinmemberTheArchitectualizer4:26 13 Jul '09  
GeneralRe: What are your thoughts? How can I improve this article? PinmvpPete O'Hanlon4:42 13 Jul '09  
GeneralRe: What are your thoughts? How can I improve this article? PinmemberTheArchitectualizer6:34 13 Jul '09  
GeneralRe: What are your thoughts? How can I improve this article? (Use MVVM Pattern) PinmemberTheArchitectualizer9:36 13 Jul '09  
QuestionRe: What are your thoughts? How can I improve this article? PinmemberTheArchitectmc11:51 23 Jul '09  
AnswerRe: What are your thoughts? How can I improve this article? Pinmembersupercat96:57 13 Jul '09  
GeneralRe: What are your thoughts? How can I improve this article? PinmemberTheArchitectualizer7:44 13 Jul '09  
GeneralRe: What are your thoughts? How can I improve this article? Pinmembersupercat97:06 14 Jul '09  
GeneralRe: What are your thoughts? How can I improve this article? PinmemberTheArchitectualizer12:29 14 Jul '09  
GeneralRe: What are your thoughts? How can I improve this article? (Add More Examples) PinmemberTheArchitectualizer9:39 13 Jul '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 21 Jul 2009
Editor:
Copyright 2009 by dawright, TheArchitectmc
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project