[algogeeks] Re: priority inversion
But if low priority process is preempted then it should give up its resources right? On Jun 20, 10:30 am, Anand wrote: > What if low priority process holds a lock to some critical section which > high priority process when allowed for execution needs it. So if low > priority process is pre-empted with out giving up the resouces, might give > rise to dead lock. > > > > > > > > On Mon, Jun 20, 2011 at 10:05 AM, ricky wrote: > > In priority inversion the high priority process has to wait for the > > low priority process. why can't it just preempt the low priority one > > instead of waiting? Is it becoz it will jeopardize system stability > > or something else? > > > -- > > 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 at > >http://groups.google.com/group/algogeeks?hl=en. -- 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 at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] priority inversion
In priority inversion the high priority process has to wait for the low priority process. why can't it just preempt the low priority one instead of waiting? Is it becoz it will jeopardize system stability or something else? -- 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 at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: spoj--two squares problem
thanks :) it worked. cheers On May 25, 12:12 pm, Saikat Debnath wrote: > I think your problem is you are using int. Use long long. > > > > > > > > On Thu, May 26, 2011 at 12:29 AM, ricky wrote: > > can anyone help me out with this problem: > >https://www.spoj.pl/problems/TWOSQRS/ > > It runs on my machine with this code but it gives wrong ans on their > > site. > > > #include > > #include > > > using namespace std; > > > int main() > > { > > int i=0,j=0,X=0,t=0,count=0; > > cin>>t; > > while(t--) > > { > > cin>>X; > > i=sqrt(X); > > j=sqrt(X-i*i); > > while(i>=0 && i>=j) > > { > > if((i*i)+(j*j)==X) > > {count++;} > > i--; > > j=sqrt(X-i*i); > > > } > > if(count>0) > > cout<<"Yes"; > > else cout<<"No"; > > count=0; > > cout< > } > > return 0; > > } > > > -- > > 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 at > >http://groups.google.com/group/algogeeks?hl=en. -- 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 at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] spoj--two squares problem
can anyone help me out with this problem: https://www.spoj.pl/problems/TWOSQRS/ It runs on my machine with this code but it gives wrong ans on their site. #include #include using namespace std; int main() { int i=0,j=0,X=0,t=0,count=0; cin>>t; while(t--) { cin>>X; i=sqrt(X); j=sqrt(X-i*i); while(i>=0 && i>=j) { if((i*i)+(j*j)==X) {count++;} i--; j=sqrt(X-i*i); } if(count>0) cout<<"Yes"; else cout<<"No"; count=0; cout
[algogeeks] Re: FUN TEASER 11 may
Nice one anil On May 13, 11:47 am, arjoo kumar <2009ar...@gmail.com> wrote: > good answer > > On Wed, May 11, 2011 at 8:52 PM, anil chopra wrote: > > > > > > > > > i will stop imaging. > > > On Wed, May 11, 2011 at 7:38 PM, Dave wrote: > > >> I was on a river boat in Europe, and the emergency drill was to go to > >> the upper deck and wait, high and dry, for the boat to sink into the > >> muddy river bottom. > > >> Dave > > >> On May 11, 2:09 am, Lavesh Rawat wrote: > >> > *FUN TEASER > >> > * > >> > * > >> > * > >> > ** > >> > *Imagine you are alone in a boat in the middle of a river. Suddenly the > >> boat > >> > starts to sink. You don't know swimming and no one is around to help > >> you. > >> > How do you get out of the situation? > >> > * > > >> > *Update Your Answers at* : Click > >> > Here< > >>http://dailybrainteaser.blogspot.com/2011/05/fun-teaser-11-may.html?l...> > > >> > Solution: > >> > Will be updated after 1 day > > >> > -- > > >> > "Never explain yourself. Your friends don’t need it > >> and > >> > your enemies won’t believe it" . > > >> -- > >> 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 at > >>http://groups.google.com/group/algogeeks?hl=en. > > > -- > > 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 at > >http://groups.google.com/group/algogeeks?hl=en. -- 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 at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] C++ Riddle
write the program to add two numbers without using arithmetic and bit operation.. -- 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 at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Good question
@jagan: that's true obj is a pointer to the data type for which size need to be calculated. On Feb 7, 10:38 am, jagannath prasad das wrote: > @rajiv:i guess obj is a pointer here > > > > > > > > On Mon, Feb 7, 2011 at 10:51 AM, Rajiv Podar wrote: > > Hi > > Try following code > > > Suppose we need to find size of variable *"obj"* > > int size = (char*)(obj +1 ) - (char*)(obj); > > > * > > *Thanks & Regards, > > Ricky > > > On Mon, Feb 7, 2011 at 12:19 AM, albert theboss > > wrote: > > >> using this macro > > >> size(X) ((X*)0+1) > > >> if we give size(int) it ll return 4. > >> size(double) gives 8. > > >> -- > >> 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 at > >>http://groups.google.com/group/algogeeks?hl=en. > > > -- > > 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 at > >http://groups.google.com/group/algogeeks?hl=en. -- 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 at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Puzzle to Puzzle you Part _ 1
Hi, I have come up with one interesting puzzle so I thought of discussing with you guys: "A blind man is given deck of 52 cards with 10 card facing up and rest are facing down. He need to create two piles not necessarily of same height in order to have same number of up cards in both." I would publish the solution one I got some good replies.. BTW: I will publish some more puzzles once I found that members are liking these puzzles.. Thanks!! -- 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 at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Minimum positive-sum subarray
Hi you can try the following code snippet: int array[] = {11, -12, 15, -3, 8, -9, 1, 8, 10, -2}; int length = 10; int max = 0; int current = 0; for (int i = 0; i < length; i++) { current += array[i]; max = max > current ? max : current; } std::cout<<"Max is : "< wrote: > @ above > didnt get you? why is the solution wrong? and if indices starting at 1 > bothers you then take > > P[i]= A[0] + A[1] + + A[i] > its one and the same thing.. > > On Wed, Feb 2, 2011 at 6:02 PM, sankalp srivastava < > > > > > > > > richi.sankalp1...@gmail.com> wrote: > > > This solution is wrong , never has it been said that the indices will > > occur from 1.i (if that is the case , you don't need to sort , > > just return the maximum /minimum sum obtained as a result) > > > The indices were b/w i..j such that 1<=i<=j<=n > > > O(n) solution does not exist .The state space tree will have n! leaf > > nodes(because there is some ordering on the input data , otherwise it > > would have 2^n leaf nodes) .Traversing the tree will take O(log n!) > > steps , or O(n log n) > > In fact a slight modification to this , the subset sum problem id NP- > > complete . > > But with the Q[i] array , you can get the answer with simple recursion > > ( or bfs or state space search or dp ) . > > > On Feb 2, 1:33 pm, snehal jain wrote: > > > @ above > > > its nt any homework question.. i found it a good question... aftr > > spending a > > > lot of time i came up with following solution > > > > Given Input Array A > > > > form the prefix sum array P of A. > > > > i.e P[i] = A[1] + A[2] + … + A[i] > > > > Now create another array Q of pairs (Value, Index) > > > > such that > > > > Q[i].Value = P[i]. > > > Q[i].Index = i > > > > Now sort that array Q, considering only Q[i].Value for comparison. > > > > We get a new sorted array Q’ such that Q’[i].Value Q’[i].Index > > > > Time complexity o( nlogn) > > > > and my O(n) which i posted earlier is giving incorrect result in some > > > case..so ignore that.. > > > > so does there exist O(n) solution for it also.. i had tried a lot but > > could > > > not figure out. but i think it should exist as there is for the other > > > variation.. > > > > On Tue, Feb 1, 2011 at 8:24 PM, sankalp srivastava < > > > > richi.sankalp1...@gmail.com> wrote: > > > > > You should not post homework problems . > > > > 1)For divide and conquer :- > > > > Read about interval trees , binary indexed trees , segments > > > > trees . > > > > Solve this using interval tree (By the time you solve a few > > > > basic problems of interval tree , you would be able to figure out a > > > > solution) > > > > > the function to calculate the parent will be > > > > 1) first check if the two are +ve > > > > 2) if yes , join both of them and also iterate on the sides left by > > > > both , to see if you can include them also (You only need to see the > > > > positive elements , no negative elements ) > > > > > T(n)=2T(n/2)+O(n) > > > > > I gan explain in detail , please correct me if im wrong > > > > > Logic :- Basically in the subproblem , we would have founded the > > > > maximum subarray in that well , subarray (short of words ) .So , if we > > > > want to ,we can only increase the solution in the next subarray (the > > > > second subproblem ) > > > > So , there will be three cases > > > > > Either the subarray , the most minimum sum in one of the subproblems > > > > will be the answer > > > > The answer will be from between the gap of the indices between the > > > > solutions of the two subproblems > > > > The answer will be any combination of the two > > > > > All these three can be checked in O(n) itself . > > > > > 2)Using DP(I don't know how many dp (pure dp i mean) algorithms are in > > > > O(nlog n) .Never heard of any with the pure dp approach and an n log n > > > > solution ) > > > > > DP(classical for maximum positive sum array ) can be done by going > > > > through two loops > > > > > dp[i]= minimum positive sum for an array with index (last index =i ) > > > > p[i]= start index corresponding to this dp[i] > > > > > dp[i]= minimum sum condition ( for each i > > > update p[i] accordingly .Then return the minimum amongst dp[i] and > > > > corresponding p[i] . > > > > > This is a complete search , so I don't think it will get wrong . > > > > > And i don't think it could be solved in O(n log n) (at least with > > > > dp) .Because the search space tree would be of height O(log n) (with > > > > no overlapping problems ) and dp lives upon overlapping subproblems . > > > > Or may be , if someone could provide with a O( n log n) solution > > > > > Regards , > > > > Sankalp Srivastava > > > > > "I live the way I type , fast and full of errors " > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Algorithm Geeks" group. > > > > To post to this group, send email to algogeeks@goo
[algogeeks] Re: Microsoft Written Test Questions
Hi Have u already wrote the test? If yes please share the questions. Thanks On Jan 27, 6:47 am, Ankit Babbar wrote: > Hey all...Can anyone provide me with the recent (/most common) written test > questions(or links ) of Microsoft IDC and Microsoft IT SDE positions...?? > > Thanks in advance.. > > Regards, > Ankit. -- 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 at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Microsoft Written test questions required
Hi Guys, I want to know about questions asked in written test for Microsoft. I come to know that it will be for 1.5 hours and it will consists of questions from c,C++ and data structure. I am writing the test this weekend only. So please send me questions ASAP. -- 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 at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Generating a Sequence Subject To Constraints
there are two components to your algorithm. the first component is (as gene pointed out) is to generate a random number. the second component is to verify the violations for the generated integers. the violation verfication is a function of two things: the previous sequence of numbers and the set of input rules you choose.
[algogeeks] Re: Given an array containing both positive and negative integers, we r required to find the sub-array with the largest sum
Think of the negative numbers as consumers from a warehouse and positive numbers as producers from the warehouse. The problem reduces to plotting the inventory (starting from time = 0 to time = n) and then finding the max amplitude over time axis in +ve quadrant of the inventory profile which can be done in O(n).
[algogeeks] Re: longest common subsequence problem
you can store the two strings in an upside down suffix tree. a simple edge scan of common path will give you all possible (and largest) common substring