I think this will work.
# include stdio.h
void my_print(int *,int);
void swap(int a , intb)
{
a = a + b;
b = a - b;
a = a - b;
}
void sort(int* array, int SIZE, int i, int j)
{
while(ij)
{
my_print(array,SIZE);
if(array[i] = array[j])
Is not ur code is running in o(n^2) complexity
You have used two while loop ...
plzz eleborate if i m wrong .
On Jul 12, 11:00 am, Amit Mittal amit.mitt...@gmail.com wrote:
I think this will work.
# include stdio.h
void my_print(int *,int);
void swap(int a , intb)
{
a = a + b;
if we have 1 2 5 7 3 4 6
can you explain how to do in place merge... the elements are in an array
?
On Sun, Jul 11, 2010 at 10:29 AM, jalaj jaiswal
jalaj.jaiswa...@gmail.comwrote:
its easy
suppose the array is 12345 4321 2345 4321
it increases then dcreases then increases and
Partitioning a given integer n into unique partitions of size m. like
if n=10,m=4, 7111 is one
such partition. Give all such partitions
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
traverse array with 2 elements keeping track of 2 min elements. time
O(n) space O(1)
On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
Constraint - O(n)
On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
Given an array of size n.find 2 numbers from array whose
is it something different than this
foo(char *p, int num)
{
if(!p) return error
if(num 0 p[num-1] == 0) print 2 byte value
else
print 1 byte value
}
On Jul 11, 11:18 pm, Tech Id tech.login@gmail.com wrote:
Question is not clear to me :(
Can
traverse array with 2 elements keeping track of 2 min elements. time
O(n) space O(1)
On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
Constraint - O(n)
On Sun, Jul 11, 2010 at 9:24 AM, amit amitjaspal...@gmail.com wrote:
Given an array of size n.find 2 numbers from array whose
2 6 3 7
check for this
On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar vikas.kumar...@gmail.comwrote:
traverse array with 2 elements keeping track of 2 min elements. time
O(n) space O(1)
On Jul 11, 9:34 pm, Amit Jaspal amitjaspal...@gmail.com wrote:
Constraint - O(n)
On Sun, Jul 11,
order nlogn is trivial ..
any thing better ??
On Mon, Jul 12, 2010 at 2:51 PM, srikanth sg srikanthini...@gmail.comwrote:
2 6 3 7
check for this
On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar vikas.kumar...@gmail.comwrote:
traverse array with 2 elements keeping track of 2 min elements.
edit distance..
On Mon, Jul 12, 2010 at 10:22 AM, Anil Kumar S. R. sra...@gmail.com wrote:
Use the A* Search approach, which is based on a function f(x) = g(x) +
h(x), where f(x) is
the total cost, g(x) is the cost to travel to the current node and h(x) is
the heuristic
estimate of the cost
i can give an idea..
start from the LHS bit.. ( for 3 =*0*101)
divide all numbers in two groups A0and A1 , A1 = 1XXX, A0 = 0XXX form
we know that an element in A1 xor an element in A0 will give the soln for
this..
IF either of set is empty then we have to go further like this way
now divide A1
i think ques is not complete..
otherwise above ans is rite.. i suppose..
On Mon, Jul 12, 2010 at 10:00 AM, Anand anandut2...@gmail.com wrote:
you can use longest common subsequence algorithm to solve it.
http://codepad.org/NDAeIpxR
On Sun, Jul 11, 2010 at 9:32 AM, amit
you can find both the smallest and the second smallest number ...
Anil
On Mon, Jul 12, 2010 at 3:21 PM, ankur aggarwal ankur.mast@gmail.comwrote:
order nlogn is trivial ..
any thing better ??
On Mon, Jul 12, 2010 at 2:51 PM, srikanth sg srikanthini...@gmail.comwrote:
2 6 3 7
check
oh never mind that was wrong... :P
Anil
On Mon, Jul 12, 2010 at 5:03 PM, Anil C R cr.a...@gmail.com wrote:
you can find both the smallest and the second smallest number ...
Anil
On Mon, Jul 12, 2010 at 3:21 PM, ankur aggarwal
ankur.mast@gmail.comwrote:
order nlogn is trivial ..
You will need width of each bar too perhaps.
Why should this need any algo?
Just get the one which has maximum height or if width is also given
then the one with maximum height x width
It is O(n)
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks
This is a good solution.
Reversing the arrays will be O(n)
Then merging will be O(n) too.
In place merge is something like this.
Have two indices as start1 and start2
start1 points to beginning of mini-sorted portion1
start2 points to beginning of mini-sorted portion2
Increase both start1 and
This can be done by recursion.
Each number can be represented as:
N =
1) (N-1), 1
2) (N-2), 2
3) (N-3), 3
N) (1), (N-1)
For each number (N-k), repeat the above in recursion.
= Gives all the unique partitions.
--
You received this message because you are subscribed to the Google
send your matching profiles to *...@dwlabs.com
*
Hello,
We have this immediate need with our direct client in Tampa, please let me
know if you have any suitable candidates.
*Req: Mainframe Developer (Telecom industry experience is a huge plus)*
Skills:* Mainframe, **Sync Sort**, JCL,
@ above can u please be more specific
let A[1,9,10] and B [2,4,6]
Now how to swap so that the complexity remains O(n)
-- Forwarded message --
From: Tech Id tech.login@gmail.com
Date: Mon, Jul 12, 2010 at 8:18 PM
Subject: [algogeeks] Re: sort in O(n)
To: Algorithm Geeks
Given a text file, implement a solution to find out if a pattern
similar to wild cards can be detected.
fort example find if a*b*cd*, or *win or *def* exists in the text.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group,
@ above Consider S=anand T={'d','n'.'a'}
LCS is na but the Answer is and . Here the order of characters don't
matter as i have mentioned .
One way is you can take LCS with every possible permutation of T but that
would be exponential
On Mon, Jul 12, 2010 at 3:23 PM, ankur aggarwal
I am not sure if the above is very clear.
Ankur, if you can explain it some more, it would be really great.
--
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
1.Give an efficient algorithm which takes as input a directed graph G =
(V,E), and determines whether or not there is a vertex s is in V from which
all other vertices are reachable.?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to
Give a linear-time algorithm for the following task.
Input: : A directed acyclic graph G (V,E)
Question: Does G contain a directed path that touches every vertex exactly
once?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this
@amit: In this case, we can calculate the length of string S and T and
reverse the string whose length is smaller than the other. Then Take LCS of
it. To get the final answer.
On Mon, Jul 12, 2010 at 7:05 AM, Amit Jaspal amitjaspal...@gmail.comwrote:
@ above Consider S=anand T={'d','n'.'a'}
topological sort would cover every vertex once. The path given by
Topological sort would be the answer. We can also calculate the vertices
given by topological sort and compare it with given vertices. if it is same
then graph G does contain a directed path that touches every vertex exactly
once.
How will you search an integer in just 32 comparisons in an unsorted
group of integers?
Devise a data structure for it.
--
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
@amit: according to your given example this how the logic works.
In the below code I took an array a[]={1,9,10,2,4,6}; in the example at the
mid point second array start so mid point logic works here. but according to
given question we can scan through the array once and can find out where
u are using extra memory which is not supposed to be done..
On Mon, Jul 12, 2010 at 10:56 AM, Anand anandut2...@gmail.com wrote:
@amit: according to your given example this how the logic works.
In the below code I took an array a[]={1,9,10,2,4,6}; in the example at the
mid point second
In case if you need in place merging than you need to use bi- tonic merge.
But the only condition is total array length should be power of two.
http://codepad.org/hG8CnM1l
On Mon, Jul 12, 2010 at 11:13 AM, srikanth sg srikanthini...@gmail.comwrote:
u are using extra memory which is not
2 coordinate points p(x,y)and q(x,y) are given and write an algorithm to
draw aline
--
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
draw a line or equation of a line?
On Mon, Jul 12, 2010 at 4:38 PM, Anand anandut2...@gmail.com wrote:
2 coordinate points p(x,y)and q(x,y) are given and write an algorithm to
draw aline
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To
@anand ..can you explain it more with example
On Mon, Jul 12, 2010 at 10:19 AM, Anand anandut2...@gmail.com wrote:
topological sort would cover every vertex once. The path given by
Topological sort would be the answer. We can also calculate the vertices
given by topological sort and compare
@jalaj: sorry for delay i was busy these days
the implementation of my method is a bit hard because R2 and R4 which i
mentioned before are not always squares
and in that case we must first break the rectangles into squares and then
perform the search on squares
here breakToSquares function breaks
@ anand I think u did'nt get the point
what if T=['n' , 'n', 'a']
then if u reverse u wont get any LCS but answer is nan . Plz try to get
the jist of the question.
On Mon, Jul 12, 2010 at 10:44 PM, Anand anandut2...@gmail.com wrote:
@amit: In this case, we can calculate the length of string S
dp[i][j] is the number of strings that have i As and j Bs
dp[0][0]=1; // s=
for (i=1;i=n/2;i++)
dp[i][0]=1; // s=AAA...
for (i=1;i=n/2;i++)
dp[0][i]=0; // the 2nd constraint
for (i=1;i=n/2;i++)
for (j=1;j=n/2;j++)
if (ji)
dp[i][j]=0; // the 2nd constraint
else
make a bitwise trie
since the height would be 32 (number of bits in an integer) u only need 32
comparisons to find an element
--
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
This problem cannot be solved in less than O(nlgn) time with O(1)
space. The Element Distinctness Problem has a proven lower bound of
Omega(nlgn). If the least difference problem could be solved in O(n)
then we can reduce the ED Problem to Least Difference problem and
solve it in O(n) time. This
your 1st Q:
for each vertex run a dfs and count the number of vertices it can reach O(
V^2 + VE )
another solution would be using an algorithm similar to floyd-warshal O(V^3)
a[src][dest] is true if there is an edge src-dest
for (k=0;kn;k++)
for (i=0;in;i++)
for (j=0;jn;j++)
if (a[i][k]
this can be done in O(n) using DP:
for (i=n-1;i=0;i--){
dp[i]=max(dp[i+2],dp[i+3]); // usual
if (a[i]==a[i+1]) // excellent size 2
dp[i]=max(dp[i],2+dp[i+2]);
if (a[i]==a[i+1] a[i+1]==a[i+2])//excellent size 3
dp[i]=max(dp[i],2+dp[i+3]);
if (a[i]==a[i+1] || a[i]==a[i+2] ||
@abv amit askd inplace merging
On Mon, Jul 12, 2010 at 11:26 PM, Anand anandut2...@gmail.com wrote:
@amit: according to your given example this how the logic works.
In the below code I took an array a[]={1,9,10,2,4,6}; in the example at the
mid point second array start so mid point logic
Algorithm to draw a line. While searching on net, I got few pointers.
http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html
On Mon, Jul 12, 2010 at 4:53 PM, ashish agarwal
ashish.cooldude...@gmail.com wrote:
draw a line or equation of a line?
On Mon, Jul 12, 2010 at 4:38 PM, Anand
@amit..can you little explain this
On Mon, Jul 12, 2010 at 4:50 PM, Amir hossein Shahriari
amir.hossein.shahri...@gmail.com wrote:
this can be done in O(n) using DP:
for (i=n-1;i=0;i--){
dp[i]=max(dp[i+2],dp[i+3]); // usual
if (a[i]==a[i+1]) // excellent size 2
On Jul 12, 10:48 am, Tech Id tech.login@gmail.com wrote:
This is a good solution.
Reversing the arrays will be O(n)
Then merging will be O(n) too.
In place merge is something like this.
Have two indices as start1 and start2
start1 points to beginning of mini-sorted portion1
start2
@ashish: i think u meant amir! anyway...
profit for an excellent group is 2 and for a good group it's 1
dp[i] is the max profit for memorizing a[i], a[i+1], ... , a[n]
dp is initialized to 0
so for example if a[i]==a[i+1]==a[i+2] it means that we can group a[i]
a[i+1] a[i+2] together in an
suppose n is the size of S and m is the size of T
make to pointers p1=0 and p2=0
make another array C[]={0,0,...} which c[i] counts the number
of occurrence of T[i] in S[p1],S[p1+1]...S[p2]
n1=0 is the number of nonzero elements in C so each time n1==m means that
range p1..p2 can be an answer
See en.wikipedia.org/wiki/Bresenham's_line_algorithm
Dave
On Jul 12, 7:38 pm, Anand anandut2...@gmail.com wrote:
2 coordinate points p(x,y)and q(x,y) are given and write an algorithm to
draw aline
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks
On Jul 11, 9:58 am, amit amitjaspal...@gmail.com wrote:
Give a algorithm to remove extra pair of parenthesis
Remove unnecessary from an expression :
1) (((a))) = a
2) (a+b) = a+b
3) (a+b)*c = (a+b)*c
4)(((a+b)*(c+d))+e) = (a+b)*(c+d)+e
We can build an abstract syntax tree with a simple
On Jul 12, 10:56 am, Tech Id tech.login@gmail.com wrote:
This can be done by recursion.
Each number can be represented as:
N =
1) (N-1), 1
2) (N-2), 2
3) (N-3), 3
N) (1), (N-1)
For each number (N-k), repeat the above in recursion.
You have the right idea, but this
You have an array like ar[]= {1,3,2,4,5,4,2}. You need to create
another array ar_low[] such that ar_low[i] = number of elements lower
than or equal to ar[i] in ar[i+1:n-1].
So the output of above should be {0,2,1,2,2,1,0}
Time complexity : O(nlogn)
use of extra space allowed.
Can anyone help
here's an algorithm that can find the the max black rectangle in O(n^3)
here sum[i][j] is the number of contiguous 1s in the ith row from j column
until the end of the row
for (i=0;in;i++){
sum[i][m]=0;
for (j=m-1;j=0;j--){
if (a[i][j]==1)
sum[i][j]=1+sum[i][j+1];
else
sum[i][j]=0;
}
}
so now
good 1.
On Tue, Jul 13, 2010 at 2:56 AM, Amir hossein Shahriari
amir.hossein.shahri...@gmail.com wrote:
make a bitwise trie
since the height would be 32 (number of bits in an integer) u only need 32
comparisons to find an element
--
You received this message because you are subscribed to
@Gene
Please explain the recursive function and the first if condition i
m not getting it.
--
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,
I did not get your point.
for 2 6 3 7
min 2
sec min 3
difference is 1
answer is 2 and 3
what more is asked??
On Jul 12, 2:21 pm, srikanth sg srikanthini...@gmail.com wrote:
2 6 3 7
check for this
On Mon, Jul 12, 2010 at 12:46 AM, vikas kumar vikas.kumar...@gmail.comwrote:
traverse array
54 matches
Mail list logo