[algogeeks] Difference between Singleton pattern and static member

2010-12-15 Thread Prims
there is at all any difference between a Singleton class and one with all static member (ie methods and attributes ) We could not find any instance where 'all static member class' would not achieve the same functionality as class properely implementing Singleton pattern ?? For eg

[algogeeks] Re: Amazon Interview Question

2010-12-15 Thread SVIX
use a dictionary (available in C#... basically a collection of generic key-value pairs where the key lookup is O(1) - hashed internally) since number that occurred first should be listed first when frequencies are the same, u need to record the first occurrence of each number as well. Hence, the

[algogeeks] Same Depth nodes

2010-12-15 Thread snehal jain
Problem is to find print all the nodes at the same levels of a binary tree.Inputs given are root pointer and the pointer to the node (let it be A)whose level elements need to be printed. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post

[algogeeks] Max Heap + Binary Search Tree

2010-12-15 Thread snehal jain
A rooted binary tree with keys in its nodes has the binary search tree property (BST property) if, for every node, the keys in its left subtree are smaller than its own key, and the keys in its right subtree are larger than its own key. It has the heap property if, for every node, the keys of its

[algogeeks] Re: Max Heap + Binary Search Tree

2010-12-15 Thread Prims
Lets assume that the tree node has two keys K1 and K2. K1 satisfies the BST property K2 satisfies the Max Heap Property. Our problem is to build a binary tree which satisfies both the properties. For a maximal heap the root node must be the maximum. So we find the node which has the K2 max. And

Re: [algogeeks] linkd list

2010-12-15 Thread Prashant Kulkarni
Hi, Very good question. i think very knows brute-force soln of n^3 time complexity. here is a alternative method/soln of O(n^2 * log(n)) time complexity Algo 1) pick any number from list A (One by one).. let say 'x' 2) pick any number from list B (one by one ).. let say 'y' 3) z=x+y

Re: [algogeeks] linkd list

2010-12-15 Thread Divya Jain
no not sorted On 15 December 2010 11:37, Anand anandut2...@gmail.com wrote: @Divya, I think you ask this question before. Not sure of the answer though :) On Tue, Dec 14, 2010 at 9:06 PM, Soumya Prasad Ukil ukil.sou...@gmail.com wrote: Are the linked list sorted? On 14 December 2010

[algogeeks] sort array

2010-12-15 Thread divya
Given an array of size n wherein elements keep on increasing monotically upto a certain location after which they keep on decreasing monotically, then again keep on increasing, then decreasing again and so on. Sort the array in place (ie. using only O(1) extra memory). -- You received this

Re: [algogeeks] Re: What would be the output of the following program..?

2010-12-15 Thread Terence
Just the opposite. All the operands are evaluated from left to right, and the right most operand is returned as the value of whole comma expression. But remember the operator precedence. Comma is lower than assignment. So c=--a, b++ - c is equivalent to c=--a; b++ -c; While c=(--a, b++ -c) is

Re: [algogeeks] linkd list

2010-12-15 Thread Ankur Murarka
wouldn't your algo take n^3 time as well given the fact that the lists are not sorted? searching for the matching value fr z should be taking O(n) time and to do so for each pair of x and y shall take O(n^2). Please correct me if i got something wrong here On Wed, Dec 15, 2010 at 11:44 AM,

Re: [algogeeks] linkd list

2010-12-15 Thread Soumya Prasad Ukil
@prashant How does log(n) come in your algo? I think yours is O(n^3). Using Hashtable,if allowed, reduces complexity. On 14 December 2010 22:14, Prashant Kulkarni prashant.r.k...@gmail.comwrote: Hi, Very good question. i think very knows brute-force soln of n^3 time complexity. here is a

Re: [algogeeks] sort array

2010-12-15 Thread Soumya Prasad Ukil
First determine the point from which array becomes decreasing. Then In-place merge sort. On 14 December 2010 23:22, divya sweetdivya@gmail.com wrote: Given an array of size n wherein elements keep on increasing monotically upto a certain location after which they keep on decreasing

[algogeeks] Re: Amazon Interview Question

2010-12-15 Thread bittu
@ankur,saurabh,soumya.. ya ankur i forget to remove range from dare also no need to find range for this..\ put size-1 intead of range so that malloc will alocate the memory to all elements in array ..no hope its fine... what i did is that i took counter array thta cvontains the no of

[algogeeks] Fwd: [Lovers India] @~|| DFFERENCES BETWEEN LOVE AND LIKE ||~@

