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
#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));
@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;
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
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
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-
@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,
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
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
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
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
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
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
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
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
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;
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
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
@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
@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
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
@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
22 matches
Mail list logo