Results 1 to 2 of 2

Thread: Help with an algorithm design problem

  1. #1
    Senior Member PJ's Avatar
    Join Date
    Jan 2002
    Posts
    18,425

    Default Help with an algorithm design problem

    The problem states: You are given an unsorted list of n−1 distinct integers from the range 1 to n. Write a linear-time algorithm to find the missing integer.

    For example, you have the list of integers from 1 - 5, with the number 4 missing. So you could have: 3, 1, 5, 2. You are to find that the missing number is 4, in 5 or fewer comparisons.

    Is it possible to solve this problem in linear time O(n)? I can certainly think of a way to do it in n^2 time, but I'm stuck on linear time...

    Any help or hint would be appreciated.
    忽见柳荫下两个小孩子在哀哀痛哭,瞧模样正是武敦儒、武修文兄弟。郭芙大声叫道:「喂,你们在干甚麽?」武 修文回头见是郭芙,哭道:「我们在哭,你不见麽?」

  2. #2
    Member
    Join Date
    May 2003
    Posts
    159

    Default

    Are you allowed to do computations? You can sum up the values and get the difference from n(n+1)/2.

Similar Threads

  1. Design your own martial art
    By aniking_8 in forum Wuxia Fiction
    Replies: 30
    Last Post: 02-24-10, 02:06 AM
  2. 9 Yum Jen Ging's healing techniques: design flaws?
    By Ken Cheng in forum Wuxia Fiction
    Replies: 45
    Last Post: 02-25-09, 02:27 AM
  3. Design your ELOC version of Novel endings
    By PJ in forum Wuxia Fiction
    Replies: 12
    Last Post: 12-24-07, 03:06 PM
  4. Science peeps: Research design help needed
    By levendis d'orange in forum Academia
    Replies: 4
    Last Post: 06-20-07, 10:30 PM

Posting Permissions

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