[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Most efficient Structures for sorting

Posted on 2006-06-08
3
Medium Priority
?
279 Views
Last Modified: 2010-04-16
What is the most efficient structure in C# for sorting between various types

For example I have

Strings
Integers
Booleans

As opposed to having them all scattered I want to sort my structure so that I have all strings then integers then booleans.

I was thinking a list would be the simplest solution.
0
Comment
Question by:directxBOB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:t_itanium
ID: 16867794
try to use the GetType property ...and sort according to it..

cheers
0
 
LVL 11

Accepted Solution

by:
anyoneis earned 1000 total points
ID: 16867816
Do they have to go into the same structure? Why not have three separate structures, one for each type? The reason this comes to mind is that if you store all of these together, you are going to have to store objects, and that means you will be boxing and unboxing integers and booleans.

Of course, if they are in the same structure already, that won't be any additional overhead. And the sorting algorithm shouldn't have to box/unbox, so maybe that's not a problem.

What about a simple array of objects?

David
0
 
LVL 9

Assisted Solution

by:pallosp
pallosp earned 1000 total points
ID: 16868236
If you store them in an ArrayList, the time complexity of the sorting is
   - 2*n*log2(n) GetType calls
   - n*log2(n) type comparisons
   - n*log2(n) value comparisons
   - 2*n*log2(n) boxings
If you use 3 generic lists for each type
   - n GetType calls and n boxings for distributing the elements into 3 lists
   - n/3 * log2(n/3) value comparisons for each list
   - n boxings for putting all together in 1 list

I think sorting using generic lists is 2-3 times faster.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question