Re: [algogeeks] All about references

2010-08-03 Thread dinesh bansal
Yes, both the cases are true because in both the cases memory is allocated
outside the functions internal memory. But just want to know why do you need
to return reference of a static variable.

On Tue, Aug 3, 2010 at 7:38 PM, Raj N  wrote:

> 1) Can we return a reference to an internal static variable in a
> function ?
> 2) Can we return a reference to a dynamic variable variable in a
> function ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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.
>
>


-- 
Dinesh Bansal
The Law of Win says, "Let's not do it your way or my way; let's do it the
best way."

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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: interview-question

2010-08-03 Thread Abhishek Shrivastav
I hope the value of V is 0 or 1. Is this right?

On Wed, Aug 4, 2010 at 12:48 AM, Manjunath Manohar  wrote:

> @above: i have little difficulty in perceiving the question... can u give
> certain test cases..sample input/output ..
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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.
>



-- 
Regards,
Abhishek Shrivastav

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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: interview-question

2010-08-03 Thread Manjunath Manohar
@above: i have little difficulty in perceiving the question... can u give
certain test cases..sample input/output ..

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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: interview-question

2010-08-03 Thread Seçkin Can Şahin
write a recursive function getmin(node, value) that returns the least number
of flips necessary for the subtree rooted at "node" to give the result
"value". recursive relations are easy to come up with, so I leave it as an
exercise :)

memorize the values calculated, so, never calculate a result more than once.

Since "value" is either 0 or 1, this algorithm works in O(n) time and space
complexity where n is the number of nodes.


On Tue, Aug 3, 2010 at 11:41 AM, RITESH SRIVASTAV
wrote:

> level of the tree is given or not ?
> and where do we have to output V , just at the node we get it or at
> the  root ?
>
> On Aug 3, 1:56 pm, jalaj jaiswal  wrote:
> > given a complete binary tree (either a node is a leaf node or has two
> > children)
> > every leaf node has value 0 or 1.
> > every internal node has value as the AND gate or OR gate.
> > you are given with the tree and a value V.
> > you have to output the minimum number of flips (AND to OR or OR to AND)
> if
> > the evaluated value is not equal to V, if it is equal return 0, if not
> > possible return -1.
> > you can just change the value of internal nodes i.e can make and to or ,
> or
> > to and to get the desired output
> > give the minimum number of flips required to get the desired output.
> >
> > --
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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 algoge...@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: interview-question

2010-08-03 Thread RITESH SRIVASTAV
level of the tree is given or not ?
and where do we have to output V , just at the node we get it or at
the  root ?

On Aug 3, 1:56 pm, jalaj jaiswal  wrote:
> given a complete binary tree (either a node is a leaf node or has two
> children)
> every leaf node has value 0 or 1.
> every internal node has value as the AND gate or OR gate.
> you are given with the tree and a value V.
> you have to output the minimum number of flips (AND to OR or OR to AND) if
> the evaluated value is not equal to V, if it is equal return 0, if not
> possible return -1.
> you can just change the value of internal nodes i.e can make and to or , or
> to and to get the desired output
> give the minimum number of flips required to get the desired output.
>
> --

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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] Diff b\w BST and binary tree............

2010-08-03 Thread Anand
While creating BST we follow the rule that element on the left hand side of
the root should be less than or equal to the root element and element on the
right hand side of the root should be greater than or equal to the root
element. For binary tree we don't follow any rule for creating it.

Data structure for both BST & binary tree: we use a simple structure that
holds a data value and pointer to its left and right child.


On Tue, Aug 3, 2010 at 10:18 AM, UMESH KUMAR wrote:

> what is the main difference b/w BST and Binary tree for the
> purpose of implementation .
> and what is the Data structure of that.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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 algoge...@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] what Garbase value.........

2010-08-03 Thread Seçkin Can Şahin
those are the things that you can google for.

On Tue, Aug 3, 2010 at 10:22 AM, UMESH KUMAR wrote:

> What is the  Garbase value in C/C++
> and what is the Null pointer ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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 algoge...@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] what Garbase value.........

2010-08-03 Thread UMESH KUMAR
What is the  Garbase value in C/C++
and what is the Null pointer ?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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] Diff b\w BST and binary tree............

2010-08-03 Thread UMESH KUMAR
what is the main difference b/w BST and Binary tree for the
purpose of implementation .
and what is the Data structure of that.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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] All about references

2010-08-03 Thread Abhishek Shrivastav
1) yes, you can return reference to an internal static variable, but instead
of heap it would be on data segment. Also, that reference should be used by
the function defined in the file(I am not sure of it).
2) Yes. we do it all the time.

On Tue, Aug 3, 2010 at 7:38 PM, Raj N  wrote:

> 1) Can we return a reference to an internal static variable in a
> function ?
> 2) Can we return a reference to a dynamic variable variable in a
> function ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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.
>
>
-- 
Regards,
Abhishek Shrivastav

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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] pointer and array

2010-08-03 Thread Raj N
array is passed a pointer in the function, hence sizeof(arr)==sizeof(*arr)

On Fri, Jul 23, 2010 at 9:10 PM, tarak mehta  wrote:

