Re: [algogeeks] You are given two 32-bit numbers, N and M, and two bit positions, i and j.

2012-10-31 Thread atul anand
check out my comment ...i had posted it log time back on
geekforgeeks...search for atull007 int the below link.
let me know it does not work
http://www.geeksforgeeks.org/forum/topic/adobe-interview-question-for-software-engineerdeveloper-fresher-about-bit-magic-1

On Thu, Nov 1, 2012 at 4:00 AM, rahul sharma wrote:

> You are given two 32-bit numbers, N and M, and two bit positions, i and j.
> Write a method to set all bits between i and j in N equal to M (e.g., M
> becomes a substring of N located at i and starting at j).
> EXAMPLE:
> Input: N = 100, M = 10101, i = 2, j = 6
> Output: N = 10001010100
>
> Following is code...guys i think that in line no. 5  (1< be replaced with (1< no. 5 should be
>  int left = max - ((1 << j+1) - 1);
> plz comment ???
>
> public static int updateBits(int n, int m, int i, int j) {
> 2 int max = ~0; /* All 1’s */
> 3
> 4 // 1’s through position j, then 0’s
> 5 int left = max - ((1 << j) - 1);
> 6
> 7 // 1’s after position i
> 8 int right = ((1 << i) - 1);
> 9
> 10 // 1’s, with 0s between i and j
> 11 int mask = left | right;
> 12
> 13 // Clear i through j, then put m in there
> 14 return (n & mask) | (m << i);
> 15 }
>
> --
> 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.



[algogeeks] You are given two 32-bit numbers, N and M, and two bit positions, i and j.

2012-10-31 Thread rahul sharma
You are given two 32-bit numbers, N and M, and two bit positions, i and j.
Write a method to set all bits between i and j in N equal to M (e.g., M
becomes a substring of N located at i and starting at j).
EXAMPLE:
Input: N = 100, M = 10101, i = 2, j = 6
Output: N = 10001010100

Following is code...guys i think that in line no. 5  (1

Re: [algogeeks] Problem

2012-10-31 Thread prankur gupta
Hi,

You can view this problem as
parentValue -> actual value of parent
childValue  -> number of childs associated with it(which can be zero or 1)

so, (8,2) (4,1) (10,2) (2,0) (9,0) (12,0) is the BST.

Thanks.

On Wed, Oct 31, 2012 at 10:01 AM, Arun Kindra
wrote:

> Ques - *
>
> struct node
> {
> int parentValue;
> int childValue;
> }str[10];
>
> how to construct a BT,given an array of structure containing parent and
> child value.
> *
>
> --
> 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.
>



-- 
PRANKUR GUPTA

Masters Student (CSE)
State University of New York
Stony Brook University
prgu...@cs.stonybrook.edu

-- 
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.



[algogeeks] Problem

2012-10-31 Thread Arun Kindra
Ques - *

struct node
{
int parentValue;
int childValue;
}str[10];

how to construct a BT,given an array of structure containing parent and
child value.
*

-- 
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: Informatica written que : C output

2012-10-31 Thread Rahul Kumar Patle
@shivam: but when i replace
printf("Hello"); by printf("Hello\n");
it works correctly.. can you justify this by your logic..


On Wed, Oct 31, 2012 at 1:07 PM, Shivam Rohilla <
rohillashivam.jade...@gmail.com> wrote:

> Yes it will print 30+ times.
> fork() --> it's create the the child process which copie's the address
> stack of the parent process.
> now when you will do fork();
> look 1st iteration --> it wil break; ( if parent process scheduled 1st by
> the kernel )
> when 2nd iteration --> it will again fork in child process. and will print
> hello once and dan goes to parent dan break.
> when 3rd iteration -->  it will fork again and print hello twice and dan
> break
> when 4th iteration --> it will again fork and prnt hello 4 times i.e.
> hello once by iteration and dan fork child will start process from start
> and dan print hello 3 more times and dan parent will schedule and dan break.
> and so on...
>
> On 31 October 2012 11:49, tendua  wrote:
>
>> \n also flushes the standard output buffer. If it is not present, it is
>> possible that you have previously entered data in it. Flushing also means
>> it forces printf to print on the screen as soon as \n is processed.
>> Otherwise it is buffered output and you can never predict how long would OS
>> buffer your output and when precisely it chooses to actually print.
>>
>> --
>> 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/-/cNFex4s9a8UJ.
>>
>> 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.
>



-- 
Thanks and Regards:
Rahul Kumar Patle
M.Tech, School of Information Technology
Indian Institute of Technology, Kharagpur-721302,
India
Mobile No: +91-8798049298, +91-9424738542
Alternate Email: rahulkumarpa...@hotmail.com
[image: Linkedin]
[image: Twitter] 


-- 
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.



[algogeeks] Re: Informatica written que : C output

2012-10-31 Thread Ankit Tripathi
I would also like to add up something related to this context.
One can use *fprintf* and set the *1st argument to 2*, *which stands for 
stderr*, ie., the standard error stream.
stderr is defined in *stdio.h* header.
The classic thing about stderr is that, by default it does not buffers any 
contents and outputs everything immediately
to your terminal/console.
stdout and stderr are both associated to your terminal/console, but 
applications can use them differently.

-- 
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/-/uudvxmDRjVkJ.
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: @Walmart Labs interview questions

2012-10-31 Thread Shyam Sundar
@deepikaanand Thanks a lot!


On Wed, Oct 31, 2012 at 7:56 PM, deepikaanand wrote:

> Hi I appeared for walmart .
> the exam for for 90 min no negative marking
> mcqs were pretty easy almost all form geeksforgeeks(gate corner). 1
> qsnetworking + 1qs on database(min and max number of rows possible in join
> table) , no of distinct colors required to color map of India .rest were
> from data structures and 2 coding qs
> q1 :to rotate array 1,2,3,4,5 to 4,5,1,2,3
> q2 :Display row wise sum
> They shortlisted 6 students from 100 students..
> Interview round first qs :- Find subarray in array of given sum .
> Interviewer kept his mouth shut all the time.opened his mouth to say just 4
> words wrong , right,yes,no and yeah he gave me a hint to solve this
> qs(already given in geeksforgeeks) to use extra space .
> and second qs about SESSION variables in PHP(I had written about my
> project implemented in PHP)
> Other qs(asked from other students) was of riddle to find rand7() from
> rand5() ,LIS,LCS etc
> .All the best :)
>
>
>
>
> On Tuesday, October 30, 2012 9:42:27 PM UTC+5:30, Shyam Sundar wrote:
>>
>> Hi all,
>>
>> Has Walmart Labs visited any of your campuses this year? If so, can
>> anyone please provide the details about the interview process and the
>> questions that were asked?
>>
>>
>> Thanks
>> Shyam Sundar
>>
>  --
> 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/-/sr5n77ynUgkJ.
> 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.



[algogeeks] Extern in c

2012-10-31 Thread rahul sharma
How actually to use extern

suppose in file 1 i write code..(test_new.c)

#include 

 #include

 int interest_rate =5;
int main()
{
   int test = 0;
   int t=5;
  // cout<
#include"test_new.c"
extern int interest_rate;
void fun()
{
interest_rate=6;
}

it works..
now if i make interest_rate as static in c..it also wokrs in file 2..but it
should not...and if i remove the declaration of interest from file 2 it
also works...all this happening becoz i #included test_new.c(file1) in
file2so i definition comes in a...plz tell how to tell fille 2 to refer
file 1...as by #inlcuded resultsare not as accepted...itz full code coming
in file a...i want that

global variable is accessible in file 2 but for static it shows that itz an
undefined referenceplz provide me code snippet..

-- 
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] BIG O

2012-10-31 Thread rahul sharma
Its nlogn dude

On Wed, Oct 31, 2012 at 8:03 PM, jai gupta  wrote:

> is O(long n!)
> n! is O(n^n) by sterling approximation
> hence it is O(log n^n) = O(nlogn)
>
>
> On Sun, Oct 28, 2012 at 11:14 PM, Pralay Biswas <
> pralaybiswas2...@gmail.com> wrote:
>
>> @ Siddharth :
>> Well, here is how you may understand it:
>> 1) There is an outer loop that runs n times. (k)
>> 2) Then there is an inner loop where j is initially set to current k, but
>> it halves itself in every iteration
>>   -- So for example, if k is 32, and j halves every time, then
>> the inner loop runs for 5 times (32->16->8->4->2 etc)
>>   -- This is a log base 2 order depreciation in for all k
>> 3) So for every k, the inner loop runs for log k times. k itself varies
>> from 1 to n, hence O(nlogn)
>>
>> Hope this helps.
>>
>> #Pralay
>> MS-CS, UC Irvine
>>
>> On Sun, Oct 28, 2012 at 10:38 AM, bharat b 
>> wrote:
>>
>>> while loop : logj base 2 ..
>>> ==> log1 + log2 + ... logn = log(n!) [since logab = loga + logb]
>>> ==> O(log(n^n)) = O(nlogn)
>>>
>>>
>>> On Sun, Oct 28, 2012 at 3:56 AM, Siddharth Malhotra <
>>> codemalho...@gmail.com> wrote:
>>>
 Can somebody explain how it is O(n log n).
 What is the significance of while loop in the above code?

 I understand that the for loop implies O(n),does the log n in the O(n
 log n) comes from the while loop?
 What if there where two while loops in the for loop separately?

 On Sat, Oct 27, 2012 at 3:26 AM, Pralay Biswas <
 pralaybiswas2...@gmail.com> wrote:

