Re: [algogeeks] Re: unset leftmost bit

2010-07-24 Thread Ashish Goel
this algo sets all bits to zero Debajyoti refer http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, Jul 24, 2010 at 10:20 AM, Debajyoti Sarma sarma.debajy...@gmail.com

[algogeeks] Re: unset leftmost bit

2010-07-24 Thread sonic
#include stdio.h; main() { int input,output; int temp; int counter=0; printf(\nEnter the number: ); scanf(%d, input); temp=input; while(temp) { counter++; temp=1; } printf(\n[debug] the length of the binary no. is : %d, counter); output = input^(1(counter-1));

Re: [algogeeks] You have 2 arrays of integer. You have to write a function, which take an integer as input and returns bool. Example array 1 has {1,5,10} array 2 has {2,5,9}. Func(3) should return t

2010-07-24 Thread Algoose chase
@jalaj TRY A:16, 12, 10, 6 ,2 B:11, 10,7, 2, 1 num: 26 On Sat, Jul 24, 2010 at 5:13 AM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: Take two pointers both at the start of each array... i=0,j=0 let the size of sorted arrays be m and n int func(int num,int m,int n){ int i=0,j=0;

Re: [algogeeks] pointer and array

2010-07-24 Thread jalaj jaiswal
sizeof(arr) is 4.. o.e the number of elements in the array size of *arr is the size of any normal pointer i.e 4(in case of 32-bit compilers) so the answer is 1 On Sat, Jul 24, 2010 at 9:52 AM, ravi gupta ravikant0...@gmail.com wrote: On Sat, Jul 24, 2010 at 9:40 AM, tarak mehta

Re: [algogeeks] Re: unset leftmost bit

2010-07-24 Thread Amir hossein Shahriari
we can use a binary search to search for the bit in O(logn) the search would look like this: we first compute n 0x (which is 16 1s and 16 0s) if the result is 0 then the left most 1 is in the 16 less significant bits else it is in the 16 more significant bits then we can continue this way

[algogeeks] Re: BST

2010-07-24 Thread rahul patil
1 convert the BST into a sorted doubly linklist.(increasing order) It will take O(n) time. 2 Now find two nodes in a link list whose sum is k(given no) to find sum in linklist. take two pointers ptr1= head ptr2=tail of linlist. now find sum of ptr1-data + ptr2- data while(ptr1-data ptr2-

Re: [algogeeks] You have 2 arrays of integer. You have to write a function, which take an integer as input and returns bool. Example array 1 has {1,5,10} array 2 has {2,5,9}. Func(3) should return t

2010-07-24 Thread Shafi Ahmad
@jalaj your code will not work for list having negative numbers. A: 8, 9, 12, 14 (Sorted) B: -5, -4, 1, 10 (Sorted) num=3 Regards, Shafi On Sat, Jul 24, 2010 at 3:17 PM, Algoose chase harishp...@gmail.com wrote: @jalaj TRY A:16, 12, 10, 6 ,2 B:11, 10,7, 2, 1 num: 26 On Sat, Jul 24,

Re: [algogeeks] Re: interview microsoft............

2010-07-24 Thread Ashish Goel
this is a recursive problem, the moment it says that there are n lists, it becomes recursive, the solution i have given can be made generic even though the sample is for 3 if total number of elements in a list is m i.e. 2 power k //function to merge two lists L1S//represents start of list 1

[algogeeks] Re: unset leftmost bit

2010-07-24 Thread Dave
int ClearHighestBitSet (unsigned int n) { double x; int exp; x = frexp((double)n, exp); return n ^ (1 (exp-1)) } To see how it works, look up the standard C++ function frexp. Dave On Jul 23, 10:15 am, Tech Id tech.login@gmail.com wrote: Write a C function that unsets

[algogeeks] Abstract computer

2010-07-24 Thread BALARUKESH
You have an abstract computer, so just forget everything you know about computers, this one only does what I'm about to tell you it does. You can use as many variables as you need, there are no negative numbers, all numbers are integers. You do not know the size of the integers, they could be

Re: [algogeeks] pointer and array

2010-07-24 Thread Manjunath Manohar
when arrays are passed as arguments to a function,the starting address of the array is passed like a pointer, thus sizeof(arr)=2..thus 2/2=1..this is the precise reason for always specifying the column length in the definition of function when functions have arrays as one of the arguments.. Hope

[algogeeks] pallindrome

2010-07-24 Thread dreamer ................
please tell me how to find longest pallindrome in a string in linear time -- 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] memory allocation

2010-07-24 Thread dreamer ................
Write a code that will check whether the memory allotted to the program at the initial and the memory returned to the system is same or not. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] sort