2010-12-15 Thread parth panchal
-- Forwarded message -- From: NiTz niteshnanda...@gmail.com Date: Wed, Dec 15, 2010 at 3:44 PM Subject: [Lovers India] @~|| DFFERENCES BETWEEN LOVE AND LIKE ||~@ To: loversin...@googlegroups.com, hellom...@googlegroups.com, we_love_in...@googlegroups.com,

Re: [algogeeks] array

2010-12-15 Thread parth panchal
HI HOW ARE YOU On Tue, Dec 14, 2010 at 7:45 PM, divya sweetdivya@gmail.com wrote: an array contain +ve and -ve element, find subarray whose sum =0; Lets take input array as a[]={-3,2,4,-6,-8,10,11} -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] coins

2010-12-15 Thread bharath kannan
refer topcoder tutorials..dp On Wed, Dec 15, 2010 at 12:12 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: how do we find the complexity of DP program ? i know it cn be done using DP states , but the gien complexity is n^2 . i am not sure how to compare that On Tue, Dec 14, 2010 at

Re: [algogeeks] array

2010-12-15 Thread Soumya Prasad Ukil
It's a subset-sum problem, I guess. On 15 December 2010 04:12, parth panchal parthpancha...@gmail.com wrote: HI HOW ARE YOU On Tue, Dec 14, 2010 at 7:45 PM, divya sweetdivya@gmail.com wrote: an array contain +ve and -ve element, find subarray whose sum =0; Lets take input array as

Re: [algogeeks] Re: Amazon Interview Question

2010-12-15 Thread Soumya Prasad Ukil
Have a look : http://geeksforgeeks.org/?p=1488 On 15 December 2010 05:19, Saurabh Koar saurabhkoar...@gmail.com wrote: @ Bittu: Lets analyze your code with iterations: the array contains 1 3 3 1 2 3 5 2 3 count contains 0 2 2 4 0 1 0 0 0 now 1st iteration: i=8,7,6 the inner loop

[algogeeks] zigzag

2010-12-15 Thread divya
A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a zig-zag sequence. For

Re: [algogeeks] linkd list

2010-12-15 Thread Prashant Kulkarni
we can use binary search algorithm to find the z ( sorting ll take O(n log n ) but it is very less compared to n^2 * log n ) -- Prashant Kulkarni On Wed, Dec 15, 2010 at 3:32 PM, Ankur Murarka ankur.murarka@gmail.comwrote: wouldn't your algo take n^3 time as well given the fact that

Re: [algogeeks] coins

2010-12-15 Thread Amir hossein Shahriari
@ankur: the operation for each cell in dp array is O(1) so since we fill n^2 cells the total complexity is O(n^2) On Wed, Dec 15, 2010 at 10:12 AM, Ankur Khurana ankur.kkhur...@gmail.comwrote: how do we find the complexity of DP program ? i know it cn be done using DP states , but the gien

Re: [algogeeks] linkd list

2010-12-15 Thread Terence
Here is an O(N^2) algorithm: 1. Sort both A and B. (O(NlogN) or O(N^2), either will work) 2. For each element C[k] in C, find if there is such (i,j) pair that A[i] + B[j] = -C[k]: Start with i = 0 and j = N-1, and loop through the following: a. if A[i] + B[j] -C[k], then j = j-1;

[algogeeks] tricky C aps ques

2010-12-15 Thread siva viknesh
main() { int a[5]={1,3,6,7,0}; int *b; b=a[2]; coutb[-1]; } the value of b[-1] is a.1 b.3 c.-6 d.none give me the answer and explain why ?? -- Regards, $iva -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

Re: [algogeeks] tricky C aps ques

2010-12-15 Thread Tagged
The answr is 3. Arrays can have negative elements. The address is the address of base - address of int. On Wed, Dec 15, 2010 at 10:56 PM, siva viknesh sivavikne...@gmail.comwrote: main() { int a[5]={1,3,6,7,0}; int *b; b=a[2]; coutb[-1]; } the value of b[-1] is a.1 b.3 c.-6

Re: [algogeeks] C output... ???

2010-12-15 Thread Tagged
Is it that the first case its a pointer to a pointer. So size of pointer to a pointer is 4. In next case , Its the size of array. So its 40. Is the explanation correct? On Wed, Dec 15, 2010 at 9:43 AM, rahul rahulr...@gmail.com wrote: you would like to read peter ven der linden.(deep C