> Yes!
>
>
> On Fri, Oct 26, 2012 at 2:55 PM, rahul sharma  > wrote:
>
>> for k=1 to n
>> {
>> j=k;
>> while(j>0)
>> j=j/2;
>> }
>> the complexity is big o is o(nlogn)
>> am i ryt
>>
>> --
>> 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.
>

  --
 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.
>>>
>>
>>  --
>> 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.
>>
>
>
>
> --
>
> kriateive
>
> --
> 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] BIG O

2012-10-31 Thread jai gupta
is O(long n!)
n! is O(n^n) by sterling approximation
hence it is O(log n^n) = O(nlogn)

On Sun, Oct 28, 2012 at 11:14 PM, Pralay Biswas
wrote:

> @ Siddharth :
> Well, here is how you may understand it:
> 1) There is an outer loop that runs n times. (k)
> 2) Then there is an inner loop where j is initially set to current k, but
> it halves itself in every iteration
>   -- So for example, if k is 32, and j halves every time, then the
> inner loop runs for 5 times (32->16->8->4->2 etc)
>   -- This is a log base 2 order depreciation in for all k
> 3) So for every k, the inner loop runs for log k times. k itself varies
> from 1 to n, hence O(nlogn)
>
> Hope this helps.
>
> #Pralay
> MS-CS, UC Irvine
>
> On Sun, Oct 28, 2012 at 10:38 AM, bharat b 
> wrote:
>
>> while loop : logj base 2 ..
>> ==> log1 + log2 + ... logn = log(n!) [since logab = loga + logb]
>> ==> O(log(n^n)) = O(nlogn)
>>
>>
>> On Sun, Oct 28, 2012 at 3:56 AM, Siddharth Malhotra <
>> codemalho...@gmail.com> wrote:
>>
>>> Can somebody explain how it is O(n log n).
>>> What is the significance of while loop in the above code?
>>>
>>> I understand that the for loop implies O(n),does the log n in the O(n
>>> log n) comes from the while loop?
>>> What if there where two while loops in the for loop separately?
>>>
>>> On Sat, Oct 27, 2012 at 3:26 AM, Pralay Biswas <
>>> pralaybiswas2...@gmail.com> wrote:
>>>
 Yes!


 On Fri, Oct 26, 2012 at 2:55 PM, rahul sharma 
 wrote:

