Re: [algogeeks] Microsoft Interview Question

2012-06-14 Thread nadeem khan
how to do it in space comp- O(1)  . I mean without using additional arrays.
Could it be done ?

On Thu, Jun 14, 2012 at 3:46 PM, utsav sharma utsav.sharm...@gmail.comwrote:

 @all :- by segregating 0 and 1 or by taking quicksort approach
 we have to swap no.s resulting which array becomes unordered.

 my approach is start from right and  if a negative no. occurs insert it
 into another array temp[]
 this will shift all positive no.s to right and in 2nd pass start from left
 of original array and insert all the elements of temp.
 time comp-O(n), space comp-O(n)
 correct me if i am wrong

 On Thu, Jun 14, 2012 at 1:53 PM, saurabh singh saurab...@gmail.comwrote:

 Order may not be maintained necessarily by this solution

 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT
 blog:geekinessthecoolway.blogspot.com



 On Thu, Jun 14, 2012 at 1:47 PM, Manikanta Babu 
 manikantabab...@gmail.com wrote:

 Check this out, it works in O(n);

 int i = 0;
 int j = n-1;

 while((in  j= 0)(ij))
 {
 if(a[i]0  a[j]0)
 {
 swap(a[i],a[j]);
 i++; j--;
 }
 else
 {
 if(a[i]0)
 i++;
 if(a[j]0)
 j--;
 }

 }

 Thanks,
 Mani

 On Thu, Jun 14, 2012 at 1:05 PM, Mad Coder imamadco...@gmail.comwrote:


 As nothing is written about space complexity, I am assuming that we can
 take extra space.

 Take a temporary array of length n.

 1. Maintain a counter for the length of temporary array filled till now.

 2. Traverse the given array. If value contained is negative insert it
 in new array and update counter. After complete traversal all negative
 values will be in the temporary array.

 3. Traverse again the given array. Repeat step 2 but this time for
 positive numbers.

 Finally temporary array contains the required answer. If required copy
 it into original array.

 As this approach takes max. 3 traversals so its complexity is O(n).

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Thanks  Regards,
 Mani
 http://www.sanidapa.com - The music Search engine

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Utsav Sharma,
 NIT Allahabad

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Can anyone explain this strange behavior ?

2012-06-12 Thread nadeem khan
i=-3  it gets incremented to -2 (++i)
m is evaluated and as ++i is non zero it evaluates to TRUE and m is
assigned value 1,  hence remaining part is not executed , so j and k is not
incremented.

On Tue, Jun 12, 2012 at 2:19 AM, Dave dave_and_da...@juno.com wrote:

 This is the result of short-circuit evaluation. See, e.g.,
 http://en.wikipedia.org/wiki/Short-circuit_evaluation, or this topic in
 your language reference.

 Dave

 On Monday, June 11, 2012 2:28:52 PM UTC-5, ((** VICKY **)) wrote:

 #includestdio.hint main(){int i,j,k,m,l;
 i=-3;
 j=2;
 k=0;m=++i || ++j  ++k ;printf 
 http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(\n%d 
 %d %d %d,i,j,k,m);return 0;}

 o/p: -2 2 0 1


 k should be 1 right


 --
 Cheers,

   Vicky

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/8PoAya7NqjYJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] If any one have algorithms for interviews by adnan aziz ebook... Please mail ...

2012-06-07 Thread nadeem khan
please share the link !!

On Thu, Jun 7, 2012 at 3:01 PM, Abhishek Sharma abhi120...@gmail.comwrote:

 yes,it is helpful,but read it only if u have fully understood
 Introduction to algorithms or if u have strong foundation of
 algorithms/data structures


 On Thu, Jun 7, 2012 at 12:37 PM, BUBUN SHEKHAR dce.stu...@gmail.comwrote:

 Guys is this book useful for cracking interviews??

 On Mon, Jun 4, 2012 at 1:31 AM, Dhaval Moliya moliyadha...@gmail.comwrote:

 If any one have algorithms for interviews by adnan aziz ebook... Please
 mail ...
 Thanks

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Abhishek Sharma
 Under-Graduate Student,
 PEC University of Technology

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.