Hi,
This can be solved the technique to use stacks to save incomplete problems.
Push first element to stack.
While iterating over the array,
if the element is smaller than stack top, push it to stack along with index.
if the element is larger than stack top, pop till current element
is
@above right
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this
Create BST of given list...
1. using extra space now you can create DLL and inorder traversal
2. Create sorted linked list from DLL, Great tree list recusion
(cslibrary.stanford.edu/109/TreeListRecursion.pdf)
On Jan 31, 12:11 am, bittu shashank7andr...@gmail.com wrote:
can u provide
1. how do u find 10 most repeating words on a large file containing
words
in most efficient way
2.
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
please give your ideas for this
On Fri, Jan 21, 2011 at 2:28 PM, snehal jain learner@gmail.com wrote:
Magy! receives a huge amount of queries everyday. They don’t want to
store all of them, since many of the queries are unique (submitted
just one time by just one user). Anyway, for
Use google.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this
@above Are you kidding? :) What is the complexity of your solution? And why
not simply use merge sort?!
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this
You are given n segments. In turn, you take each one of them and join
it with one among those already selected, creating either a loop or a
longer segment. How many loops there are in average, at every instant
of time?
--
You received this message because you are subscribed to the Google Groups
Q : Given an array, one has to replace its elements in such a way that no
element is at its original place and the placement has to be random.
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
--
You received this message because you are subscribed to
Random shuffle algorithm:
for i = n - 1 to 1
j = random index within [0..i)
swap elements at (i, j)
end
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from
a try:
int minsum(int A[],int n)
{
int min=-1,cur=0,x1=0,x2=0,i;
for(i=0;in;i++)
{if(A[i]0)
{
min=A[i];
break;
}
}
if(i==nmin==-1)
return min;
for(i=0;in;i++)
{
cur =cur + A[i];
if(curcur-A[x1]i!=x1) {
cur=cur-A[x1];
x1=x1+1;
}
If space is not a constrain, try to do it using count sort
http://en.wikipedia.org/wiki/Counting_sort
Regards,
S.C.Harish
On Sun, Jan 30, 2011 at 6:10 PM, bittu shashank7andr...@gmail.com wrote:
Sort the Doubly Linked List..In Minim time complexity...is it possible
to sort doubly linked list
bittu,
you have written this code at end of main()
*printGivenOrder(start);
printList(rslt);*
so the BT in spiral order should be printed twice
But you are getting a extra 4 only in place of the whole tree because of
these lines
*temp=current;
current=head;
rslt=appnd(temp,current);
* There
First Approach,
0) the queries can be considered as an infinite stream. maintain a global
count of the number of queries coming from the stream (used for calc the
frequency %).
1) maintain a min-heap (has just top 100 queries by frequency) + hash table
(where we store frequency for each word in
Juver++..right its basically Knuth Shuffle Simple Algo..
http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
Thanks
Shashank
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
@above in your second approach, in the worst case you need to traverse the
heap 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 algogeeks@googlegroups.com.
To unsubscribe from this group,
@ above
ur code fails for following example
channel 1 : prog1 8:00-9:00, prog 2 9:00-10:00
channel 2 : prog1 8:15-10:00
your code returns 8:15- 10
and the answer should be channel1/prog1 + channel1/prog2
On 21 January 2011 12:54, Anand anandut2...@gmail.com wrote:
Sort all program with
@manoj
the great recursion problem has the time complexity as
tn=2(T(n/2))+O(1) . It is not linear .
ur algo is O(nlog n)
This can be possible using a counting sort (again , use Bitsets to
save ur space )
--
You received this message because you are subscribed to the Google Groups
Algorithm
The DP solution to this problem is very similar DP solution for counting the
number of Dyck words with some additional conditions.
while calculating DP[i][j] you need to check if i+j equals one from the
list of k values. if yes copy the value from the prev row(i.e DP[i-1][j])
instead of
Another approach would be to use a counting sort method (less space
efficient though )
So , for space efficiency , we can use a bitset .element insertion
will take O(n) time in the set (with a space complexity of O(log n) )
so , for the above elements , the bitset will look like
(the p# shows the
@above
Many ways to do this problem
One will be to find the bfs (there will be many and this will lead to
a forest )
This , in turn can be done in O(e+v) , using adjancy list or matrix .
Whenever , we cannot go further , start from any new uncovered node ,
and keep exploring recursively .Keep a
@wei.qui
On a second thought , if the petrol pumps have many petrol pumps
connected to it , we cannot find the answer your way or the method
suggested by me previously .
Thus , the solution becomes one to find out the Eulerian Path
(constraint based of course )
--
You received this message
or provide some link
On Mon, Jan 31, 2011 at 10:44 PM, snehal jain learner@gmail.com wrote:
@ juver++
can you please share your approach
On Mon, Jan 31, 2011 at 8:43 PM, Divya Jain sweetdivya@gmail.comwrote:
@ above
ur code fails for following example
channel 1 : prog1
You are given a wooden log of length n. It has n+1 grooves marked on
it from 0 to n. You are given an array containing numbers within the
range of 1 to n-1. These elements of the array represents the points
on the log at which u need to cut the wooden log. Now the cost of
cutting a log is
@Ralph
Build a data structure on array B[1..n] in O(n) time such that
the following problem can be solved in O(log n) time:
Given an index i and value v, find the index j of the first
element in B such that j = i and B[j] v.
Return -1 if no such j exists.
then it ll take
DP solution is ..
c[i][j] = min (c[i][k] + c[k][j] + (a[j]-a[i])) where k=i+1 to j-1
c[i][j] = a[j]-a[i] when j=i+1
c[i][j] indicates the minimum cost to cut the log starting at a[i] and
ending at a[j]...
c[0][n] gives the answer..
correct me if i am wrong or any better solutions?
--
You
DP solution is ..
c[i][j] = min (c[i][k] + c[k][j] + (a[j]-a[i])) where ji k=i+1 to
j-1
c[i][j] = a[j]-a[i] when j=i+1
c[i][j] indicates the minimum cost to cut the log starting at a[i] and
ending at a[j]...
c[0][n] gives the answer..
correct me if i am wrong or any better solutions?
--
You
plz help
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group
You have given a nice setup, but you haven't stated a problem or asked
a question.
On Jan 31, 12:14 pm, ritu ritugarg.c...@gmail.com wrote:
You are given a wooden log of length n. It has n+1 grooves marked on
it from 0 to n. You are given an array containing numbers within the
range of 1 to
Practice. Practice. Practice. After all, Practice makes perfect.
On Jan 31, 2:00 pm, sandy sandeep.aa...@gmail.com wrote:
plz help
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
http://geeksforgeeks.org/?p=3758cpage=1#comment-1371
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Sun, Jan 30, 2011 at 6:28 PM, sankalp srivastava
richi.sankalp1...@gmail.com wrote:
Spiral order .. means zigzag order for example
1
sorry ..the complete question is
You are given a wooden log of length n. It has n+1 grooves marked on
it from 0 to n. You are given an array containing numbers within the
range of 1 to n-1. These elements of the array represents the points
on the log at which u need to cut the wooden log. Now
vectorvectorint cuts(int n, vectorint A)
{
int min;
int numcuts = A.size();
vectorvectorint Cuts(vectorint V(0,n), n);
vectorvectorint Result(vectorint V(0,n), n);
for(int i=0;inumcuts;i++)
{
Cuts[A[i]][A[i]]=0;
Cuts[A[i]][A[i+1]]=0;
}
for(int
@sankalp the question is to change the Tree to a doubly linked list inplace
not to print
On Tue, Feb 1, 2011 at 9:11 AM, Ashish Goel ashg...@gmail.com wrote:
http://geeksforgeeks.org/?p=3758cpage=1#comment-1371
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
34 matches
Mail list logo