> for k=1 to n
> {
> j=k;
> while(j>0)
> j=j/2;
> }
> the complexity is big o is o(nlogn)
> am i ryt
>
> --
> 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.

>>>
>>>  --
>>> 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.
>>
>
>  --
> 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.
>



-- 

kriateive

-- 
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.



[algogeeks] Re: @Walmart Labs interview questions

2012-10-31 Thread deepikaanand
Hi I appeared for walmart .
the exam for for 90 min no negative marking
mcqs were pretty easy almost all form geeksforgeeks(gate corner). 1 
qsnetworking + 1qs on database(min and max number of rows possible in join 
table) , no of distinct colors required to color map of India .rest were 
from data structures and 2 coding qs 
q1 :to rotate array 1,2,3,4,5 to 4,5,1,2,3
q2 :Display row wise sum
They shortlisted 6 students from 100 students..
Interview round first qs :- Find subarray in array of given sum . 
Interviewer kept his mouth shut all the time.opened his mouth to say just 4 
words wrong , right,yes,no and yeah he gave me a hint to solve this 
qs(already given in geeksforgeeks) to use extra space .
and second qs about SESSION variables in PHP(I had written about my project 
implemented in PHP)
Other qs(asked from other students) was of riddle to find rand7() from 
rand5() ,LIS,LCS etc
.All the best :)




