Thread: find the k'th smallest in two arrays algorithm(psedo code)

  1. #16
    Registered User
    Join Date
    Nov 2011
    Posts
    26
    you are not specific at all

    have
    you read my posts so far
    ?

  2. #17
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by henri View Post
    you are not specific at all

    have
    you read my posts so far
    ?
    Ok, let me put this bluntly in the hope that you'll understand...

    What you wrote makes no sense whatsoever. It's nonsense.

    Understand?

  3. #18
    Registered User
    Join Date
    Nov 2011
    Posts
    26
    i have two arrays ,each of size n, which are sorted.

    write an algorithm that finds the k'th smallest amongst the array of size 2n which is the resolt of sticking those two together

    in O(lg min (k,2n-k))



    i have this idea of how to solve it.





    in the added picture

    i find the k smallest of array A by A[k] and k smallest of array B by B[k]



    and the k smallest of the sum is between those
    k1 and k2


    in my photo k2>k1



    i wrote the following function but i dont know how to know if i got the k'th smallest in the recurtion.and i am not sure abiut the sub arrays ranges in the recursive calls
    Code:
    Mikum(A,q,r)
    
    k1=A[k/2]
    
    k2=B[k/2]
    
    If (x>y)
    
    Mikum(A,k, n)
    
    Mikum(B,0 ,k)
    http://i42.tinypic.com/1192yl5.png
    Last edited by henri; 12-13-2011 at 04:37 PM.

  4. #19
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Reposting the same garbage isn't going to make it any clearer...



    Why don't you just find the kth smallest in each array and take the smaller of the two?

    It sounds like you have two sorted arrays... ok now you need to find, for example, the 8th smallest number in each array... Well if they're sorted that's automatically the 8th element in each.

    Then to choose between them you just need something extremely simple like this...
    Code:
    ksmall = (array1[k] < array2[k]) ? array1[k] : array2[k];
    But your definition of the problem is so confused that I'm just guessing.
    Last edited by CommonTater; 12-13-2011 at 04:34 PM.

  5. #20
    Registered User
    Join Date
    Nov 2011
    Posts
    26
    i have change my original posts and added description .

    common man you are totally insoltive and clearly lack the knowledge about time complexity

    pls stop waisting my and your time with posting in a trolling matter uselless insoltive remarks

    i hope laserlight or adak will help me

  6. #21
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Oh my... the guy who cannot define a problem is calling me stupid...

    Now that's a hoot.

  7. #22
    Registered User
    Join Date
    Nov 2011
    Posts
    26
    Commnotater stop posting in this thread


    i have two arrays ,each of size n, which are sorted.

    write an algorithm that finds the k'th smallest amongst the array of size 2n which is the resolt of sticking those two together

    in O(lg min (k,2n-k))



    i have this idea of how to solve it.





    in the added picture

    i find the k smallest of array A by A[k] and k smallest of array B by B[k]



    and the k smallest of the sum is between those
    k1 and k2


    in my photo k2>k1



    i wrote the following function but i dont know how to know if i got the k'th smallest in the recurtion.and i am not sure abiut the sub arrays ranges in the recursive calls
    Code:
    Mikum(A,q,r)
    
    k1=A[k/2]
    
    k2=B[k/2]
    
    If (x>y)
    
    Mikum(A,k, n)
    
    Mikum(B,0 ,k)
    http://i42.tinypic.com/1192yl5.png
    Last edited by henri; 12-13-2011 at 04:51 PM.

  8. #23
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by henri View Post
    Commnotater stop posting in this thread
    Ok... when you tell us what...

    write an algorithm that finds the k'th smallest amongst the array of size 2n which is the resolt of sticking those two together
    ... "the result of sticking those two together" means...

    End to end?
    Side by side?

    Merging sums?

    Sorted?
    Unsorted?


    What????

    As I told you 3 times already... the reason you're not getting good help is that your description of the problem is meaningless.


    Oh... and BTW... trying to order me around almost always has the exact opposite of the desired effect.

  9. #24
    Registered User
    Join Date
    Nov 2011
    Posts
    26
    ok i have reported your posts to the admin

    and i will keep posting my question

    in the end on top of your trolling posts
    Last edited by henri; 12-13-2011 at 04:50 PM.

  10. #25
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    It's clear that the OP means concatenating the arrays when s/he demonstrated that the 2 arrays:
    1,2,3
    and
    4,5,5

    ...could result in:
    1,2,3,4,5,6
    or
    4,5,6,1,2,3

    It's not hard to figure out that the arrays are just being concatenated in arbitrary order and that's what s/he means by "sum" or "sticking them together".

    There. Mystery solved. Now you can move onto a solution that fits the big-O criteria.
    If you understand what you're doing, you're not learning anything.

  11. #26
    Registered User
    Join Date
    Nov 2011
    Posts
    26
    itsme86

    the problem is findind the k'smallest in the big 2n array

    i know that its between k1 and k2 where k2>k1

    so i did recursive calls is the code to look the areas from index of 0 till k1

    and another recursive call fron 2n-k

    understand?
    Last edited by henri; 12-13-2011 at 04:57 PM.

  12. #27
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Nobody can possibly understand what you're tying to do, because your explanations of the problem are so hopelessly nonsensical and confusing, and we told you this. You probably can't write a coherent description of the problem because it is not clear in your own head. Nobody can code a solution to a problem they don't understand. We told you that, too.

    What you should have done from that point is take a step back, thought about the problem, tried to understand what the question is. Then you could have come back with a more understandable question and we'd be able to help you.

    Instead, what you did is call people stupid, reject their advice, and copy and paste the same pointless incomprehensible crap you've posted from the beginning

    We are all volunteers here. We owe you nothing. And that's all you'll get from us with that attitude.



    Edit- Wow. You seriously reported Tater to the mods for being a troll? Seriously?

    Get lost, henri. Just go away.
    Code:
    while(!asleep) {
       sheep++;
    }

  13. #28
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    What you need...is a crash course in this .

    Quote Originally Posted by itsme86 View Post
    There. Mystery solved. Now you can move onto a solution that fits the big-O criteria.

    AFAIK....
    This is a merge sort... after deciding in which direction to do it.
    Last edited by manasij7479; 12-13-2011 at 04:59 PM.

  14. #29
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by henri View Post
    ok i have reported your posts to the admin

    and i will keep posting my question

    in the end on top of your trolling posts
    Gee thanks... I'm sure we'll have a good chuckle over this one!

  15. #30
    Registered User
    Join Date
    Nov 2011
    Posts
    26
    the problem is findind the k'smallest in the big 2n array

    i know that its between k1 and k2 where k2>k1

    so i did recursive calls is the code to look the areas from index of 0 till k1

    and another recursive call fron 2n-k

    understand?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging two heaps in psedo code
    By henri in forum C Programming
    Replies: 2
    Last Post: 11-22-2011, 11:49 AM
  2. Replies: 6
    Last Post: 09-23-2010, 10:12 PM
  3. recursive find of the smallest member..
    By transgalactic2 in forum C Programming
    Replies: 35
    Last Post: 01-13-2009, 09:21 AM
  4. need to find smallest int
    By lankeveil in forum C Programming
    Replies: 3
    Last Post: 11-30-2008, 05:48 AM
  5. Find the Largest and Smallest Number
    By Nightsky in forum C Programming
    Replies: 27
    Last Post: 09-04-2006, 03:40 PM