Results 1 to 2 of 2
  1. #1
    jamalraihan is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default Find two elements in an array that sum to k

    Given : An unsorted array A of integers
    Input : An integer k

    A = {3,4,5,1,4,2}

    Input : 6
    Output : {5,1}, {4,2}

    How can I do this in O(n) or O(log n). Any suggestions will be appreciated.
    Last edited by jamalraihan; 12-04-2011 at 06:24 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Find two elements in an array that sum to k

    Can you find any or all such pairs at all? But what algorithm and how many operations does it take?

    O(log n) would be a neat trick. What do you mean by the expression "O(log n)"?

Similar Threads

  1. Swapping elements of an array help please
    By ikillu in forum New To Java
    Replies: 11
    Last Post: 01-15-2012, 09:49 PM
  2. Replies: 3
    Last Post: 11-25-2011, 01:38 AM
  3. keep the first N elements of an array only
    By aneuryzma in forum New To Java
    Replies: 13
    Last Post: 03-27-2011, 05:03 PM
  4. sum of elements in array
    By myst in forum New To Java
    Replies: 7
    Last Post: 07-17-2010, 09:36 AM
  5. Help with array of elements
    By zoe in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 06:33 PM

Tags for this Thread

Posting Permissions

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