Very simple N^2*logN solution: sort the input array, then go through all
pairs Ai, Aj (N^2 time), and for each pair check whether (S - Ai - Aj) is in
array (logN time).
On 12 May 2010 23:08, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
@sateesh
suppose after sorting the array is
Hi Friends
I have encountered the question in sites - Given a Binary Search
Tree, write a program to print the kth smallest element without using
any static/global variable. You can't pass the value k to any function
also.
I have tried my hands using explicit stack for inorder and keeping a
One more way to do this can be:
1. sorting the number in decreasing order
2. start with 2 empty sets A and B and assign first 2 elements to each of
them (see the following example)
3. maintain the sums of A and B in variables.
4. take the next number from list and add it to the set
Hi ,
We can do Breadth first search but without any additional Memory like Queue.
Since we connect the siblings we can traverse through siblings.
Going from Top to bottom, Each Internal node(non-leaf) must connect its
children. If that internal node has a right sibling then connect the right
most
@atul linked list can be converted to array with O(n) both space @ time
overhead. then tree can be built in O(n)
On Sat, May 15, 2010 at 2:53 AM, W Karas wka...@yahoo.com wrote:
See the definition of:
templatetypename fwd_iter
bool build(fwd_iter p, size num_nodes)
Within the iter
We can try rotation too.
1.We iterate rotating of the left/right sub-tree having greater number of
nodes.
2. if number of keys are :-
ODD- Equal number of nodes exist on both left and rt subtree of root .Key
at root is the median of the BST..
EVEN-left subtree should have 1 less node than
my approach:
1. sort the array
2. take a variable diff. intitialize it to 0.
3. take the 1st element from array nd place it in array A and 2nd element in
array B. stoe in diff sum(A)-sum(B).
4. now place the next element in array A or B according to the condition if
if sum(A+element)-sum(B)
Cant it be done this way:-
1. Sort the array in O(n log(n)) time
2. select all pairs of numbers in array and keep track of minimum sum
(closest to zero) and also their indices, in O(n^2) time
3. In another iteration skipping the indices which gave the minimum sum,
check whether the
so what will ur algo give for array 1,200,500,2000
On 5/15/10, divya jain sweetdivya@gmail.com wrote:
my approach:
1. sort the array
2. take a variable diff. intitialize it to 0.
3. take the 1st element from array nd place it in array A and 2nd element in
array B. stoe in diff
there is something called morris inorder traversal.
credits to donald knuth
On 5/15/10, kaushik sur kaushik@gmail.com wrote:
Hi Friends
I have encountered the question in sites - Given a Binary Search
Tree, write a program to print the kth smallest element without using
any
10 matches
Mail list logo