Jump to content

Serial Searching in Java

kleanthisky

I have a project to create a java program.

I created a RandomAccessFile of 10million integers (from 1-10000000 sorted)

 

I have to use it as a drive and load 512 bytes(128 ints) into a buffer and then binary searching in this buffer to find a key.

 

how long would it take to serial search 10000 random keys in that file???

 

if it has anything to do with it im on a 3.6Ghz cpu

Link to comment
Share on other sites

Link to post
Share on other sites

You could get time stamp before algorithm processes numbers. Then get another time stamp after it processed.

timeStamp2 - timeStamp1 = timeTook

 

You could convert the timestamp then to whatever format you like.

 

And yeah it depends on processor.

Link to comment
Share on other sites

Link to post
Share on other sites

32 minutes ago, bigneo said:

You could get time stamp before algorithm processes numbers. Then get another time stamp after it processed.

timeStamp2 - timeStamp1 = timeTook

 

You could convert the timestamp then to whatever format you like.

 

And yeah it depends on processor.

would be faster is you could parallel process the numbers. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

34 minutes ago, bigneo said:

You could get time stamp before algorithm processes numbers. Then get another time stamp after it processed.

timeStamp2 - timeStamp1 = timeTook

 

You could convert the timestamp then to whatever format you like.

 

And yeah it depends on processor.

 

Just now, vorticalbox said:

would be faster is you could parallel process the numbers. 

 

My problem is not the time it would take. I tried it and it took about 20 mins.

 

the problem is that even the professor told us it would take 1 hour +

it took 20 mins on my pc while cpu usage was 25%, other guys did it in 1+ hour with 8% cpu usage. 

Link to comment
Share on other sites

Link to post
Share on other sites

There's no way to know how long a piece of code will take to run on a given machine, that's what benchmarking is for. You can do a theoretical analysis of your algorithm and determine it's time complexity (if you know how) however that can only tell you so much.

 

The differences between your time and your teachers/the other guys could be because

  • Your hardware is faster
  • Your algorithm is better
  • Your algorithm is wrong (ie: it's not doing stuff it's supposed to do, making it seem faster)
  • etc

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

15 minutes ago, madknight3 said:

There's no way to know how long a piece of code will take to run on a given machine, that's what benchmarking is for. You can do a theoretical analysis of your algorithm and determine it's time complexity (if you know how) however that can only tell you so much.

 

The differences between your time and your teachers/the other guys could be because

  • Your hardware is faster
  • Your algorithm is better
  • Your algorithm is wrong (ie: it's not doing stuff it's supposed to do, making it seem faster)
  • etc

 

 

from the post to seems to searches all numbers to find a key, could be that the op key as lower in the list. Might also be that the teachers doesn't stop when it finds the key but continues though all numbers. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

16 minutes ago, vorticalbox said:

from the post to seems to searches all numbers to find a key, could be that the op key as lower in the list. Might also be that the teachers doesn't stop when it finds the key but continues though all numbers. 

 

Agree to you, OP said he is using binary search and if i remember correct additional flag check in binary search can jump out of the loop.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×