On Tuesday, October 30, 2012 9:42:27 PM UTC+5:30, Shyam Sundar wrote:
>
> Hi all,
>
> Has Walmart Labs visited any of your campuses this year? If so, can anyone 
> please provide the details about the interview process and the questions 
> that were asked?
>
>
> Thanks
> Shyam Sundar
>

-- 
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/-/sr5n77ynUgkJ.
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] Ternary operators

2012-10-31 Thread rahul sharma
plz read carefully

On Wed, Oct 31, 2012 at 10:18 AM, Tamanna Afroze wrote:

> sorry for my last post, i didn't look carefully at the code. I think
> without bracket the ternary expression is incomplete, that's why; first
> code doesn't compile correctly.
>
>
>
> On Wed, Oct 31, 2012 at 9:51 AM, Tamanna Afroze wrote:
>
>> both codes are same. Where is the difference?
>>
>
>  --
> 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.



[algogeeks] Re: Repeated values

2012-10-31 Thread Don
A solution is to sort the array taking advantage of the fact that if
the contents are in fact a permutation of the values 0..n-1, value x
always goes in position A[x]. Therefore you can immediately swap value
x into the correct position. If that position already contains value
x, you have identified a duplicate.

bool hasDuplicate(int *a, int n)
{
  for(int i = 0; i < n; ++i)
  {
while(a[i] != i)
{
   int j = a[i];
   if (a[j] == j) return true;
   a[i] = a[j];
   a[j] = j;
}
  }
  return false;
}

At first it may appear to be O(n^2) but notice that each pass through
the inner loop puts one value in its correct place. Thus the inner
loop executes at most n times. Unlike a similar solution above, if it
finds a duplicate it immediately returns, so in some cases it doesn't
require n iterations.

This solution is also faster than the solution using the sign bit,
based on a benchmark test I ran.

Don


On Oct 30, 2:27 pm, Don  wrote:
> Given an array of N integers in the range 0..N-1, determine if any
> number is repeated in the array.
> Solution should execute in O(n) time and use constant space.
> Don

-- 
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: Informatica written que : C output

2012-10-31 Thread Shivam Rohilla
Yes it will print 30+ times.
fork() --> it's create the the child process which copie's the address
stack of the parent process.
now when you will do fork();
look 1st iteration --> it wil break; ( if parent process scheduled 1st by
the kernel )
when 2nd iteration --> it will again fork in child process. and will print
hello once and dan goes to parent dan break.
when 3rd iteration -->  it will fork again and print hello twice and dan
break
when 4th iteration --> it will again fork and prnt hello 4 times i.e. hello
once by iteration and dan fork child will start process from start and dan
print hello 3 more times and dan parent will schedule and dan break.
and so on...

On 31 October 2012 11:49, tendua  wrote:

> \n also flushes the standard output buffer. If it is not present, it is
> possible that you have previously entered data in it. Flushing also means
> it forces printf to print on the screen as soon as \n is processed.
> Otherwise it is buffered output and you can never predict how long would OS
> buffer your output and when precisely it chooses to actually print.
>
> --
> 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/-/cNFex4s9a8UJ.
>
> 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.



[algogeeks] Re: Repeated values

2012-10-31 Thread apsalar
I think this is the answer - 
http://stackoverflow.com/questions/5739024/finding-duplicates-in-on-time-and-o1-space

On Tuesday, October 30, 2012 2:27:29 PM UTC-4, Don wrote:
>
> Given an array of N integers in the range 0..N-1, determine if any 
> number is repeated in the array. 
> Solution should execute in O(n) time and use constant space. 
> Don 
>

-- 
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/-/XPyEFSy1Gh0J.
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: Repeated values

2012-10-31 Thread Vineeth
@Don : Shift all the numbers to the corresponding positions in the first
iteration
And in the second loop check whether the number and the position matches or
not.
O(N) space and O(1) time

constraint : the number's range must be from 0 to N-1

Cheers,


On Wed, Oct 31, 2012 at 3:16 AM, Don  wrote:

> In addition, inputs such as {2,2,0} will fail because when you try to
> make zero negative, it doesn't work so well.
> Don
>
> On Oct 30, 5:36 pm, Don  wrote:
> > That solution is using the sign bit as extra storage, which is clever,
> > but if you have an array of unsigned integers and N is more than half
> > of the largest unsigned integer, it won't work. There is a way to do
> > it without using the sign bit as extra storage.
> >
> > On Oct 30, 5:16 pm, rahul sharma  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > i thnik this is the solution...
> http://www.geeksforgeeks.org/archives/9755
> >
> > > On Wed, Oct 31, 2012 at 2:20 AM, Don  wrote:
> > > > We can modify the array. The algorithm should work even if we use
> > > > unsigned integers and N is the largest unsigned integer.
> >
> > > > Don
> >
> > > > On Oct 30, 4:42 pm, rahul sharma  wrote:
> > > > > Can we modify the array???we can make index we visit as negative
> and then
> > > > > if any one already containing -ve..then its repeating
> >
> > > > > On Wed, Oct 31, 2012 at 1:40 AM, Don  wrote:
> > > > > > Does your algorithm work if N=4 and the array is {1,1,2,2}.
> >
> > > > > > Don
> >
> > > > > > On Oct 30, 2:32 pm, arumuga abinesh 
> wrote:
> > > > > > > if sum of all elements = n(n-1)/2 , no elements are repeated
> > > > > > > else some numbers are repeated
> >
> > > > > > > On Tue, Oct 30, 2012 at 11:57 PM, Don 
> wrote:
> > > > > > > > Given an array of N integers in the range 0..N-1, determine
> if any
> > > > > > > > number is repeated in the array.
> > > > > > > > Solution should execute in O(n) time and use constant space.
> > > > > > > > Don
> >
> > > > > > > > --
> > > > > > > > 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.
> >
> > > > --
> > > > 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.
>
>

-- 
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] C Macro

2012-10-31 Thread dCoder
Thats because you have swapped pointers and printing variables.

On Mon, Oct 29, 2012 at 11:22 PM, rahul sharma wrote:

> I have taken form book...i am writing exact code
>
> #include
> #define swap(a,b,c) c t;t=a,a=b,b=t;
>
>
> int main()
> {
> float a,x;
> a=20.0;
> x=30.0;
> float *p,*q;
> p=&a,q=&x;
> swap(p,q,float*);
> printf("%f %f",a,x);
> getchar();
> }
>
> o/p=20.000 30.000
>
>
> why not swapped???
> On Mon, Oct 29, 2012 at 11:01 PM, atul anand wrote:
>
>> if you think the your expanded version is incorrect.You are wrong ,
>> because int * will hold pointer but you are not allocating address of
>> x ..instead you are allocating x value as an address of x to *t.This
>> wont work.
>> so to make it work you need to save the address of x and y in temp
>> pointers i.e
>>
>>int *p.*q;
>> p=&x;
>> q=&y;
>> int t;
>> t=*p;
>> *p=*q;
>> *q=t;
>> now you can convert it into macro.
>>
>> On 10/29/12, rahul sharma  wrote:
>> > @atul...mistakenly  i have put w at place of t in my last post...i wana
>> say
>> >
>> >
>> >
>> > On Mon, Oct 29, 2012 at 10:07 AM, dCoder  wrote:
>> >
>> >> Just replace your macro with its definition and you will understand.
>> >>
>> >> its not doing swapping of pointers...plz explain
>> >>
>> >
>> >
>> > @dCode i expanded..but its fine...please tell
>> >
>> >> #include
>> >> #define swap(a,b,c) c t;t=a,a=b,b=t
>> >>
>> >> int main
>> >> int x=10,y=20;
>> >> int *p,*q;
>> >> swap(x,y,int*);
>> >>
>> > int * t;
>> > t=x;
>> > x=y;
>> > y=t;
>> >
>> >
>> > There is int* at the end..there is som problem with my
>> > keyborad...:(.acc to me axpanded version is above..but not
>> swapping
>> > two pointerssplz comment
>> >
>> >
>> >
>> >
>> >> On Sun, Oct 28, 2012 at 9:16 PM, rahul sharma
>> >> wrote:
>> >>
>> >>> its now doing swapping of pointers...plz explain
>> >>>
>> >>>
>> >>> On Sun, Oct 28, 2012 at 8:08 PM, atul anand
>> >>> wrote:
>> >>>
>>  it should swap
>> 
>>  On 10/28/12, rahul sharma  wrote:
>>  > Why the following code is not able to swap two macros???although it
>>  > is
>>  > easily swapping 2 variables
>>  >
>>  > #include
>>  > #define swap(a,b,c) c t;t=a,a=b,b=t
>>  >
>>  >
>>  > int main
>>  >
>>  >
>>  > int x=10,y=20;
>>  > int *p,*q;
>>  >
>>  > swap(x,y,int);
>>  >
>>  > --
>>  > 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.
>> 
>> 
>> >>>  --
>> >>> 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.
>> >>
>> >
>> > --
>> > 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.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send emai