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. General Programming
  3. Design and Architecture
  4. Top 100 algorithm

Top 100 algorithm

Scheduled Pinned Locked Moved Design and Architecture
questionalgorithms
3 Posts 3 Posters 8 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.
  • M Offline
    M Offline
    mike7411
    wrote on last edited by
    #1

    Let's say you need to find the top 100 best-selling books out of a list of a million books. What is the appropriate algorithm? I thought it would be QuickSelect, but that only chooses one item. Thank you.

    L P 2 Replies Last reply
    0
    • M mike7411

      Let's say you need to find the top 100 best-selling books out of a list of a million books. What is the appropriate algorithm? I thought it would be QuickSelect, but that only chooses one item. Thank you.

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

      You first need the list sorted in order.

      1 Reply Last reply
      0
      • M mike7411

        Let's say you need to find the top 100 best-selling books out of a list of a million books. What is the appropriate algorithm? I thought it would be QuickSelect, but that only chooses one item. Thank you.

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        If you don't want to sort the list, for whatever reason, you could always use a Max Heap structure with a heap size of 100. Iterate over your books and, if the new book has higher sales than a book in the heap, replace the bottom element with the new one. This assumes that no two book sales are going to be the same, so you would have to consider that particular wrinkle. In .NET for instance, you can use the PriorityQueue class to handle max heaps.

        Advanced TypeScript Programming Projects

        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