PHP
  Home arrow PHP arrow Page 4 - Collections and Sorting Continued
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Collections and Sorting Continued
By: David Fells
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2006-04-04


    Table of Contents:
  • Collections and Sorting Continued
  • Sort Algorithms of Quadratic Complexity
  • Sort Algorithms of n log n Complexity
  • Metrics

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Collections and Sorting Continued - Metrics
    ( Page 4 of 4 )

    Here are some lovely graphs borrowed from http://linux.wku.edu/~lamonml/algor/sort/sort.html. The first graph shows execution time, represented in seconds on the vertical axis and the number of items in a data set on the horizontal axis. The second graph shows execution time in tenths of a second. You can perhaps guess which sort of complexity is represented by each graph!

     

    The n log n algorithms absolutely crush the quadratic algorithms in terms of speed.

    Conclusion

    In this article we have reviewed the primary sorting algorithms and their general properties. We have reviewed how quickly they complete relative to the size of the data set to be sorted. We have also discussed how to choose the appropriate algorithm. The metrics presented in this article were borrowed from http://linux.wku.edu/~lamonml/algor/sort/sort.html, who was kind enough to compile them, knowing that eventually I would need them-–so, thanks to wku.edu.

    As I wrote this article, it occurred to me that we could go one step further and throw in an implementation of the Strategy design pattern using the contents of this article. We will create a SortStrategy class and create a method in the base Collection class to select a SortStrategy class based on the data it contains. Since we have reviewed the best and worst of our two classes of algorithms and know how complex (or simple) they are, we will pick the “best” from each class and go from there.



     
     
    >>> More PHP Articles          >>> More By David Fells
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek