Write a function getBits that gives bits from a given position p of a
given number n.
Diff between typedef and #define?
Suggest DS for polynomials. Write C program to add two polynomials.
Regards
Shashank
--
You received this message because you are subscribed to the Google Groups
Algorithm
If we rewrite question in terms of Probability, call to foo2() depends on
two events:
1. (E1) A B, probablity 75%.
2. (E2) C D, again probability 75%.
Probability (E) = Prob(E1) * Prob(E2) = 75/100 * 75/100 * 5000 = 2812.50
times.
Correct me if wrong.
- Dinesh Bansal
On Wed, Dec 15, 2010 at
@ashish. u r getting wrong if else makes complete unit so if 1
fails other executes..no doubt in these..its not tough as much as u
taking it
what ii think some guys r right i got same solution..i don't thinsg
to xplain becoz, kathir,ankur has xplained same... answer will be
2812
1. int getBits(int n, int p) { return (n p) 1; }
2. use internet
3. depends, may be linked list of terms or array of coefficients.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
Which one is the efficient sorting technique for arranging the books
in a library?
a) Bubble Sort
b) Selection Sort
c) Insertion Sort
d) Heap Sort
Regards
Shashank
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group,
let S be the set containing n people
int i=0,j=n-1;
while(i!=j)
{
*ask S[i] if he knows S[j]*/
if(YES)
i++;//if yes then S[i] cant be the celebrity take him
out of the equation
else
j--; //if no then S[j] cant be the celebrity so let him
pass
}
Thnx a lot !
On Tue, Dec 21, 2010 at 1:18 AM, Dave dave_and_da...@juno.com wrote:
@Shalini: You can find a table of Fibonacci numbers at
http://en.wikipedia.org/wiki/Fibonacci_number#List_of_Fibonacci_numbers.
You will notice that every third number in the sequence is even, and
that there
Convert the given number in to binary and stored into every bit into
array
now compare the a[i]==0 if true then print that value that is nithing
but zero else number doesn't has zero in its binary form.
e.g code is given below
int binary_zero(int n)
{
for(int i=0;iarraylength;i++)
{
a[i]=n%2;
hey in last program i forget to take a variable that the position of
one so that we can print zero groups
shashank
--
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
u can see topcoder and codechef tutorials may help
--
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
The question is to find the length of the smallest cycle in a
bipartite graph G=(V,E) (V - vertices, E - edges).
Required time complexity: O(|V|^2)
A given graph is bipartite iff it has no odd length cycles.
--
You received this message because you are subscribed to the Google Groups
Dear Shashank
What will get executed if AB and CD, then will foo2 get executed? NO
In worst cast(when AB and CD happens at same time i.e.25%), the foo2 fn
will get executed 50% i.e. 2500 times
Don't get me wrong, but closed mind is one of the reason people get
rejected.
Best Regards
Ashish
insertion sort in IMHO
On Tue, Dec 21, 2010 at 5:44 PM, bittu shashank7andr...@gmail.com wrote:
Which one is the efficient sorting technique for arranging the books
in a library?
a) Bubble Sort
b) Selection Sort
c) Insertion Sort
d) Heap Sort
Regards
Shashank
--
You received this
Fleury algorithm.
- Ursprüngliche Mitteilung -
The question is to find the length of the smallest cycle in a
bipartite graph G=(V,E) (V - vertices, E - edges).
Required time complexity: O(|V|^2)
A given graph is bipartite iff it has no odd length cycles.
--
You received this
insertion sort
On Tue, Dec 21, 2010 at 6:49 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote:
insertion sort in IMHO
On Tue, Dec 21, 2010 at 5:44 PM, bittu shashank7andr...@gmail.com wrote:
Which one is the efficient sorting technique for arranging the books
in a library?
a) Bubble
ashish , nobody is fighting here , but are u sure you are clear on
your probability concepts ? independent events do multiply .
what is the probability that when we toss three coins , we get all three heads ?
On Tue, Dec 21, 2010 at 6:45 PM, Ashish Goel ashg...@gmail.com wrote:
Dear Shashank
Given a chessboard in which it is not known how the black and white
boxes are arranged but it is sure that there will 32 black squares and
32 white squares. You have to find the least possible distance between
any two squares of same colour.
--
You received this message because you are
this is not probability purely...there is an else in between :)
why don't you write the program and test it out yourself :)
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Tue, Dec 21, 2010 at 6:52 PM, Ankur Khurana
can you provide the test cases ?
between ,
btw answer my question abt the tosses. plus closed mind argument goes
both ways. i have tried to explain.
if you dont want to understand , it is nobody's prob.wont comment
further on this topic.
On Tue, Dec 21, 2010 at 6:55 PM, Ashish Goel
test
a] AB, CD
b] AB, CD
c] A=B, CD,
d] AB, CD
e] AB, CD
f] A=B, CD
g] A=B, C=D
AB is 25% means the case could be a or d 25% in both cases CD does not
get executed as if condition is satisfied
and CD is 75% means case could be a or b or c. in case a foo2 will not get
executed but in b,c it
CD was 75%. no ?
On Tue, Dec 21, 2010 at 7:16 PM, Ashish Goel ashg...@gmail.com wrote:
test
a] AB, CD
b] AB, CD
c] A=B, CD,
d] AB, CD
e] AB, CD
f] A=B, CD
g] A=B, C=D
AB is 25% means the case could be a or d 25% in both cases CD does not
get executed as if condition is satisfied
and
You are given an (unsorted) set of n integers. Given some k (1 k =
n), you are required to find and return the element of the set that
has more than n/k occurrences. Return None otherwise.
Required (best known) time complexity: O(n log k)
I thought of something... Lets scan each element one by
You are given a set of 'n' points on a two dimensional plane. Now,
draw a straight line such that it can pass through maximum number of
points. Return the maximum number of points.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to
Hint: If the colors are not arranged as in a normal chess board, then
there will be at least two adjacent squares that have the same color.
Dave
On Dec 21, 7:25 am, snehal jain learner@gmail.com wrote:
Given a chessboard in which it is not known how the black and white
boxes are arranged
How do you write your own random function?
--
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.
Answered at http://groups.google.com/group/algogeeks/msg/d329dda12b332dd1.
Dave
On Dec 21, 8:24 am, snehal jain learner@gmail.com wrote:
You are given a set of 'n' points on a two dimensional plane. Now,
draw a straight line such that it can pass through maximum number of
points. Return
Use count sort logic.It will be O(n). Bt space complexity matters there.
--
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
no need to store in array
the function can look like this
int fun(int n)
{
int i=0,count=0;
boolean set=false;
while(isizeof(n)*8)
{
if(n^1==1)
{
if(set==false)
{
count++;
set=true;
}
}
else
set=false;
n=n1;
}
On Dec 21, 6:07 pm, shubham singh shubhamsisodia0...@gmail.com
wrote:
u can see
can u explain why and how
On Dec 21, 6:22 pm, bhupendra dubey bhupendra@gmail.com wrote:
insertion sort
On Tue, Dec 21, 2010 at 6:49 PM, Ankur Khurana
ankur.kkhur...@gmail.comwrote:
insertion sort in IMHO
On Tue, Dec 21, 2010 at 5:44 PM, bittu shashank7andr...@gmail.com
@juver
I didnt get the approach.Could you please explain for the below
expression.
3 + 6 * 7 + 3 * 2
On Dec 20, 10:46 pm, juver++ avpostni...@gmail.com wrote:
Keep 2D arrray. For each segment (i, j) calculate min and max value for the
subexpression.
To do this, iterate k over (i, j),
There is an array, how will you partition that into two parts so that
the sum of both the sub set is minimum
--
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
@Prims:
It looks something like this:
take an array num to store:3 6 7 3 2 (sequentially as it is)
Take another array op : + * + * (sequentially as it is)
Now make a 5X5 2-D array maxResult
where maxResult[i][j] means maximum value of the subexpression form
num[i] to num[j]
Here n=5;
so u have to
please whats the primary key for books in the library?
On 12/21/10, rajessge...@yahoo.com rajessge...@yahoo.com wrote:
can u explain why and how
On Dec 21, 6:22 pm, bhupendra dubey bhupendra@gmail.com wrote:
insertion sort
On Tue, Dec 21, 2010 at 6:49 PM, Ankur Khurana
Result for the max[i,j] depends not only on max[k, l] but min[k,l]. E.g. for
/ operation maximum result is achived - division of max number by min
number.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
I think you mean absolute diffrence bewteen two sums is minimal. It's a DP
problem.
--
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
Sort the array and then process it in O(n) 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
It is given in the question Given an expression E of n numbers with
*, + operations.So,I dont think that min array is required is
required in this case.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
I would use Insertion sort if the Library gurantees Insertion in O(1).
Practically, I do that in Library push a book somewhere in middle.
Then the recurrence so obtained is : T(n) = T(n-1) + O(1) which gives O(n)
time complexity.
PS: It also speaks about Lateral thinking and whatever they call
Yes, for {+,*} operations set Max state is enough.
--
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
Sounds like Project Euler ... problem 2, to be precise.
On Tue, Dec 21, 2010 at 4:31 AM, Shalini Sah
shalinisah.luv4cod...@gmail.com wrote:
Thnx a lot !
On Tue, Dec 21, 2010 at 1:18 AM, Dave dave_and_da...@juno.com wrote:
@Shalini: You can find a table of Fibonacci numbers at
O(N) if everybody knows everybody.
O(N^2) if there is no such condition. (i.e. Ask for each person to
everybody.)
On Mon, Dec 20, 2010 at 9:43 PM, Bhavesh Chauhan chauhan.bhave...@gmail.com
wrote:
Every question can eliminate 1 person so you can identify the spy in N-1
questions.
Bhavesh
IMHO
1.When books are nearly sorted : Insertion sort and can be incorporated with
Shell sort technique @ O(n^1.5) provided number of books are in '000s
2.If number of books are huge in millons so its Heap sort will be better and
taking the burden of coding build heap @ O(N) is justified.This
ya through down pointer we can print..coz each time i m making fwd as
NULL
On Dec 20, 2:33 pm, Rishi Agrawal rishi.b.agra...@gmail.com wrote:
See inline ..
On Sat, Dec 18, 2010 at 12:09 PM, siva viknesh sivavikne...@gmail.comwrote:
Given a linked list structure where every node
There can be a simple check.
For any element to occur n/k times or more .It has occur atleast once in
every subset of (n/k)+1 size.So we take a window of n/k+1 size and set the
hash of every number equal to 1.These are the only probable elements which
can occur n/k times or more.
We move the
Brute force :
Have 2 pointers one pointing to last character and other pointing to the
first occurrence of last character. compare the chars at the corresponding
positions and decrement both pointers. when the latter hits -1 increment the
counter and reset it to its original value. if the
@saurabh Sum of all the elements of subset.
On Tue, Dec 21, 2010 at 11:42 PM, Saurabh Koar saurabhkoar...@gmail.comwrote:
sum of both the sub set is minimum means
sum of subset1+sum of subset = constant(=sum of the total array)
When one decreases the other increases.
Plzz give an
@Bhupendra
Thanks for pointing it out
actually, it should be
3.now first element in A[0]..A[j-1] greater than min is 7(index 1) and *LAST
* element in
A[k+1]A[n] less than max is 1(index 9)
if you look at code, it was proper
for( i = e+1; i n; i++)
{
if(arr[i] max)
e = i;
@Swapnil I got a counter example for my approach.By O(8) i mean O(c) c: a
constant leading to O(1).
On Tue, Dec 21, 2010 at 2:10 AM, Saurabh Koar saurabhkoar...@gmail.comwrote:
@yq: Can u plzz inform what was ur approach/logic while deriving the
condition that index will be increased of that
zero_group(N) {
c=1-(N1); // For even N, zero groups is one more than 1 groups.
while(N) {
d = (N(-N)); // Get the least significiant bit.
N = N+d; // Clear the last 1-group bits
c++; // inc counter.
}
return c;
}
For more bit manipulations, refer to
@Saurabh You used an extra pointer compared to shiva's code ,you can avoid
that. :)
On Mon, Dec 20, 2010 at 8:24 PM, Saurabh Koar saurabhkoar...@gmail.comwrote:
@Rishi:I think Shiva's code is also fine.U can access the list easily
by using down pointer in his code.
Because he is assigning
You need to keep generating Fibonacci numbers until you meet the
condition.Check for even valued term by using TERM%2==0 and sum
up.Fibonacci series grows exponentially so n wont be very high.Take care
that it doesn't overflow integer range.
On Mon, Dec 20, 2010 at 8:36 PM, Shalini Sah
*Hi,*
*
*
*I wonder that if the element of the array contains negative integer?
*
On Wed, Dec 22, 2010 at 1:25 AM, snehal jain learner@gmail.com wrote:
There is an array, how will you partition that into two parts so that
the sum of both the sub set is minimum
--
You received this
@Nikhil: ya..rt
--
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
hi shashank,
for sparse polynomial addition we prefer use of linked list.for more
detailed
explanation
http://code-forum.blogspot.com/2010/11/polynomial-addition.html
for getbits function
http://code-forum.blogspot.com/2010/11/getbits-function-in-c.html
visit these links and post your comment if
@Nikhil: What if the array is 1 2 3 4 9 6 6 6 5 and k=3 ?
--
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
Given an array having 16000 unique integers, each lying within the
range 12, how do u sort it. U can load only 1000 numbers at a
time in memory
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
You have n machines contains n integer. How will you find the median
of n^2 element. Only 2n number can be loaded in the memory
--
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
Algorithms to check if binary representation of a number is palindrome
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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to
I want to see if all the ones in a number appear on the right side of
the number and all zeros appear on the left, how can I do this most
efficiently? (i.e. 0111 is true but 100010 is false)
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
Xcellent Shiva..keep goin on..\
Best Regards
Shashank Mani Narayan
BIT Mesra
--
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
If you are given a number as a parameter, write a function that would
put commas after every third digit from the right
--
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
if x is a 32 bit number
if((x0x)==((x16)0x)))
x's bit pattern is a polyndrome
--
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,
@Terence: I think the above fails for 0X.Correct me if I m wrong.
--
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
See External Sort at Wiki.
--
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
If there are two structs, TreeNode and Tree. TreeNode contains 3
elements, data, lChild and rChile. Tree contains 2 elements, int size
and TreeNode *root. The tree is a complete tree. So how to find a
O(logN) approach to insert a new node
--
You received this message because you are subscribed
void main(int arg,char *argc)
{
char *s=argc[1];
int count=0,i;
for(i=strlen(s)-1;i=0;i--)
{
count++;
printf(%c,s[i]);
if(count==3)
{
count=0;
putchar(',');
}
}
}
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send
How to output the number in a sorted way in which The sorting is done
based on string sorting and not on numerical
(Eg:121 comes before 2 because the Most Significant Digit is 1 in 121
which is less than 2)
disp(int low, int high);
disp(5, 1113);
Required Output is:
10
100
1000
11
12
.
.
19
101
Find the first node whose left child is NULL or Right child is NULL
using BFS.(As the tree is complete,all nodes before this will have two
children).Insert at that node.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group,
hi guys,
does anyone has experince with Sun Microsystem
interview rounds..if yes let me no..ASAP
Thanks Regards
Shashank Mani Narayan Dont B evil U Can earn While U Learn
Cell No- +91-9740852296
--
You received this message because you are subscribed to the Google Groups
uhhh... but isn't Sun dead?
Anil
On Wed, Dec 22, 2010 at 12:38 PM, bittu shashank7andr...@gmail.com wrote:
hi guys,
does anyone has experince with Sun Microsystem
interview rounds..if yes let me no..ASAP
Thanks Regards
Shashank Mani Narayan Dont B evil U Can earn
it takes O(n) and also O(n)extra space(queue)
On Wed, Dec 22, 2010 at 12:37 PM, Saurabh Koar saurabhkoar...@gmail.comwrote:
Find the first node whose left child is NULL or Right child is NULL
using BFS.(As the tree is complete,all nodes before this will have two
children).Insert at that node.
How could a linked list and a hash table be combined to allow someone
to run through the list from item to item while still maintaining the
ability to access an individual element in O(1) time
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To
since you know the size, you know exactly the path to the new node.
Sent from Nexus one
On Dec 21, 2010 11:10 PM, mo...@ismu mohan...@gmail.com wrote:
it takes O(n) and also O(n)extra space(queue)
On Wed, Dec 22, 2010 at 12:37 PM, Saurabh Koar saurabhkoar...@gmail.com
wrote:
Find the first
It's a lexicographical sorting. Use radix sort (MSB).
Or convert your numbers into a strings and use standard sorting routine.
Also you may code your own comparator.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send
I hope the code is self explainatory.
int main()
{
//num is the number
int prev =1, next=1,count=0;
while(num)
{
if(count1)
{
print false
break;
}
prev=next;
next=num%10;
num=num/10;
if(next!=prev)
count++;
}
if(count=1)
print true
}
--
You received this message because you are
It depends on the structure of the tree. Is it binary search tree? What is
the expected position of placing particular node in the tree?
Cause the tree is complete, we know that its height is log n
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks
may be he is talking oracle .
On Wed, Dec 22, 2010 at 12:40 PM, cr.a...@gmail.com cr.a...@gmail.com wrote:
uhhh... but isn't Sun dead?
Anil
On Wed, Dec 22, 2010 at 12:38 PM, bittu shashank7andr...@gmail.com wrote:
hi guys,
does anyone has experince with Sun Microsystem
stroe the pointers in the hash table. it will do i suppose.
On Wed, Dec 22, 2010 at 12:36 PM, snehal jain learner@gmail.com wrote:
How could a linked list and a hash table be combined to allow someone
to run through the list from item to item while still maintaining the
ability to access
count the no of bits lets say n
then answer becomes 2^n-1
--
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
Use bits manipulation tricks. There is a way to remove a group of
consecutive 1's from the right: A = n (n - 1). Then check A==0.
--
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 in duel with two other gunmen. First guy shoot with 100%
accuracy, second person shoot with 50% accuracy and you shoot with 33%
accuracy. Everyone will get a chance to shoot in every round and
shooting will start from the guy with worst accuracy. What will you
shoot in first round?
--
then access will not be O(1).. it will be on O(n) int he worst case when all
the nodes are hash to same location
On Wed, Dec 22, 2010 at 12:50 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote:
stroe the pointers in the hash table. it will do i suppose.
On Wed, Dec 22, 2010 at 12:36 PM, snehal
And what? Hash table provides O(1) expected time for access elements. We
should not speak about worst case if you should use hash table.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
@above
nice approach :)
On Wed, Dec 22, 2010 at 1:06 PM, juver++ avpostni...@gmail.com wrote:
Use bits manipulation tricks.
1. There is a way to remove a group of consecutive 1's from the right: A =
n (n + 1). Then check if A==0 then OK.
2. Second approach: B=n+1, check if B (B-1) (this
84 matches
Mail list logo