Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how can i do this in o(n)

Reply
Thread Tools

how can i do this in o(n)

 
 
kitts
Guest
Posts: n/a
 
      09-14-2005
A given array of size 2n with n elements in sorted order. Another array
with size n & n elements in it in sorted order. Merge the two arrays &
final array should be in sorted order without using extra memory

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      09-14-2005
In article < om>,
kitts <> wrote:
>A given array of size 2n with n elements in sorted order. Another array
>with size n & n elements in it in sorted order. Merge the two arrays &
>final array should be in sorted order without using extra memory


That sounds like an assignment question.

How does one know where the n elements are in the array of size 2n ?
The question as stated does -not- indicate that the n elements
are at the beginning of the array, nor that the n elements are
evenly distributed -- only that the elements are in order.

--
"Never install telephone wiring during a lightning storm." -- Linksys
 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      09-14-2005
kitts wrote:
> A given array of size 2n with n elements in sorted order. Another array
> with size n & n elements in it in sorted order. Merge the two arrays &
> final array should be in sorted order without using extra memory


Not today. Post your instructor's name and email address, and I'm sure
someone will be glad to send him an answer to your demand.
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      09-14-2005
(Subject line: "how can i do this in o(n)")

kitts said:

> A given array of size 2n with n elements in sorted order. Another array
> with size n & n elements in it in sorted order. Merge the two arrays &
> final array should be in sorted order without using extra memory


Consider writing a C function to do it. Post your best-effort code if you
get stuck.Here's an algorithm hint, using playing cards (E means "empty
slot"):

A 5 6 9 E E E E

2 7 8 K

You can compare the last card in each deck, and move the highest value card
out of those two to the last empty slot in the upper deck. Then compare
whichever card "lost" the previous comparison to the last card in the other
deck that has not yet been shoved into all that lovely space at the back.


--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/2005
http://www.cpax.org.uk
email: rjh at above domain
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      09-14-2005
"kitts" <> writes:

[ Subject: how can i do this in o(n) ]
> A given array of size 2n with n elements in sorted order. Another array
> with size n & n elements in it in sorted order. Merge the two arrays &
> final array should be in sorted order without using extra memory


I don't think this problem is solvable in o(n) time.
I think it should be solvable in O(n).
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
 
Reply With Quote
 
Christian Bau
Guest
Posts: n/a
 
      09-14-2005
In article < om>,
"kitts" <> wrote:

> A given array of size 2n with n elements in sorted order. Another array
> with size n & n elements in it in sorted order. Merge the two arrays &
> final array should be in sorted order without using extra memory


Not possible in o (n).
Trivial in O (n).
 
Reply With Quote
 
August Karlstrom
Guest
Posts: n/a
 
      09-15-2005
kitts wrote:
> A given array of size 2n with n elements in sorted order. Another array
> with size n & n elements in it in sorted order.


An array of n elements of which n elements are sorted... sounds like a
(fully) sorted array!?


August
 
Reply With Quote
 
Alan Balmer
Guest
Posts: n/a
 
      09-15-2005
On Thu, 15 Sep 2005 00:20:23 GMT, August Karlstrom
<> wrote:

>kitts wrote:
>> A given array of size 2n with n elements in sorted order. Another array
>> with size n & n elements in it in sorted order.

>
>An array of n elements of which n elements are sorted... sounds like a
>(fully) sorted array!?
>

Yes. There is some question about the composition of the other array,
however.
--
Al Balmer
Balmer Consulting

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Can Groovy be used in an applet and/or can it generate the Java bytecodes that then can be used in an applet? Casey Hawthorne Java 1 03-18-2009 12:56 AM
Word Docs Won't Open, Can't Be E-Mailed, Can't Be Deleted, Can't Be Copied, Etc. Martin Computer Support 16 02-24-2009 07:35 PM
Wireless can get internet but can't see network -- can when wired 02befree Computer Support 0 12-24-2007 09:10 PM
SOLVED - can't open file in windows media player / WMP. But can in VLC - video LAN .. Now can in WMP jameshanley39@yahoo.co.uk Computer Information 2 09-19-2007 02:53 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57