CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    9

    The Best Structure

    Hi,
    What is the Best Structure for this goal!
    the Add function in O(n) and fetch-meddian in O(1)?
    Thanks!

  2. #2
    Join Date
    Sep 2004
    Location
    Tehran(Ir)
    Posts
    469

    Re: The Best Structure

    a min-max heap!



    its add would take O(n) but for finding its Meddian you should pick the max and min number and divide them on 2 which would take in O(1)
    //I'm not sure what is your meaning from fetch-median?

  3. #3
    Join Date
    Jun 2002
    Location
    Moscow, Russia.
    Posts
    2,176

    Re: The Best Structure

    What is add function complexity? if it's one of adding of just one element, you can as well use simple sorted array, inserting new element by bubble sort and picking median as center element of that array.
    "Programs must be written for people to read, and only incidentally for machines to execute."

  4. #4
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    Re: The Best Structure

    I read it the same way as Robotact. A sorted array seems like the easiest solution.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured