@ anand all input is in 1 array n in ur approach u hve used 2 arrays ,bt
that is not d ques
--
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,
@anand. Perhaps, its not correct. Does not work for larger inputs.
Anurag Sharma
On Mon, Jun 7, 2010 at 3:35 AM, Anand anandut2...@gmail.com wrote:
Here is my approach is o(n).
http://codepad.org/YAFfZpxO
http://codepad.org/YAFfZpxO
On Sun, Jun 6, 2010 at 7:28 AM, sharad kumar
how abt using FSA ?
consider state as a remainder when the given no. is divided by 3.
Then we get a FSA for any length no. as
[image: fsa.JPG]
On Sun, Jun 6, 2010 at 12:15 AM, divya sweetdivya@gmail.com wrote:
Find if a number is divisible my 3, without using %,/ or *. You can
@Anand: Your solution will take huge space and can easily be made to
run out of memory!
If arr5[] = {12,12,6,6,635}, you will run into n^3 space complexity.
For arr[5]={12,12,6,6,390625} it will be n^6.
Sain
On Jun 7, 3:27 am, Anand anandut2...@gmail.com wrote:
Here is my approch which runs in
@Anand and @Minotaurus
The code seems to fail for 15.
Am I missing something?
On Mon, Jun 7, 2010 at 2:20 AM, Minotauraus anike...@gmail.com wrote:
@Anand: Thanks for the code. I knew you could do it by bit
shifting. :-)
On Jun 5, 10:21 pm, Anand anandut2...@gmail.com wrote:
Here is a
: Three containers are of 15,10 and 6 ltrs capacity. Initially its in
configuration (15,0,0). Make it to configuration (2,8,5)
--
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
Can someone tell me the difference between
1) const int i=5; 2) int i=5;
int *ptr=i; const int
*ptr=i;
In the first case i can be modified via ptr i.e *ptr++ is valid. In
the second case *ptr++ is illegal. Why is that so? Aren't
@sain: But the question demands O(n) time
On Mon, Jun 7, 2010 at 3:35 AM, Anand anandut2...@gmail.com wrote:
Here is my approach is o(n).
http://codepad.org/YAFfZpxO
http://codepad.org/YAFfZpxO
On Sun, Jun 6, 2010 at 7:28 AM, sharad kumar sharad20073...@gmail.comwrote:
this is ques by
Ok this is just counting now how to do the same to print all possibilities?
On Mon, Jun 7, 2010 at 1:14 PM, Raj N rajn...@gmail.com wrote:
@Dave: Hey i'm finding little difficulty in understanding the 3rd condition
- p(*k*,*n*) = 0 if *k* *n*
- p(*k*,*n*) = 1 if *k* = *n*
-
@Dave: Hey i'm finding little difficulty in understanding the 3rd condition
- p(*k*,*n*) = 0 if *k* *n*
- p(*k*,*n*) = 1 if *k* = *n*
- p(*k*+1,*n*)+p(*k*,*n*-*k*) otherwise
Can you explain me p(k+1,n) partition. I understood p(k,n-k)
On Mon, Jun 7, 2010 at 6:16 AM, Dave
@Dave: Thanks it really helped !!
On Mon, Jun 7, 2010 at 6:16 AM, Dave dave_and_da...@juno.com wrote:
In number theory, a partition of a positive integer n is a way of
writing n as a sum of positive integers. Two sums that differ only in
the order of their summands are considered to be the
changing vfork with fork gives the correct output but in case of vfork the
loop behaviour is unpredictable
@harit : I guess the child is simply reading the value of i from the same
data area of the parent.
First time it showed a garbage, after which it shows the value
inputted in the
@Anand :Your approach will turn out very crude if elements are something
like 1000, 2000
keeping an array i.e count[1000] is not feasible. I think souravsain's
approach is better.
On Mon, Jun 7, 2010 at 3:57 AM, Anand anandut2...@gmail.com wrote:
Here is my approch which runs in O(n).
We can do it in O(n * log n) by individually binary-searching for zero on
each of the rows. Once we get the index of the first position where zero
appears, counting the number of negative number is straight-forward.
Here is an even better O(N) algorithm which is very elegant:
Consider the
Here's a problem that occurs in automatic program analysis. For a set
of variables x1; .. ; xn, you are given some equality constraints,
of the form xi = xj and some dis equality constraints, of the form
xi != xj Is it possible to satisfy all of them? Give an efficient
algorithm that takes as
it might be referring to no of sequences (say T(n) ) with no consecutive 1's
for n = 3, ans would be 5 viz.
000, 001, 010, 100, 101
T(n) = fib(n+2)
where fib = Fibonacci series
which is interesting.
On Sat, Jun 5, 2010 at 11:40 AM, Raj N rajn...@gmail.com wrote:
@sharad: What about 101 even
The link http://geeksforgeeks.org/?p=1488 has many different solutions and
implementation of hashing method.
On Mon, Jun 7, 2010 at 12:59 AM, Raj N rajn...@gmail.com wrote:
@Anand :Your approach will turn out very crude if elements are something
like 1000, 2000
keeping an array i.e
#includeiostream
using namespace std;
int main(){
int a[4][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
int i=0,j,n=3,l=0,m=n;
j=n;
while(i=n){
int i1=i,j1=j,k=0,l=n;
for(;kj1;i1++,j1--){
swap(a[k][i1],a[j1][l]);
if(i!=0){
Hi guys d soln z quite easy by swapping the variables..
consider a1a2a3a4b1b2b3b4
In the first iteration, swap (a2,b1),(a4,b3) giving a1b1a3b3a2b2a4b4
In the second iteration, swap (a3b3,a2b2) which gives d soln...
a1b1a2b2a3b3a4b4...
Any comments on dis??
On Mon, Jun 7, 2010 at 1:51 PM, Raj N
@Sharad,
3 4 5
A= 6 7 9
1 2 8
If B[i,j] = A[n-j, n-i]
then
---
8 9 5
B = 2 7 4
1 6 3
Mohit Ranjan
On Mon, Jun 7, 2010 at 8:26 AM, sharad sharad20073...@gmail.com wrote:
write
is it possible ?
if we say nth state is [2, 8, 5]
I could not find possible (n-1)th state
Mohit Ranjan
On Mon, Jun 7, 2010 at 2:02 PM, sharad sharad20073...@gmail.com wrote:
: Three containers are of 15,10 and 6 ltrs capacity. Initially its in
configuration (15,0,0). Make it to
Hello Guys
Anyone have a implementation of knapsack 0-1 using brute force approach ?
Or. Do you have some link with a sample in C language?
Thanks
jean
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send
consider a tree. policemen is to be placed such that for each edge of
tree, there is a policeman on atleast one side of each edge. tell the
min no. of policemen and their locatn in time O(n)
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To
let a[n][n] be the input array nd b[][] be the output
for(i=0;in;i++)
for(j=0;jn;j++)
b[i][j]=a[n-j-1][n-i-1]
On 7 June 2010 08:26, sharad sharad20073...@gmail.com wrote:
write a c routine to flip an nXn matrix about its non major diagnol
3 4 5
6 7 9
Here is another approach.
Example: 23 (00..10111)
1) Get count of all set bits at odd positions (For 23 it’s 3).
2) Get count of all set bits at even positions (For 23 it’s 1).
3) If difference of above two counts is a multiple of 3 then number is also
a multiple of 3.
(For 23 it’s 2 so 23 is not
u r given a circularly sorted array of n integers ie the array was
1st sorted nd then left or right shifted any no. of times. search for
a given integer k in the array in O(logn) time
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to
@Raj,
no they are not same
case 1: i is const
case 2: ptr is const
and whatever is const cann't be modified
Mohit Ranjan
On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote:
Can someone tell me the difference between
1) const int i=5; 2) int i=5;
write an efficient algo to compute no. of sequences of n binary digits
that do not contain 2 1's in a row. eg 111 is invalid whereas
1001001 is valid..
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
Given a Binary Search Tree, write a program to print the kth smallest
element without using any static/global variable. You can’t
pass the value k to any function also
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this
1) const int i=5;2) int i=5;
int *ptr=i; const
int*ptr=i;
On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote:
Can someone tell me the difference between
1) const int i=5;
@souravsain :Your approach works really well..
Here is the Implementation:
http://codepad.org/ricAcQtu
On Sun, Jun 6, 2010 at 11:40 AM, souravsain souravs...@gmail.com wrote:
@divya:go through the elements and keep inserting them in a BST. While
inserting if elements already exists in BST,
So u want efficient algo for fibonacci numbers?
--
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14
--
You received this message because you are subscribed to the
A simple solution :
Use the union find data structure and add notes for x1...xn and the negation
of all these.
Every constraint makes one union.
Finally check if for any i , xi and !xi are connected.
It is worst case O(n lg n) for sure where n is the number of equations.
Average case is much
Hmmm. The first few Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21,
34, 55, ...
Of these, 3, 13, and 55 have binary representations with two 1-bits in
a row.
And 9, 10, 17, 18, etc are not included. So what was your question?
Dave
On Jun 7, 9:28 pm, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:
@Anand
Depending upon the sequence of data in the input, an insertion/search into
the (unbalanced) BST will take O(n) time causing the overall complexity to
shoot up to O(n^2) for each element counted once. Sourav's approach requires
a balanced binary search tree.
@Divya..
If you know something
getting fibonacci nos is trivial using matrix multiplication in almost
constant time.
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14
--
You received this message
Of course you should do it via swappings.. why would one think of anything
else :)
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
http://www.cse.iitb.ac.in/~rohitfeb14
On Mon, Jun 7, 2010 at 10:39 PM,
37 matches
Mail list logo