Welcome to Dream.In.Code
Become a Java Expert!

Join 150,138 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,275 people online right now. Registration is fast and FREE... Join Now!




Got any tool to simulate our coding is effective?

 
Reply to this topicStart new topic

Got any tool to simulate our coding is effective?

fsloke
23 Aug, 2008 - 12:25 AM
Post #1

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
Here is the situation or problem raise
You have a basket of marble. Your task is to identity got how many color in the basket.

I prepare a small note book to jot down the identify color of marble.

Algorithm 1:
First I take out one marble from the basket. Oh, it is red color. Then I jot down on my book. Then I find got red color or not in the basket. If got red all take out... Now, the basket no red color marble because I took it all got. In my list got mark red color. After that I take other marble from the basket. Oh blue color. Then I jot down to my book. Then I find all blue color marble then take it out all of then which is blue. Then continue until no marbe in the basket.

In short, in list? No put it in list then go to the basket find all the same color one then throw away.

Algorithm 2
First I take out one marble from the basket. Oh, it is red color. Then I jot down on my book. When I take the second marble. I will compare with my list. If is in my list I will take it out. If not in my list I will jot it down then take it away. This will continue until no marble in the basket.

In short, in list? No put it in list then throw away. Yes then throw away.

May I know have any tool to simulate which algorithm is the best and fastest?

Thank you

This post has been edited by fsloke: 23 Aug, 2008 - 12:30 AM
User is offlineProfile CardPM
+Quote Post

JeroenFM
RE: Got Any Tool To Simulate Our Coding Is Effective?
23 Aug, 2008 - 05:49 AM
Post #2

D.I.C Head
Group Icon

Joined: 30 Jun, 2008
Posts: 191



Thanked: 9 times
Dream Kudos: 100
My Contributions
QUOTE(fsloke @ 23 Aug, 2008 - 01:25 AM) *

Here is the situation or problem raise
You have a basket of marble. Your task is to identity got how many color in the basket.

I prepare a small note book to jot down the identify color of marble.

Algorithm 1:
First I take out one marble from the basket. Oh, it is red color. Then I jot down on my book. Then I find got red color or not in the basket. If got red all take out... Now, the basket no red color marble because I took it all got. In my list got mark red color. After that I take other marble from the basket. Oh blue color. Then I jot down to my book. Then I find all blue color marble then take it out all of then which is blue. Then continue until no marbe in the basket.

In short, in list? No put it in list then go to the basket find all the same color one then throw away.

Algorithm 2
First I take out one marble from the basket. Oh, it is red color. Then I jot down on my book. When I take the second marble. I will compare with my list. If is in my list I will take it out. If not in my list I will jot it down then take it away. This will continue until no marble in the basket.

In short, in list? No put it in list then throw away. Yes then throw away.

May I know have any tool to simulate which algorithm is the best and fastest?

Thank you


I don't know of any tools, but you could of course just calculate the computational complexity. Both algorithms have the same worst case complexity (number of marbles times number of colors), but on average case your second algorithm would be better, as the list of colors is usually shorter than the number of marbles, and you only iterate through the marbles once, and through colors multiple times.

User is offlineProfile CardPM
+Quote Post

Gloin
RE: Got Any Tool To Simulate Our Coding Is Effective?
23 Aug, 2008 - 08:58 AM
Post #3

Expert Schmexpert...
Group Icon

Joined: 4 Aug, 2008
Posts: 934



Thanked: 54 times
My Contributions
Sounds like a sorting problem. If you define(represent) each color as a number. Then by sorting them (O(n log n)) and then go through the list and remove multiples (O(n)), you should be able to solve this problem without getting too high complexity.

This post has been edited by Gloin: 23 Aug, 2008 - 08:58 AM
User is offlineProfile CardPM
+Quote Post

fsloke
RE: Got Any Tool To Simulate Our Coding Is Effective?
23 Aug, 2008 - 08:21 PM
Post #4

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
Sometime Arrangement are important...

FOr this case not...

I just want to find a tool to do statistic to test which code is most suitable...

Thank you
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:08AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month