yes..DFS seems a good solution..then look until u get a Z..here is a
piece of code..
static ArrayListInteger buffer;
void findSum(TreeNode head, Node nodeZ,ArrayListInteger buffer) {
if (head == null || head == nodeZ) return;
buffer.add(head.data);
ArrayListInteger c1 = (ArrayListInteger)
small correction in my post..
yes..DFS seems a good solution..then look until u get a Z..here is a
piece of code..
void findSum(TreeNode head, Node nodeZ,ArrayListInteger buffer) {
if (head == null || head == nodeZ) return;
buffer.add(head.data);
ArrayListInteger c1 = (ArrayListInteger)
my solution will not work..it works only if X Y or on the same side
of subtree..like suppose if path is left node,root,right node..then
the LCS will do..i think first we need to find whether both X Y r on
the both side of subtree or different sides..depending on tht we need
to find the path and
Just got AC for this problem. Here is simple solution:
1. Calculate degree for each vertex. If there is a degree 2, then answer
is No.
You may use hash_map or map here.
2. So at this step we don't have any verticies with 3 and more edges, only
= 2 are allowed.
Though, we should check if there
RLE run length encoding is another solution because counting sort
eats space whilw with RLE we can do it in
time complexity O(n)
Space Complexity O(1)
Correct me if i am wrong ...i m talking about possibility not
exactness.
Regards
Shashank
--
You received this message because you are
Jig saw puzzle. What are the data structures? Assume you have some
method which can tell you if two pieces fit together. How would you
solve the puzzle, minimizing the number of times you have to call that
function?
Thanks
Shashank
--
You received this message because you are subscribed to the
Design an algorithm and write code to serialize a binary tree.
Regards
SHahsank
--
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
store inorder and preoder traversal of tree in arrays..
On Sat, Jan 8, 2011 at 5:49 PM, bittu shashank7andr...@gmail.com wrote:
Design an algorithm and write code to serialize a binary tree.
Regards
SHahsank
--
You received this message because you are subscribed to the Google Groups
@bittu
I would like to discuss one thing regarding your approach ,
How you managed to put forward your 1st statement that is of Synchronization
.
On Fri, Jan 7, 2011 at 1:18 PM, Pedro Rezende web...@gmail.com wrote:
Hi all!
And what could be the best way to test / debug issues like these?
@bittu ,
I think RLE , would be of no use ;
as
inp:AAABBRRGH
out :3A2B2R1G1H
so to reach the top 5 counts , there will be of no use .
as stated earlier by others ,
HASH TABLE will be the one of best solution for this .
maintain hash table in O(n) and then sort it .for top 5 counts.
Please
Another option is to serialize it in XML-like manner.
--
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
@Juver++ Its its not reachable then print answer as 'no'.. whats the
problem..
can you elaborate a bit ? I didnt get where it fails.
On Sat, Jan 8, 2011 at 1:30 AM, juver++ avpostni...@gmail.com wrote:
z can be unreachable while doing DFS from node x, cause their common
ancestor locates on
Hi.. thanks for your response.
The number of kids:
3 = K = 10^9
I cant declare an array: long long A[10];
and how does dfs or bfs finds the components of the graph?
because i have to verify if there is a cycle in all the components.
--
You received this message because you are
Use mapint, vectorint whichs maps vertex and all its neighbors.
You should use bfs only to find if there is cycle (with a shape of circle).
setint is useful to keep track of visited vertices.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To
Also, you may use hash_set and hash_map if such exists in your language.
--
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
Here is simple example: x = 2, z = 3, y = 1. Your code cannot reach node 1
while doing dfs from x.
https://lh3.googleusercontent.com/_qdJSDBXyZKE/TSi5XyCrEzI/ARg/PB7anNiPA2c/graph.png
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
Given a (decimal - e.g.3.72) number that is passed in as a string,
print the binary rep¬resentation.If the number can not be represented
accurately in binary, print “ERROR
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group,
cam somebody provide hint in solving this problem ?? I am stuck :( .
--
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
I don't think you should ask help for the problem of the *running *contest.
--
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
oops it is running
--
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
Her is the code...u need to add the if block for -ve numbers.
1 public static String printBinary(String n) {
2 int intPart = Integer.parseInt(n.substring(0, n.indexOf(‘.’)));
3 double decPart = Double.parseDouble(
4 n.substring(n.indexOf(‘.’), n.length()));
5 String int_string = “”;
6 while
http://coders-stop.blogspot.com/2010/12/most-used-data.html
On Jan 7, 5:24 pm, bittu shashank7andr...@gmail.com wrote:
You have a stream of infinite queries (ie: real time Google search
queries that people are entering). Describe how you would go about
finding a good estimate of 1000 samples
The problem never says that the tree is rooted. So LCA is not
very relevant.
The path between two nodes in any tree is unique. (Otherwise it has a cycle
and is not a tree.) So all that's needed is to search for z starting at x
(DFS or BFS will work fine). When you find the unique path, see
In the 3rd test case, how come the answer is Yes. 1,2 and 3 are
forming a cycle.
On Jan 8, 1:19 pm, juver++ avpostni...@gmail.com wrote:
Also, you may use hash_set and hash_map if such exists in your language.
--
You received this message because you are subscribed to the Google Groups
#includestdio.h
int main()
{
float a=275.7;
if(275.7a)
printf(Hi);
else
printf(Hello);
return 0;
}
#includestdio.h
int main()
{
float a=75.7;
if(75.7a)
printf(Hi);
else
printf(Hello);
return 0;
}
why the above two programs give different output?
--
You received this message
I wondered that too...seems kid 3 gets too many wishes
On Jan 8, 8:21 pm, bhawana goel bhawan...@gmail.com wrote:
In the 3rd test case, how come the answer is Yes. 1,2 and 3 are
forming a cycle.
On Jan 8, 1:19 pm, juver++ avpostni...@gmail.com wrote:
Also, you may use hash_set and
I guess it has to do with how float/double is stored on your computer.
Always use an error tolerance when it comes to floating-point numbers
comparison. By the way, on my machine it outputs the same
thing(Hello)
e.g.
#define epsilon 10e-6
if(275.7-aepsilon)
printf(HI);
else
printf(Hello);
i know the EPS stuff.
ok so it is machine dependent what output we get.
On Sun, Jan 9, 2011 at 9:08 AM, Jammy xujiayiy...@gmail.com wrote:
I guess it has to do with how float/double is stored on your computer.
Always use an error tolerance when it comes to floating-point numbers
comparison.
The 275.7 and 75.7 are doubles. The assignment statements round the
double constant to float precision. Then you compare the unrounded
double to the rounded float. If you had used 275.7e0 and 75.7e0 in the
if statements, the results would have been Hello in both cases.
Or to put it differently,
why is 1 double rounded down and the other double rounded up
is it compiler dependent?
On Sun, Jan 9, 2011 at 9:29 AM, Dave dave_and_da...@juno.com wrote:
The 275.7 and 75.7 are doubles. The assignment statements round the
double constant to float precision. Then you compare the unrounded
On Sunday 09 January 2011 04:24:40 priya mehta wrote:
#includestdio.h
int main()
{
float a=275.7;
if(275.7a)
printf(Hi);
else
printf(Hello);
return 0;
}
#includestdio.h
int main()
{
float a=75.7;
if(75.7a)
printf(Hi);
else
printf(Hello);
return 0;
}
why the
@Priya: Most modern processors have arithmetic that conforms to the
IEEE Floating Point Standard. Double constants have 53 bits of
precision, while floats have 24 bits. Rounding depends on the bit to
the right of the 24th bit from the left. If that bit is a 1, the
number is rounded up, while 0
we can make a doubly linked list of the tree.
--
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
int a=2;
printf(%d %d %d,a,a,a++);
the output is 3 3 2
can someone tell the logic behind this?
--
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,
@priya,
Generally printf evaluation starts from left to right
so first a++ using post increments assign the value of 3rd %d to be 2
then a++gets evaluated , now a value is 3
2nd %d takes a value as 3
1st %d takes a value as 3
if it is a preincrement like ++a in the third place
the output
small correction printf evaluation starts from right to left.
On Sun, Jan 9, 2011 at 10:59 AM, kartheek muthyala
kartheek0...@gmail.comwrote:
@priya,
Generally printf evaluation starts from left to right
so first a++ using post increments assign the value of 3rd %d to be 2
then
Given two binary trees T1 and T2 which store character data, duplicates
allowed. You have to devise an algorithm to decide whether the T2 is a
subtree of T1. T1 has millions of nodes and T2 has hundreds of nodes.
--
Harshal Choudhary,
III Year B.Tech Undergraduate,
Computer Science and
ok
i got that
On Sun, Jan 9, 2011 at 11:01 AM, kartheek muthyala
kartheek0...@gmail.comwrote:
small correction printf evaluation starts from right to left.
On Sun, Jan 9, 2011 at 10:59 AM, kartheek muthyala kartheek0...@gmail.com
wrote:
@priya,
Generally printf evaluation starts
Yeah you might be knowing how the expression evaluators work using stack
right. printf also uses the same approach
On Sun, Jan 9, 2011 at 11:06 AM, priya mehta priya.mehta...@gmail.comwrote:
@kartheek so does it use stack for that?
On Sun, Jan 9, 2011 at 11:03 AM, priya mehta
ok but the output of
int a=10,b;
b=a++ + ++a;
printf(%d,%d,%d,%d,b,a++,a,++a);
is 22 13 14 14
howz that then?
On Sun, Jan 9, 2011 at 11:11 AM, kartheek muthyala
kartheek0...@gmail.comwrote:
Yeah you might be knowing how the expression evaluators work using stack
right. printf also uses the
Evaluation of printf is from right to left !!!,
Regards
Sundi
On Jan 9, 10:08 am, priya mehta priya.mehta...@gmail.com wrote:
int a=2;
printf(%d %d %d,a,a,a++);
the output is 3 3 2
can someone tell the logic behind this?
--
You received this message because you are subscribed to the
Evaluation of b=a++ + ++a;
is also from right to left,
so
b = 22;
but i am getting the o/p as 22,13,13,13
On Jan 9, 10:59 am, Sundi sundi...@gmail.com wrote:
Evaluation of printf is from right to left !!!,
Regards
Sundi
On Jan 9, 10:08 am, priya mehta priya.mehta...@gmail.com wrote:
http://www.ideone.com/mxvmt
please see
On Sun, Jan 9, 2011 at 11:34 AM, Sundi sundi...@gmail.com wrote:
Evaluation of b=a++ + ++a;
is also from right to left,
so
b = 22;
but i am getting the o/p as 22,13,13,13
On Jan 9, 10:59 am, Sundi sundi...@gmail.com wrote:
Evaluation of printf is
hey i am also getting the output as 12,13,13,13..
--
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
http://www.ideone.com/mxvmt
please see
please see the link it has the program with output
On Sun, Jan 9, 2011 at 11:44 AM, Harshal hc4...@gmail.com wrote:
hey i am also getting the output as 12,13,13,13..
--
You received this message because you are subscribed to the Google Groups
When you invoke the ++ operator (either pre- or post-increment) twice in the
same statement, you invoke undefined behavior. How your compiler decides to
resolve that is completely compiler-dependent. There is undefined
behaviour because the same variable is modified more than once between
it would be more accurate to call that behaviour (as in order of evaluation
of arguments) unspecified rather than undefined. It is compiler dependent
whether it takes from right to left or the other way round.
--
You received this message because you are subscribed to the Google Groups
output should be 22,13,13,13 right ?
On Sat, Jan 8, 2011 at 10:22 PM, priya mehta priya.mehta...@gmail.comwrote:
http://www.ideone.com/mxvmt
please see
please see the link it has the program with output
On Sun, Jan 9, 2011 at 11:44 AM, Harshal hc4...@gmail.com wrote:
hey i am also getting
Do an inorder walk on T1 till you get the root of T2.
Then do a simultaneous walks on both the trees till T2(smaller tree) is
fully explored.
If at any point you discover dissimilar nodes. print 'no'
else print 'yes'
One more issue is if duplicates are allowed, then we cant print 'no' with
just
which order of execution will anyways give 22,13,14,14? The only way to
explain is interleaving of each of the operations(i.e operations are not
atomic).
On Sat, Jan 8, 2011 at 10:34 PM, nishaanth nishaant...@gmail.com wrote:
output should be 22,13,13,13 right ?
On Sat, Jan 8, 2011 at
@Gene...BFS wont work i guess. Because even if y is in the path it may not
be in the queue. DFS is a bit intuitive i guess
On Sat, Jan 8, 2011 at 4:32 PM, Gene gene.ress...@gmail.com wrote:
The problem never says that the tree is rooted. So LCA is not
very relevant.
The path between two
to add to @Dave's reply. He explained it elaborately in
thishttp://groups.google.com/group/algogeeks/browse_thread/thread/20af6e098297d413thread
Programmers should realize their critical importance and responsibility in a
world gone digital. They are in many ways similar to the priests and monks
Will this work ?
Find the node x, then the node y within the sub tree rooted at x and then z
within the sub tree rooted at y since they must within a unique path
If any of those searches fails there are no such nodes
On Sun, Jan 9, 2011 at 6:02 AM, Gene gene.ress...@gmail.com wrote:
The
@harshal, sundi: Use some compiler to check, i checked on gcc , it gives
13,14,14
On 9 January 2011 11:44, Harshal hc4...@gmail.com wrote:
hey i am also getting the output as 12,13,13,13..
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
Design an algorithm to figure out if someone has won in a game of tic-
tac-toe. give O(N) soln
--
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,
b=(11++)+ (++10)=11+11=22
a=12
in printf the control goes to right first , i.e. ++a , so
++a =(++12), (a becomes 13 but ++a is not printed) then control moves to a
but as the next expression pushed in stack is of the same variable so
control moves to a++. without printing a
a++= 13++, (now a
One approach would be to convert both the trees to well formed flat-tree
representation and then reduce the problem to a substring matching one (can
use KMP/Boyer-Moore/Rabin-Karp for it).
eg.
1
2 3
4 5
is flattened to (using postorder traversal) (1 (2 4 .) (3 . 5))
Programmers
@Juvier, @yq Zhang
In your approach, when you are asked pop_front() you keep popping from
one stack and pushing them to another and then from the other pop the
top element. What happens is this top element happens to have been the
Min element?Example
stack1 {(2,2),(4,2),(3,2),(6,2)} (a,b) = (
When you push into stack2, you have to recompute the min value. So after you
push into stack2, it will be:
(6,6),(3,3),(4,3),(2,2)
On Thu, Jan 6, 2011 at 6:34 PM, sourav souravs...@gmail.com wrote:
@Juvier, @yq Zhang
In your approach, when you are asked pop_front() you keep popping from
one
59 matches
Mail list logo