Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Friday's Coding Challenge

Friday's Coding Challenge

Scheduled Pinned Locked Moved The Lounge
c++algorithmsarchitectureperformancehelp
48 Posts 22 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chris Maunder
    wrote on last edited by
    #1

    Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

    cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

    N N V C J 14 Replies Last reply
    0
    • C Chris Maunder

      Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

      cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      Chris Maunder wrote:

      ASM gets you Man Points.

      And brainfuck? Do we get points for using brainfuck?


      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

      G 1 Reply Last reply
      0
      • C Chris Maunder

        Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

        cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

        V Offline
        V Offline
        Vikram A Punathambekar
        wrote on last edited by
        #3

        Programming questions don't belong in the Lounge! ;P

        Cheers, विक्रम "We have already been through this, I am not going to repeat myself." - fat_boy, in a global warming thread :doh:

        N C H S 4 Replies Last reply
        0
        • C Chris Maunder

          Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

          cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

          N Offline
          N Offline
          NormDroid
          wrote on last edited by
          #4

          Caching with a latency (decay) value, and a watchdog timer to purge the cache, simple enough to whip up even in assembler, unfortunately its friday and the last thing on my mind this weekend is coding.

          Software Kinetics Wear a hard hat it's under construction
          Metro RSS

          C 1 Reply Last reply
          0
          • V Vikram A Punathambekar

            Programming questions don't belong in the Lounge! ;P

            Cheers, विक्रम "We have already been through this, I am not going to repeat myself." - fat_boy, in a global warming thread :doh:

            N Offline
            N Offline
            NormDroid
            wrote on last edited by
            #5

            Vikram A Punathambekar wrote:

            Programming homework questions don't belong in the Lounge

            ;)

            Software Kinetics Wear a hard hat it's under construction
            Metro RSS

            1 Reply Last reply
            0
            • V Vikram A Punathambekar

              Programming questions don't belong in the Lounge! ;P

              Cheers, विक्रम "We have already been through this, I am not going to repeat myself." - fat_boy, in a global warming thread :doh:

              C Offline
              C Offline
              Chris Maunder
              wrote on last edited by
              #6

              Read the fine print here[^]. :|

              cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

              Richard Andrew x64R V 2 Replies Last reply
              0
              • N NormDroid

                Caching with a latency (decay) value, and a watchdog timer to purge the cache, simple enough to whip up even in assembler, unfortunately its friday and the last thing on my mind this weekend is coding.

                Software Kinetics Wear a hard hat it's under construction
                Metro RSS

                C Offline
                C Offline
                Chris Maunder
                wrote on last edited by
                #7

                How do you set the decay value? It's non-deterministic.

                cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                N 1 Reply Last reply
                0
                • C Chris Maunder

                  How do you set the decay value? It's non-deterministic.

                  cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                  N Offline
                  N Offline
                  NormDroid
                  wrote on last edited by
                  #8

                  Arbitary found out during testing to get the *best* size for the cache.

                  Software Kinetics Wear a hard hat it's under construction
                  Metro RSS

                  C N 2 Replies Last reply
                  0
                  • N NormDroid

                    Arbitary found out during testing to get the *best* size for the cache.

                    Software Kinetics Wear a hard hat it's under construction
                    Metro RSS

                    C Offline
                    C Offline
                    Chris Maunder
                    wrote on last edited by
                    #9

                    The size of the cache would depend on the decay time. The problem says there is around 1000 common lookups, but it doesn't define for how long these items stay common. Could be a minute. Could be an hour. Could be a second.

                    cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                    1 Reply Last reply
                    0
                    • N NormDroid

                      Arbitary found out during testing to get the *best* size for the cache.

                      Software Kinetics Wear a hard hat it's under construction
                      Metro RSS

                      N Offline
                      N Offline
                      Nagy Vilmos
                      wrote on last edited by
                      #10

                      Allow it to be self sizing. Fixed limit, 1k as Chris indicated, and up to that limit just test how often you're reading from disk vs retrieving from cache. If we're talking in the order of a million records we could maybe even hold a token for each record, or block or records, to determine if we're caching too much or too little.


                      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                      1 Reply Last reply
                      0
                      • V Vikram A Punathambekar

                        Programming questions don't belong in the Lounge! ;P

                        Cheers, विक्रम "We have already been through this, I am not going to repeat myself." - fat_boy, in a global warming thread :doh:

                        H Offline
                        H Offline
                        hairy_hats
                        wrote on last edited by
                        #11

                        It's a "challenge", not a "question". ;)

                        1 Reply Last reply
                        0
                        • V Vikram A Punathambekar

                          Programming questions don't belong in the Lounge! ;P

                          Cheers, विक्रम "We have already been through this, I am not going to repeat myself." - fat_boy, in a global warming thread :doh:

                          S Offline
                          S Offline
                          Simon_Whale
                          wrote on last edited by
                          #12

                          I like these Challenges as they give me a chance to try something beyond what I do at work! I would also like to see what the possible answer could be too

                          Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

                          C 1 Reply Last reply
                          0
                          • C Chris Maunder

                            Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

                            cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                            C Offline
                            C Offline
                            Chris Losinger
                            wrote on last edited by
                            #13

                            i'd try it with a fixed-size double-ended list. get a request for A check the list for A, starting at the 'front' if A is in the list, move it to the front if A isn't in the list add it to the front of the list if you just added and the list has more than N items, pull the item off the back end, and discard. frequently-used items will stay near the front of the list. infrequently-used items will get pushed out, eventually. (you could probably also do this with a circular buffer.)

                            image processing toolkits | batch image processing

                            M T 2 Replies Last reply
                            0
                            • C Chris Maunder

                              Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

                              cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                              J Offline
                              J Offline
                              jesarg
                              wrote on last edited by
                              #14

                              This suspiciously sounds like you want us to do your work for you. Academic, programming-competition-style questions are more fun, imo.

                              C 1 Reply Last reply
                              0
                              • J jesarg

                                This suspiciously sounds like you want us to do your work for you. Academic, programming-competition-style questions are more fun, imo.

                                C Offline
                                C Offline
                                Chris Maunder
                                wrote on last edited by
                                #15

                                :rolleyes: I'm pulling out small puzzles we have already solved and that I enjoyed solving. It's easier for me to pose a question that I have already solved (at least to a point where it works sufficiently) than to rip off programming challenges from other sites and books that people can simply Google to get the answer to. So how about a different challenge for you: come up with your own programming challenge.

                                cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                J A 2 Replies Last reply
                                0
                                • C Chris Maunder

                                  Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

                                  cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                  P Offline
                                  P Offline
                                  PIEBALDconsult
                                  wrote on last edited by
                                  #16

                                  Are you sure it's a bottleneck? Have you tried throwing more hardware at it? Have you tried a specialized Spell Check Tree? :-D I'm not a big fan of caching dynamic sets of data. I'd simply let SQL Server figure it out. Edit:

                                  Chris Maunder wrote:

                                  a trillion name/value pairs

                                  On the long scale? Or the short scale?

                                  1 Reply Last reply
                                  0
                                  • C Chris Maunder

                                    Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

                                    cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                    W Offline
                                    W Offline
                                    wout de zeeuw
                                    wrote on last edited by
                                    #17

                                    I'd make a trillion web pages and let google index them, and then use google to lookup the result. ;P

                                    Wout

                                    1 Reply Last reply
                                    0
                                    • C Chris Maunder

                                      Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

                                      cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                      N Offline
                                      N Offline
                                      Nish Nishant
                                      wrote on last edited by
                                      #18

                                      When I worked on an app that needed to cache the most recently/frequently used media files (large videos/PNGs), what I did was to write a cache-manager that promoted items to a higher rank based on the frequency of access as well as considered most-recently-accessed-time as a factor. I don't remember if I kept the size of the cache fixed. That was not RDBMS-based (at that time) and used a custom binary data format (large GB+ files). BTW, Rama and I tried to get these programming discussions going here in the past. After getting poor responses (mostly humor), we tried to do it in GIT (where it got more attention), but later GITians lost interest too. Kinda ironic that the guys who are most likely to have tried to respond to these threads don't post here all that much anymore (Rama, John, Shog, CG).

                                      Regards, Nish


                                      My technology blog: voidnish.wordpress.com

                                      S 1 Reply Last reply
                                      0
                                      • C Chris Maunder

                                        Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

                                        cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #19

                                        How about a fully associative LRU cache of "around" 1000 entries?

                                        1 Reply Last reply
                                        0
                                        • C Chris Maunder

                                          Here's a more involved problem that is suitable for a lazy Friday afternoon. Suppose you have a table (or other structure) that stores a trillion name/value pairs. You need to look up values from this table millions of times as fast as possible, but you don't have enough memory to simply store the table in memory. One thing you do notice, though, is that the same values tend to be requested multiple times over short periods of time. So for 1 minute you may only be accessing 1000 values, repeatedly, then another minute - or hour (who knows) - you may be accessing an entirely different set of 1000 values. You can't cache the entire table. The challenge is to provide a caching algorithm that will automatically adapt to the changing subset of values being requested. Pseudo code is fine but ASM gets you Man Points.

                                          cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                                          A Offline
                                          A Offline
                                          Andrew Rissing
                                          wrote on last edited by
                                          #20

                                          This sounds oddly like something for CodeProject. Are you trying to cut overhead costs by outsourcing to the people who visit this site? :D Diabolical! [Edit: Ha...sounds like I wasn't the first to think such[^].]

                                          P 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups