Re: [algogeeks] Re: why we can not swap values using macro?

2011-10-19 Thread Wasif Hossain
@prasad jondhale: +1 Thanx. Wasif Hossain Final Semester Student, Computer Science and Engineering(CSE), Bangladesh University of Engineering and Technology(BUET) Dhaka, Bangladesh. On Wed, Oct 12, 2011 at 3:47 AM, prasad jondhale wrote: > hey man u have made a very silly mistakeyou have sw

Re: [algogeeks] Re: print vertical sums of a binary tree

2011-10-19 Thread yq Zhang
You should use a doubly linked list instead of any sort of array. All the operation on the data structure you need are goto next/prev and insert front/end. Yunqiao On Wed, Oct 19, 2011 at 6:40 AM, monish001 wrote: > I think it might done using function of following prototype: > void func(node*

[algogeeks] Amazon Ques Suggest Algo

2011-10-19 Thread Ankur Garg
{You are given an unsorted array of integers. You have to find out the first sub array whose elements when added sum up to zero. eg:- int Array[] = {1,2,-4,-3, 6 ,-3.}Here sub array is -3,6,-3 bcos adding all these sum to zero. A sub array can be of size 2 to whole length of the array. You can

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread sunny agrawal
yes u r wrong 11 11<<1 = 110 but sequence will be 11 101 110 On Thu, Oct 20, 2011 at 12:18 AM, tin wrote: > Can you just generate them sorted? > > 1 is the minimum > 1 << 1 is the next in line > 1 << 2 is the next one > > 1 << N > 11 > 11 << 1 > > and so on > > Am i wrong? > > Il 19/10/2011

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread tin
Can you just generate them sorted? 1 is the minimum 1 << 1 is the next in line 1 << 2 is the next one 1 << N 11 11 << 1 and so on Am i wrong? Il 19/10/2011 19:33, Vandana Bachani ha scritto: Completing it... Got sent before I completed On Wed, Oct 19, 2011 at 12:31 PM, Vandana Bachani mail

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread Vandana Bachani
Completing it... Got sent before I completed On Wed, Oct 19, 2011 at 12:31 PM, Vandana Bachani wrote: > Better logic: > create a list array of lists 'arr' (like a hash table with lists). Array > size is N represents 1 to N bits and lists that will increase as we add more > elements to it. a. > fo

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread sunny agrawal
No need of creating a tree simply take an array of size 2^N in which all a[i] initialized to i now sort the array first depending upon the set bits in the a[i] if set bits are equal then use value this function call to sort function of algorithms will do the required bool cmp(int x, int y){ int

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread Vandana Bachani
Better logic: create a list array of lists (like a hash table with lists). Array size is N represents 1 to N bits and lists that will increase as we add more elements to it. for(i = 1; i < 2^N; i++) { c = count no. of 1s. in i } On Wed, Oct 19, 2011 at 12:16 PM, Vandana Bachani wrote: > Hi,

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread sunny agrawal
although input is small so a brute force will also do but some optimization can be like 1. first we can find that how many bits will be set in Kth Codewords using the following method no of codewords with N bits set = 1 no of codewords with N-1 bits set = NC1 no of codewords with N-2 bits set = NC

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread Vandana Bachani
Hi, logic: We can work on this problem from the way we construct the sequence. First we generate a binary tree such that each leafnode corresponds to one of the 2^N nodes. We start we an empty root, creating 0, 1 nodes assigning one bit at a time upto N levels (there would be 2^N - leafnodes) but w

[algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread aritra kundu
*Question 1 / 1* Given an integer *N*, there are *2^N* binary codewords of length N. All of them are taken and sorted to create a sequence: Sort by the number of 1-bits in the codeword bit-string. If there is a tie, break tie so that the smaller number comes first in the output sequence *Testcases

Re: [algogeeks] Re: finding anagrams in file

2011-10-19 Thread sravanreddy001
The next question interviewer would ask is. the length of the string is not small. and if they mentioned it as m, we can't assume it to be constant, anyway.. the formula O(nm log m) --> will be converted to O(nm) or O(n) based on what you assume m to be. Another Question: log (m) goes constan

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-19 Thread sravanreddy001
Sorry.. this is good one, but works for consecutive numbers only from 1..N -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/07wiKGP2WusJ. To post to this g

[algogeeks] Re: print vertical sums of a binary tree

2011-10-19 Thread monish001
I think it might done using function of following prototype: void func(node* root, deque& d, const deque::iterator& it); I will add left child's value in it-1 if exists else create new... similarly for right child. and call the same function for each of the children to explore further.. Monish O

Re: [algogeeks] Re: finding anagrams in file

2011-10-19 Thread WgpShashank
@Marcelo & all , Yes it will be definitely O(nmlogm) . Thanks Shashank CSE,BIT Mesra -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/aP1bCH0v_nYJ. To post

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-19 Thread ravindra patel
@Anshu >> first check that particular number can be written as the sum of two squares or not What would be the way to figure it out. >> O(n * (number of side which is largest one for any triplet)) Didn't get it. Thanks, - Ravindra On Wed, Oct 19, 2011 at 11:09 AM, anshu mishra wrote: > @Ravind

Re: [algogeeks] Re: Code it...

2011-10-19 Thread Azhar Hussain
I am not sure about the program to do it. But, 'strace' on linux would give the details of a program(parameters passed, retrun values, signals recieved etc). If you are looking for something similar then you can loot at strace source. mean while a.out does not not have information of stack pointer

Re: [algogeeks] Re: Code it...

2011-10-19 Thread Rahul
http://www.dgp.toronto.edu/~ajr/209/notes/memoryos.html Rahul On Wed, Oct 19, 2011 at 2:29 PM, Rahul wrote: > http://valgrind.org/ > > I am not sure but this may help on linux. > I have a question that how to determine the number of system calls a > program has made ? > That too of a particular

Re: [algogeeks] Re: Code it...

2011-10-19 Thread Rahul
http://valgrind.org/ I am not sure but this may help on linux. I have a question that how to determine the number of system calls a program has made ? That too of a particular type Rahul On Wed, Oct 19, 2011 at 11:07 AM, kumar raja wrote: > Can someone give me an idea about how to see the range