> int arr[]={1,2,3,4};
> k=sizeof(arr)/sizeof(*arr);
> value of k=4;
>
> however
>
>
> void hell(int arr[]);
> main()
> {
>int arr[]={1,2,3,4};
>hell(arr);
> }
> void hell(int arr[])
> {
> printf("%d",sizeof(arr)/sizeof(*arr));
> }
>
>
> output of hell() is 1. why???
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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 algoge...@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] All about references

2010-08-03 Thread Raj N
1) Can we return a reference to an internal static variable in a
function ?
2) Can we return a reference to a dynamic variable variable in a
function ?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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] Default arguments

2010-08-03 Thread Raj N
I wanted to know if the default arguments are pushed on the stack in c+
+?

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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] interview-question

2010-08-03 Thread jalaj jaiswal
given a complete binary tree (either a node is a leaf node or has two
children)
every leaf node has value 0 or 1.
every internal node has value as the AND gate or OR gate.
you are given with the tree and a value V.
you have to output the minimum number of flips (AND to OR or OR to AND) if
the evaluated value is not equal to V, if it is equal return 0, if not
possible return -1.
you can just change the value of internal nodes i.e can make and to or , or
to and to get the desired output
give the minimum number of flips required to get the desired output.

--

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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: sorting range of numbers in O(n)

2010-08-03 Thread Terence
 I think count sort is not acceptable (see Ankur's post for 
explanation), while radix sort fits the requirement.


Take the array as an array of 2-digit base n numbers.
First sort by the least significant digit (x%n), then the most 
significant digit (x//n), both using the stable counting sort. The 
overall time complexity is O(n).



On 2010-8-2 17:34, Avik Mitra wrote:

You can use count sort or radix sort. Both are of O(n) as running time
complexity.
You can refer to the book by "Introduction to Algorithms" by Thomas H.
Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein.



--
You received this message because you are subscribed to the Google Groups "Algorithm 
Geeks" group.
To post to this group, send email to algoge...@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: algorithm

2010-08-03 Thread Sathaiah Dontula
Please check the DS Symmetric Min-Max Heap, the root node is empty in this
DS, we can use of this and use the root always median.

I think this will give the median with O(1) and insertion and deletion costs
O(logN).

Thanks & regards,
Sathaiah Dontula

On Tue, Aug 3, 2010 at 7:59 AM, Gene  wrote:

> This is a great solution.
>
> On Jul 28, 3:09 am, janak  wrote:
> > How about keeping heap?
> > Have two heaps 1. max heap and 2. min heap
> > keep them equal size all the time and shift top element from one to
> > other when required...
> >
> >
> >
> > On Wed, Jul 28, 2010 at 7:46 AM, Gene  wrote:
> > > I think you have confused the statement of this problem.  The "(in
> > > sorted order)" comment makes no sense because a median is exactly one
> > > number.  One number is always sorted.
> >
> > > After every stream element is read, you want to be able to get the
> > > median of all elements read so far.
> >
> > > You're correct that the way to do this is maintain the elements in
> > > some kind of sorted data structure where you have O(1) access to the
> > > middle element.  An array or list will work fine, but each stream
> > > element will require O(n) to insert in the sorted order (just as you'd
> > > do for insertion sort).  It's easy to use a balanced tree instead.
> > > This reduces the processing time for each element to O(log n).  You
> > > must maintain the invariant that the root of the tree is the median,
> > > so access time is still O(1).  When a new element is read, it goes in
> > > either the left or right subtree of the root.  This may cause the
> > > median to shift by 0 or 1 position in either direction.  In this case,
> > > you'll always be able to pull the successor or predecessor of the
> > > root--whichever is the new median--up to the root by using e.g. AVL
> > > rotations.  You'd have to prove that this does not make the tree too
> > > unbalanced so that the O(log n) insertion is hurt, but I don't think
> > > this would be hard.
> >
> > > On Jul 24, 10:32 am, jalaj jaiswal  wrote:
> > >> You are given a stream of numbers which can be positive or negative.
> You are
> > >> required to provide an operation FIND MEDIAN..which when invoked
> should be
> > >> able return the median of the numbers in stream (in sorted order) in
> O(1)
> > >> time.
> >
> > >> Eg: 0 1 2 3 4
> > >> Right FIND MEDIAN returns 2 as median
> >
> > >> Now input is -2 -4
> > >> So Stream = 0 1 2 3 -2 -2 -4
> > >> Sorted Stream would be -4 -2 0 1 2 3 4 and FIND MEDIAN returns 1
> >
> > >> --
> > >> With Regards,
> > >> Jalaj Jaiswal
> > >> +919026283397
> > >> B.TECH IT
> > >> IIIT ALLAHABAD
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> > > To post to this group, send email to algoge...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com
> .
> > > For more options, visit this group athttp://
> 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 algoge...@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 algoge...@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] sorting range of numbers in O(n)

2010-08-03 Thread ankur aggarwal
radix sort...

On Mon, Aug 2, 2010 at 10:22 AM, Apoorve Mohan wrote:

> Counting Sort.
>
>
> On Mon, Aug 2, 2010 at 6:15 AM, Praveen wrote:
>
>> There are N numbers in an array and each number is in the range [0,
>> n*n -1]. Is there a way to sort the elements in O(n)?
>>
>> Thanks,
>> Praveen
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@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.
>>
>>
>
>
> --
> regards
>
> Apoorve Mohan
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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.
>



-- 
With Regards

Ankur Aggarwal

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@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.