Re: [algogeeks] Re: changing structure of binary tree based on gravity and node selected.

2014-01-27 Thread Amol Sharma
Even if its collapsing into almost a straight line, the structure is still a tree with a node having a maximum of 3 nodes, thus can be called a ternary tree. -- Thanks and Regards, Amol Sharma On Mon, Jan 20, 2014 at 10:50 PM, Don dondod...@gmail.com wrote: Good point, Vikas. What if the

Re: [algogeeks] Solving equation

2014-01-27 Thread Amol Sharma
i din't get ur question. isn't the equation *(x - 7) + 7 = (x + 1) - 5* invalid ? -- Thanks and Regards, Amol Sharma On Wed, Jan 15, 2014 at 3:34 AM, Arpit Sood soodfi...@gmail.com wrote: Equivalent to solving an infix expression using stack with a pair (first variable, second constant)

[algogeeks] Find longest consecutive subsequence

2014-01-27 Thread Amol Sharma
Given an array of positive numbers arranged in any order. You have to find the length of longest continuos(difference of +1, -1) sequence in the array. for eg. A[] = *5*, 20, 45, *3*, 98, *4*, 21, *1*, 99, *2* then longest continuos subsequence is [1, 2, 3, 4, 5] and hence the output should be

Re: [algogeeks] Solving equation

2014-01-27 Thread saurabh singh
^ No its not invalid. It just represents an equation with infinitely many correct solutions depending on the domain of x. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Mon, Jan 27, 2014 at 4:21 PM, Amol Sharma amolsharm...@gmail.com wrote: i din't get

Re: [algogeeks] Find longest consecutive subsequence

2014-01-27 Thread Nishant Pandey
I think this the most optimized code i have writen : #include iostream #include vector #include map using namespace std; int longest_sequence(vectorint nums) { mapint,bool mp; int count; int max = -; int n = 0; for(unsigned int i = 0; i nums.size(); i++) { mp[nums[i]] = true;

Re: [algogeeks] Find longest consecutive subsequence

2014-01-27 Thread Don
This works, and I think is O(N*log(N)) which is similar to sorting and scanning. An unordered map will be faster, in general. It could be made faster in most cases by looping over items left in the map, to avoid processing the same number more than once. Also, when the number of items left in

Re: [algogeeks] Solving equation

2014-01-27 Thread Saurabh Paliwal
Ws On 27 Jan 2014 17:02, saurabh singh saurab...@gmail.com wrote: ^ No its not invalid. It just represents an equation with infinitely many correct solutions depending on the domain of x. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Mon, Jan 27,