Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,241 members, 7,818,824 topics. Date: Monday, 06 May 2024 at 05:55 AM

Another Programming Challenge - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / Another Programming Challenge (2204 Views)

Programming Challenge For Beginners Competition Two N20000 -SEASON 2- / Programming Challenge For Beginners N20000 / Facebook Programming Challenge Question (2) (3) (4)

(1) (2) (Reply) (Go Down)

Re: Another Programming Challenge by mkwayisi: 5:32pm On Sep 29, 2012
@lordZouga: Once will never be enough unless you're coming up with a breakthrough algorithm. Let me ask, have you tried implementing what you're thinking? If not try it!
Re: Another Programming Challenge by ektbear: 7:30pm On Sep 29, 2012
₱®ÌИСΞ:


Hahaha lol...thnx for dat...I imagined the possibility of dat occuring in a HUGE file was near impossible so I guess my mind didn't go there...lemme fix it

Indeed, if N is big, and K relatively small, then this is pretty unlikely to happen. This was the subtle issue I alluded to in my first post. But it is pretty easy to fix (just reject a random number it is already in your list).
Re: Another Programming Challenge by ektbear: 7:31pm On Sep 29, 2012
lordZOUGA:
it will take O(N)... This would be nice but your algorithm suggested doing it twice when in my opinion, once would be enough.
Yea most languages has internal buffer... C++ has the internal buffer object stream_buf that is created for every I/O operation

If you don't know N, I think that it is impossible to do it in one pass.

You have to know N to generate the K random row #s correctly. And the only way to know N is to pass through the file once.
Re: Another Programming Challenge by uzoexcel(m): 5:22pm On Jul 18, 2014
OFDM? grin grin grin

(1) (2) (Reply)

Your Advice For A Beginner Database Administrator? / Please, I Need A Step-by-step Tutorial For Developing Android Apps / Help With C# Code

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.