Its not a tough question.Basic arithmetics/algebra question.
ACB
Suppose speed of train from A =x
Suppose speed of train from B =y
They meet at C
1st train take a sec to reach C from B
CB=ax
2nd train take b sec to reach C from A
CA=bx
Time taken for
Use stack to push '( initially. if ')' is found remove its pair
'('.finally if the stack is empty then the expression is correct!
On Jun 10, 9:45 pm, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote:
give an algo which reads an paranthesised infix expression and check
well-formdness of
@Divya
o/p
c prints b
1 - prints a
6, 2 --- printf returns no of characters printed.
6=5 (length of a) + 1 (for \n)
2=1 (length of b) + 1 (for \n)
Hope it's
clarification to all
n=1
0,1 no of sequence =2
n=2
00,01,10 no of sequence =3
n=3
000,100,010,001,101 no of sequence =5
n=4
,1000,0100,0010,0001,1010,0101,1001 no of sequence
=8
n=5
printf returns number of successfully printed characters.
so printf(1\n) will return 6
and printf(c\n) will return 2
due to the extra '\n' character which is also being printed
I hope the output is now clear
Anurag Sharma
On Fri, Jun 11, 2010 at 12:26 AM, divya sweetdivya@gmail.com
Explanation:
The prototype for printf as per ANSI C is:
int printf( const char *format,…)
the return value is integer and returns the number of characters
successfully read by printf.
Also,in case of printf(),the evaluation of expressions passed on as
arguments is done from right to left
@sharad : In which order you will make the tree into doubly linklist ??
another algorithm:
1. keep root value as 0
2. when moving left decrement this value and assign to node
3. when moving right increment the value and assign to node
4. now sort the nodes on this number basis and if this number
The return value of printf is the number of characters it prints successfully.
So the rightmost printf is going to return 2 (one for char c and one
for new line), similarly second one returning 6.
Regards,
Chetan.
On 11 June 2010 00:56, divya sweetdivya@gmail.com wrote:
#include stdio.h
One solution that is very simple is: while doing division keep storing the
dividend. if any one dividend is repeated stop there and extract the part
between first occurrence digit before new occurrence.
Example:
7/9
7) 9 (1.*285714*28
7
--
20
14
---
Output will be
1,1
bcoz printf returns number of characters or integers printed
On Jun 11, 12:26 am, divya sweetdivya@gmail.com wrote:
#include stdio.h
main()
{
int a = 1;
char b='c';
int i,j;
printf(%d,%d,printf(%d\n,a),printf(%c\n,b));
wat shd b the o/p of this..plzz
BALARUKESH, In Rohit's algorithm there was one more condition that sum
should never be negative. I think you missed that point. The algorithm seems
to be fine at least for correct ordering of paranthesis. didn't check for
correctness of expression. :P
--
You received this message because you are
Please note that the fractional repeating part is recurring. and so that 4th
temporary variable assignment will be this way-
temp=x*1 - x= 233456.34563456... - 23.34563456 = 233433.0 ( mark
the fractional part is 0 now since the infinitely repeating 3456... will get
cancelled)
In this
Hi All,
For if max is 1 then we do not need to read the bits after 14th place.
1(dec) = 1001110001 (bin) that is 14 bits.
On Fri, Jun 11, 2010 at 12:08 AM, kirubakaran kirubakaran1...@gmail.comwrote:
When it is a stream of data,counting is a best way to go !
On Jun 10, 7:54
As you encounter the opening parentheses (,[,{ push them onto the stack.
When you encounter closing parentheses pop the top element if it is not a
matching parentheses then the expr is not valid. Finally after the input
string is scanned, the stack has to be empty else expr is invalid.
On Fri,
So can we say that a mutex is a binary semaphore.
On Thu, Jun 10, 2010 at 11:26 PM, souravsain souravs...@gmail.com wrote:
Originally semaphore is a concept given by Dijkstra who says it is
something that can have two operations P and V both atomic. In an OS
(for example Unix) we have kernal
If a doubly Linked List is made out of this, then there should be kept some
mechanism to keep the parent pointer in it and update it while creating and
then we can proceed in similar approach as my array solution above.
Anurag Sharma
On Thu, Jun 10, 2010 at 7:09 PM, sharad kumar
@Rohit
Consider : (a+)b
The above is not well formed! :)
On 11 June 2010 11:58, Rohit Saraf rohit.kumar.sa...@gmail.com wrote:
@BALARUKESH :
What are you saying !!
and Why would this not work
As you start you get sum -1 at start itself. Hence you quit.
The sum should be 0 always and 0 at
It will be c
1
6
2
6 and 2 because of newline
On Fri, Jun 11, 2010 at 9:26 AM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote:
c
1
6,2
u might be expecting 5,1 if u are forgetting the newline character :)
--
Rohit Saraf
Second Year
How to print very large Fibonacci numbers eg fib(1000).
My approach:
When any one of fib(i-1) or fib(i-2) has more than 12 or 13 digits,
partition them into groups of 4 digits and put them in a linked list.
fib(i-1) is put in list1, fib(i-2) in list2. Perform the addition of
these long numbers and
@Harish, it does.
@Divya, r we not on the same page.
On Thu, Jun 10, 2010 at 10:20 AM, Harish U harishs...@gmail.com wrote:
@Saurabh
I believe for Isomorphic trees only the structure counts not the value at
each nodes.
So i think there is no need to compare the value at the corresponding
@souravsain
means that process has slept and asked kernel to wake it only if its
resource which it need,it got so at that time can any process interrupt it
or not
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send
Given a large file, having N (N is very large) positive integers, how
will you find a pair of numbers that add up to x (eg. 100). What data
structure will you use and give appropriate Algo/code. It should be
efficient in time and space.
--
You received this message because you are subscribed to
it will work as the number after the decimal digit is recurring as in this
case 3456 is recurring that is the the number is not just 23.34563456, its
23.3456345634563456.. so after subtraction it will give zero as the
decimal part.
On Thu, Jun 10, 2010 at 8:55 AM, Veer Sharma
No need to enumerate all possible states.
In the final state (2,8,5), each jug is neither full nor empty, while
every valid operation has to fill or empty one jug.
So it is not possible to get this state from any other state by one
valid operation. (As others said, the state before the final
Explanation:
The prototype for printf as per ANSI C is:
*int printf( const char *format,…)*
the return value is integer and returns the number of characters
successfully read by printf.
Also,in case of printf(),the evaluation of expressions passed on as
arguments is done from right to
Give an algorithm to implement n stacks in an array... take care of the
empty space too i.e no overflow shld occur if there is eny empty space left
.
--
With Regards,
Jalaj Jaiswal
+919026283397
B.TECH IT
IIIT ALLAHABAD
--
You received this message because you are subscribed to the Google
@Rohit Saraf
i understood the question.
Superb solution by u.
On Thu, Jun 10, 2010 at 8:59 PM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote:
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
On 2010-6-11 13:39, BALARUKESH wrote:
The increment and decrement method wont work correctly for all
cases
Ex:-
))a+b((
It works. In this example, the first ')' lead to -1 which indicate the
expression is not well formed.
This is not a well formed parenthesis... But satisfies the
Given a circular linked list, what is the most efficient way of
constructing a new list which contains the common elements between the
2 given lists.
Is it sorting and then comparing ?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post
Hi,
I came across this statement that using circular lists, concatenation
can be done without traversing either list. The same case with freeing
the entire list.
Can someone elaborate on this ?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
@balarukesh thanks
On Fri, Jun 11, 2010 at 11:58 AM, Rohit Saraf
rohit.kumar.sa...@gmail.comwrote:
@BALARUKESH :
What are you saying !!
and Why would this not work
As you start you get sum -1 at start itself. Hence you quit.
The sum should be 0 always and 0 at last
excellent soln!!
--
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,
Given an array all of whose elements are positive numbers, find the
maximum sum of a subsequence with the constraint that no 2 numbers in
the sequence should be adjacent in the array.
Eg.
i) 3 2 7 10 should return 13 (sum of 3 and 10)
ii) 3 2 5 10 7 should return 15 (sum of 3, 5 and 7)
--
You
from inorder traversal i ll make doubly link list
then print it.is it correct approach
--
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
@jitendra ur approach is good but o(nlogn) where as o(n) is possible
--
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
Yeah got it !! I know, its simple. Dunno what I didn't get it when I posted
:-)
On Fri, Jun 11, 2010 at 9:26 AM, Anurag Sharma anuragvic...@gmail.comwrote:
well the solution is pretty straight forward.
let the distance between stations be 'd' and speed of trains starting at A
and B (lets call
Given three lists: A, B and C of length n each. Write a function which
returns true if any 3 three numbers (1 from each list), sum up to
zero. Else return false, if there is no such combination.
both o(n2)+o(n)space
and o(n2logn)+o(1)space
are trivial but can we optimise more
--
You received
Ya that will do..
Anurag Sharma
On Fri, Jun 11, 2010 at 7:08 PM, Raj N rajn...@gmail.com wrote:
Given a circular linked list, what is the most efficient way of
constructing a new list which contains the common elements between the
2 given lists.
Is it sorting and then comparing ?
--
@kirubakaran: How can it be 1,1 ? No of characters read in a is 5+ 1 for
'\n' so its 6 and for the next one 1+1=2
On Fri, Jun 11, 2010 at 9:09 AM, kirubakaran kirubakaran1...@gmail.comwrote:
Output will be
1,1
bcoz printf returns number of characters or integers printed
On Jun 11, 12:26
Is it without having the need to shift elements at all?
Anurag Sharma
On Fri, Jun 11, 2010 at 3:41 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote:
Give an algorithm to implement n stacks in an array... take care of the
empty space too i.e no overflow shld occur if there is eny empty space
@jalaj: This question has already been discussed for n=2,3
On Fri, Jun 11, 2010 at 4:11 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote:
Give an algorithm to implement n stacks in an array... take care of the
empty space too i.e no overflow shld occur if there is eny empty space left
.
Concatenation of two lists without traversing even one of the lists
completely requires a pointer to the last element of the first list (first,
as in the one that is to be attached in front of the other list). This is
only possible if either, there's a *last *pointer for the lists, or the list
is
@sharad: Does it have to return the first pair or all possible pairs ?
On Fri, Jun 11, 2010 at 6:56 PM, sharad sharad20073...@gmail.com wrote:
Given a large file, having N (N is very large) positive integers, how
will you find a pair of numbers that add up to x (eg. 100). What data
structure
A more theoretical answer to the question can be the following:
Let's try to construct a tree for all such possible sequences.
Level 0 = 0 or 1
Level 1 = 01 0
Level 2 =0 1 0 01
Level 3 = 0 1 0 0 1 0 10
Oh! Forgot to mention that the count of the leaves of the tree, gives the
number of possible sequences (as required to be determined by the question)
On Fri, Jun 11, 2010 at 10:02 PM, Mayur mayurhem...@gmail.com wrote:
A more theoretical answer to the question can be the following:
Let's try
@vivek:
read again:
) = -1
( = +1
Keep a sum of all these as u iterate.
That should never be negative
Plus check for these types (if you need correct arithmetic expressions as
well
*some operator followed by )*
* or / after a (
()
--
Fibonacci numbers can be calculated very efficiently
using matrix multiplications.
I hope you can think it/google it now.. that is better than me writing so
much again :)
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and
Break the link between the first and second items in each list. Link
the first item in the first list to the second item in the second
list, and link the first item in the second list to the first item in
the first list.
The traversal is from the first item of the first list, through the
second
I missed out the condition that it should never be negative... Sorry for the
comment... Thanks for correcting...
--
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
I hope using a backtracking solution suits the problem well...
maxsum( int arr[] , int n,int i,int sum, int last)
{
if(in)
{
int s1= 0,s2= 0,s3;
if(last ==i-1)
{
s1=maxsum(arr,n,i+2,sum,last);
}
else
{
s2= maxsum(arr,n,i+1,sum+arr[i],i);
I hope u can do better... try this..
use a hash table and try inserting all elements of 1st list and then
insert the elements of second list. if u find an element already
existing when u insert from second list then add it to a new list. the
new list has the common elements...
--
You received
int FindMaxSum(int array[],int i)
{
if(iSize) //Size is array size, considered as global variable in
my solution
return 0;
int Sum1 = FindMaxSum(array,i+2);//cannot chose i+1 as that will
make it adjacent
int Sum2 = FindMaxSum(array,i+3);//at any place I cannot chose i
+1, so I
@Anurag:
Check your approach for non balanced tree alsoeg take 8 nodes and try.
--
Regards
Jitendra Kushwaha
MNNIT, Allahabad
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
trivial solution will be exponential where we check for each selection
nC1+nC2...nCn = 2^n
we can optimise time by taking some memory.
It can be solved by subset sum where we will require extra memory of maximum
sum possible.
refer this link for subset sum problem:
@raj n
for 2 stacks its fine can you please tell for 3 stacks ...i'll generalize it
On Fri, Jun 11, 2010 at 9:32 PM, Anurag Sharma anuragvic...@gmail.comwrote:
Is it without having the need to shift elements at all?
Anurag Sharma
On Fri, Jun 11, 2010 at 3:41 PM, jalaj jaiswal
this can done by dyanamic programming
At every point keep the maximum sum including the current element and
excluding the current element
At last the maimum will be max of both the maximum
pseudo code :
max1 = max2 = 0
for i in 1 to n
temp = max2
max1 = MAX(max1, max2+array[i])
I think we can use a Linked List. Sort it and then find numbers adding upto
x.
On Fri, Jun 11, 2010 at 9:39 PM, Raj N rajn...@gmail.com wrote:
@sharad: Does it have to return the first pair or all possible pairs ?
On Fri, Jun 11, 2010 at 6:56 PM, sharad sharad20073...@gmail.com wrote:
all possible pairs
--
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
given an array A of n elements.
for indexes j , i such that ji
maximize( j - i )
such that A[j] - A [ i ] 0 .
Any Algorithm less than O(n^2) would do.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
this can be done easily using dynamic programming:
dp[i] = a[i] + max( dp[i+2], dp[i+3], dp[i+4] , ... )
for (i=n-1 ; i=0 ; i--)
{
max=0;
for (j=i+2 ; jn ;j++)
if (dp[j]max)
max=dp[j];
dp[i]=a[i]+max;
}
On 6/11/10, BALARUKESH sbalarukesh1...@gmail.com wrote:
I hope
See http://geeksforgeeks.org/?p=3133 for solution.
On Fri, Jun 11, 2010 at 8:41 AM, divya sweetdivya@gmail.com wrote:
Given an array all of whose elements are positive numbers, find the
maximum sum of a subsequence with the constraint that no 2 numbers in
the sequence should be adjacent
Agree with the above two.
I don't think you can free the entire list without traversing it.You
can free an element that you have a reference of.
How can you free an entire list with reference to just one element?
You'll need the other references. And if you
get the other references that means you
Array Increment Problem
Given an array A consisting of 'n' elements. Do the following both
operations in O(log n) time using a data structure.
Increment (A,i,j,x) : This should increment elements from A to A[j] by
value x .
Report(A,j) : This should report A[j]
Trivially in an array Increment
Good Evening to Algo_Geeks,
I am a newbie regarding the Algo Analysis. I was asked this question
recently in an interview. Please let me know if anyone of you know how to
solve this.
*Question:*
Assume You have a binary Tree (not sorted and not BST) with a specific
pattern on a Desktop1. How can
@Dave: What do you say about freeing the circular list without traversing
it.
On Fri, Jun 11, 2010 at 10:36 PM, Dave dave_and_da...@juno.com wrote:
Break the link between the first and second items in each list. Link
the first item in the first list to the second item in the second
list, and
@Anurag: Any other efficient way you can think of ?
On Fri, Jun 11, 2010 at 9:30 PM, Anurag Sharma anuragvic...@gmail.comwrote:
Ya that will do..
Anurag Sharma
On Fri, Jun 11, 2010 at 7:08 PM, Raj N rajn...@gmail.com wrote:
Given a circular linked list, what is the most efficient way
Ya thanks !!
On Fri, Jun 11, 2010 at 10:31 PM, Rohit Saraf
rohit.kumar.sa...@gmail.comwrote:
Fibonacci numbers can be calculated very efficiently
using matrix multiplications.
I hope you can think it/google it now.. that is better than me writing so
much again :)
@antony can u do an inverted dfs with bactracking?
On Wed, Jun 9, 2010 at 11:45 PM, Antony Vincent Pandian.S.
sant...@gmail.com wrote:
Thanks Sharad
On Wed, Jun 9, 2010 at 10:01 PM, sharad kumar sharad20073...@gmail.comwrote:
1
I guess it can be done in efficiently using a simple divide and conquer
scheme almost imitating mergesort.
Can you think of it now? :D
--
Rohit Saraf
Second Year Undergraduate,
Dept. of Computer Science and Engineering
IIT Bombay
69 matches
Mail list logo