2010-07-24 Thread dreamer ................
You are given a doubly link list and out of some nodes of this doubly linked list, some other doubly link list emerge and from some of these emerging doubly linked list, more doubly link list emerge. You have to write a quick algo that merges all these doubly linked list into a singly linked list

Re: [algogeeks] pointer and array

2010-07-24 Thread tarak mehta
void hell(int arr[]); main() { int arr[]={1,2,3,4,5}; hell(arr); } void hell(int arr[]) { printf(%d,sizeof(arr)/sizeof(*arr)); } even this gives 1 !! @manjunath ur idea seems correct..but could u plz elaborate a bit On Sat, Jul 24, 2010 at 10:51 PM, Manjunath Manohar

[algogeeks] Re: Abstract computer

2010-07-24 Thread Dave
I assume that loop(0) skips the body of the loop. 1. If given m 0, this code sets m = m - 1. If given m = 0, it leaves m = 0. k = 0; loop(m) { m = k; k++; } 2. If given m = n, this code sets m = m - n. If given m n, it sets m = 0. loop(n) { k = 0; loop(m) { m = k;

Re: [algogeeks] You have 2 arrays of integer. You have to write a function, which take an integer as input and returns bool. Example array 1 has {1,5,10} array 2 has {2,5,9}. Func(3) should return t

2010-07-24 Thread jalaj jaiswal
hmm. thnxx for the case On Sat, Jul 24, 2010 at 3:17 PM, Algoose chase harishp...@gmail.com wrote: @jalaj TRY A:16, 12, 10, 6 ,2 B:11, 10,7, 2, 1 num: 26 On Sat, Jul 24, 2010 at 5:13 AM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: Take two pointers both at the start of each

[algogeeks] algorithm

2010-07-24 Thread jalaj jaiswal
You are given a stream of numbers which can be positive or negative. You are required to provide an operation FIND MEDIAN..which when invoked should be able return the median of the numbers in stream (in sorted order) in O(1) time. Eg: 0 1 2 3 4 Right FIND MEDIAN returns 2 as median Now input is

Re: [algogeeks] Re: BST

2010-07-24 Thread Priyanka Chatterjee
@Rahil: you are correctthanks On 24 July 2010 18:33, rahul patil rahul.deshmukhpa...@gmail.com wrote: 1 convert the BST into a sorted doubly linklist.(increasing order) It will take O(n) time. 2 Now find two nodes in a link list whose sum is k(given no) to find sum in linklist. take two

Re: [algogeeks] pointer and array

2010-07-24 Thread Apoorve Mohan
@tarak: You can see it like this. When we create an array then 'a' points to the whole array not just the first element so it returns the size of the whole array. when you pass the array though by default in c it is pass by value but as you are passing the address of the array so it acts like

Re: [algogeeks] pallindrome

2010-07-24 Thread Amir hossein Shahriari
take a look at this: www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/ -- 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

Re: [algogeeks] pointer and array

2010-07-24 Thread Manjunath Manohar
@Apporve... yeah u r right :)sizeof ptr is always 2 in 16 bit compilers, i.e, the sizeof an address is 2.and the sizeof(int)=2..i.e sizeof(*arr)=2..hope u got it now.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send