Divide and Conquer Algorithm : Just like merge Sort of Quick sort...we
just need to modify the merge step of merge sort or Partition step of Quick
sort
lets call our this method Arrange();
//just as merge step takes two sorted arrays and make one completely sorted
one
it takes 2 arrays which
yes, occording to conditions he has to :)
On Fri, Jul 22, 2011 at 12:24 PM, Pankaj jatka.oppimi...@gmail.com wrote:
N people are standing in a circle ,they start shooting the person
standing *next to their neighbour.*If they start firing in this way ,
determine who will be alive after this
n+(n-1) +(n-2)++1 = O(n^2)
On Fri, Jul 22, 2011 at 3:16 PM, DeeJJ..! suryaprakash...@gmail.com wrote:
Q)complexity to find subwords in a given word?
ex: abcde
ans: a b c d e
ab bc cd de
abc bcd cde
abcd bcde
abcde
--
You received this message because
But that will save only 50% of the prisoners...as compare to 99.5% in
that of even Odd case
Read that post carefully
On Sat, Jul 23, 2011 at 1:04 AM, Gaurav Popli abeygau...@gmail.com wrote:
or we cud make more easy for prisoners...instead of counting whether
even or notthe person at
Cannot be done in O(N) if elements of list can take any value because then
counting sort wont help
On Sat, Jul 23, 2011 at 1:24 AM, Pankaj jatka.oppimi...@gmail.com wrote:
For linklist? How
On Sat, Jul 23, 2011 at 1:23 AM, Kamakshii Aggarwal kamakshi...@gmail.com
wrote:
use counting
Just take an extra array that will keep track of the values from which we
get the best in solution to that thread.
On Thu, Jul 21, 2011 at 8:55 AM, UMESH KUMAR kumar.umesh...@gmail.comwrote:
Hi
@Somnath my question is some different
if given array :3,2,7,10
So according to last discussion
no partitioning won't maintain stability
divide and Conquer will do in O(nlgn)
On Thu, Jul 21, 2011 at 11:38 PM, santosh mahto santoshbit2...@gmail.comwrote:
partitioning the element as in quicksort will work
On Thu, Jul 21, 2011 at 11:36 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote:
if a[i] is negative then what u can do is first find the min of the
array(say Min) and then
do map[a[i]-Min]++
On Wed, Jul 20, 2011 at 6:17 PM, anonymous procrastination
opamp1...@gmail.com wrote:
Hello,
Usually whenever we use index as key to count frequency or other
similar algos.
The
In first case first character input is 'a' and second is space so loop
breaks
in second loop runs till b is not read hence all characters including spaces
are found in output
On Wed, Jul 20, 2011 at 7:29 PM, mohit mohit89m...@gmail.com wrote:
guys just give input a stream of characters
http://groups.google.com/group/programming-puzzles/browse_thread/thread/4fecd0d904624a0d
this will clarify all doubts :)
On Wed, Jul 20, 2011 at 8:52 PM, SAMMM somnath.nit...@gmail.com wrote:
Yaa even if it is 8 bytes long . Compiler will treat the value 10 as 8
bytes only . It should be able
@SAMM
your algo does not work
first thing why are you xoring the xor of list with only 1-5
range of numbers is 0 - 2^32 ??
if you are xoring with min to max of array the you can try out following
case where your algorithm fails
{1,3,1,3,3}
this question is already been discussed i think
if i am not getting question wrong.
read only 3 rows
find min and max of these 3n numbers
as min and max will be only in one lines output the line without min and max
On Mon, Jul 18, 2011 at 9:55 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote:
Reading the input will cost n^2
--
You
solution below O(n^2)
On Mon, Jul 18, 2011 at 10:01 PM, sunny agrawal
sunny816.i...@gmail.comwrote:
if i am not getting question wrong.
read only 3 rows
find min and max of these 3n numbers
as min and max will be only in one lines output the line without min and
max
On Mon, Jul 18
oh common thats what have been discussed above :P
On Mon, Jul 18, 2011 at 10:52 PM, sagar pareek sagarpar...@gmail.comwrote:
oh common its a very tricky question
take 6 variables
min0,min1,min2 for 1st 3 rows and corresponding max0,max1,max2
compute all three by travering first three rows
size of pointers is equal to word size of the machine
so on 64 bit machine size of pointer will be 8 byte while that of int is 4
byte
On Mon, Jul 18, 2011 at 11:17 PM, Swathi chukka.swa...@gmail.com wrote:
Try check if (p == NULL)... may be memory is not allocated...
On Mon, Jul 18, 2011 at
Yes thats right but a small but obvious correction which holds good till you
explicitly call free function or...
On Mon, Jul 18, 2011 at 10:49 PM, Swathi chukka.swa...@gmail.com wrote:
In first 1, you are using malloc() so the memory will be allocated from
heap which holds good till end of
@Swathi
You are not counting Stack Space used
and as depth of recursion will be O(N) so SC is also O(N) for your solution
`
On Mon, Jul 18, 2011 at 10:22 PM, Swathi chukka.swa...@gmail.com wrote:
Using recursion we can do in O(1) space complexity and O(n) time
complexity..
int multiply(int
yes Alok u r right that in any case we will traverse k times if k is the
position if the element that need to searched
but by jumping we can save the time of avoiding unnecessary comparisions
On Tue, Jul 19, 2011 at 10:44 AM, Alok Prakash alok251...@gmail.com wrote:
If i am not wrong, in a
Because here we can not reOrder words, Greedy seems to work fine to me too,
i am not able to come up with an contradictory example..will post if
will get one... or post if any one can.
but here http://mitpress.mit.edu/algorithms/solutions/chap15-solutions.pdfis
the DP solution to the
@sagar
did you read the question before posting
On Fri, Jul 15, 2011 at 3:17 PM, sagar pareek sagarpar...@gmail.com wrote:
int a=(int)rand()%1001; //1-1000
int b=(int)rand()%2; // 0-1
On Fri, Jul 15, 2011 at 3:01 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote:
You are provided with a
, Jul 11, 2011 at 5:54 PM, Piyush Kapoor
pkjee2...@gmail.comwrote:
Can anybody give a full explanation
http://ideone.com/K1QmV
On Sat, Jul 9, 2011 at 10:49 PM, sunny agrawal
sunny816.i...@gmail.com wrote:
try to find out the binary representation of float value 5.2
On Sat, Jul 9, 2011
n+lgn-2 no of comparisions will do
On Thu, Jul 14, 2011 at 10:19 AM, shiv narayan narayan.shiv...@gmail.comwrote:
Describe an optimal algorithm to find the second minimum number in an
array of numbers. What is the exact number of comparisons required in
the worst case? Note that they didn't
Once a reference is initialized to an object, it cannot be changed to refer
to another object.
Ref. Bruce Eckel - ch11
So its Not possible
--
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee
--
You received this message because you are subscribed to the Google Groups
1. what if braces occur in comments
and also i think final answer should be 1 less than(dropping { for main())
the final count because there is no meaning of scope depth for a global
variable
On Tue, Jul 12, 2011 at 6:22 PM, nicks crazy.logic.k...@gmail.com wrote:
igonre the previous code,
PM, shilpa gupta shilpagupta...@gmail.comwrote:
i think there is no need of this part
else if(c== '}' )
{
depth-=1;
}
than there is no need to find out max also
depth will give max itself i think...
On Tue, Jul 12, 2011 at 6:32 PM, sunny agrawal sunny816.i
, 2011 at 6:43 PM, sunny agrawal sunny816.i...@gmail.comwrote:
@Nitish
as complete file will be scanned, program is taking care of functions
already
@shilpa
u r wrong !!
that part of code is very important
else what will be the answer for the following
i think Return statement will do the job :)
On Tue, Jul 12, 2011 at 6:58 PM, anonymous procrastination
opamp1...@gmail.com wrote:
Hello,
Suppose you have to search a particular node in a binary tree.
The code is quite simple. Pick up any traversal and see if any node
matches the value.
Algorithm in the paper says works only on sorted arrays
it is mentioned in the paper itself
On Tue, Jul 12, 2011 at 11:21 PM, Navneet Gupta navneetn...@gmail.comwrote:
I wrote the code as someone gave the reference of the paper where algo
to get max arithmetic subsequence was given.
For an
@Divye sir
yeah that will work fine if D is in reasonable limits ..
On Mon, Jul 11, 2011 at 4:26 PM, DK divyekap...@gmail.com wrote:
@Ritu: Your solution is incorrect.
Consider
1 3 41 43 47 49 90 100 110
Maximum repeated 'd' value:
'2' for the pairs (1,3), (41,43), (47,49) = 3
Smallest Number with k bits set will be the number with least significant k
bits set
ie. K=3 000111
K=4 000
and to find nth
we can use thishttp://groups.google.com/group/algogeeks/msg/2b64c4f96fa3598e
TC: O(n)
On Sun, Jul 10, 2011 at 2:13 PM, Sunny T sunny.1...@gmail.com wrote:
@Yogesh
your solution will give maximum Contiguous AP only
it will fail for the array A[] = {1,2,3,4,5,6,8,10,12,14}
your algo will give output that there is an Longest AP of 6 elements which
is wrong
checkout this http://theory.cs.uiuc.edu/%7Ejeffe/pubs/pdf/arith.pdf for an
O(n^2) algorithm
On
as answer and i guess its right... if am
wrong plz explain where and why my logic is wrong
On Sun, Jul 10, 2011 at 5:37 AM, sunny agrawal sunny816.i...@gmail.comwrote:
@Yogesh
your solution will give maximum Contiguous AP only
it will fail for the array A[] = {1,2,3,4,5,6,8,10,12,14}
your algo
Define Largest:
Total no of nodes in sub-tree
or
Height of sub-tree
On Sun, Jul 10, 2011 at 8:50 PM, Decipher ankurseth...@gmail.com wrote:
Write a code in C/C++ to find the largest BST sub-tree in a binary tree .
Eg:-
10
can be done using some modification in postorder traversal
call to left subtree will return that if left subtree is a BST of not
call to right subtree will return that if right subtree is a BST of not
if both subtrees are BST's check for curr and return its status
2 additional pass by ref.
@Divye Sir
I just came to know this is not a general Algorithm
This works only for sorted Array
this is Some description about the algo in paper
this algo uses the property of a AP that for every 3 consecutive elements of
an AP(a1,a2,a3)
a1+a3 = 2*a2
*L[i j] stores the maximum length of an
@DK sir
I was just assuming n^2 values as the 2D matrix..not creating
although i am using a O(n^2) space that keep track of which cell is already
in heap and need not be inserted againso initially all the need to
be initialized..that will make it O(n^2)
Now I have a Doubt - Is
A = 0 1 4 5 9 11 20
B = 0 2 3 6 8 13 15
(20, 15) (20, 15) - (20,15)
(20,13) (11,15) - (20,13)
(20,8) (11,15) - (20,8)
(20,6) (11,15) - assume (20,6)
(20,3) (11,15) - (11,15)
(20,3) (9,15)-
On Mon, Jul 11, 2011 at 1:06 AM, sunny agrawal sunny816.i...@gmail.comwrote
A = 0, 1, 4, 5, 9, 11, 20
B = 0, 2, 3, 6, 8, 13, 15
(20, 15) (20, 15) - (20,15)
(20,13) (11,15) - (20,13)
(20,8) (11,15) - (20,8)
(20,6) (11,15) - assume (20,6)
(20,3) (11,15) - (11,15)
(20,3) (9,15)- (9,15)
(20,3) (5,15)- (20,3) .problem (11,13) has higher
Reverse elements of set from start to end
Reverse elements of set from end+1 to destination
Reverse elements of set from start to destination
DONE
O(n)
On Sat, Jul 9, 2011 at 7:25 PM, Yogesh Yadav medu...@gmail.com wrote:
@gopi: i didnt really understand what u want to say... what start,end
try to find out the binary representation of float value 5.2
On Sat, Jul 9, 2011 at 10:46 PM, Sangeeta sangeeta15...@gmail.com wrote:
int main(){
int i;
float a=5.2;
char *ptr;
ptr=(char *)a;
for(i=0;i=3;i++)
printf(%d ,*ptr++);
}
output:
102 102 -90 64.explain?
--
You received
i have an O(nlgn) solution in mind using O(n^2) memory
All the values can be thought as the following matrix
(a0+b0) (a0+b1) (a0+b2).(a0+bn-1)
(a1+b0) (a1+b1) (a1+b2).(a1+bn-1)
.
yes it can also be the case
But faced the same Question in my MS interviews.there interviewer
mentioned that all elements are in first m places and last m places are
empty so i was thinking in that context :)
On Fri, Jul 8, 2011 at 1:31 PM, Rohan Kalra ronziiretu...@gmail.com wrote:
I
, Piyush Sinha ecstasy.piy...@gmail.comwrote:
Nopesits about finding subsequence
On 7/8/11, rajeev bharshetty rajeevr...@gmail.com wrote:
Should the sequence beContinuos ???
On Fri, Jul 8, 2011 at 1:18 AM, sunny agrawal
sunny816.i...@gmail.comwrote:
@rajiv
if Count = 2 means 3
@swathi
i think your algo won't work
try out for the following cases
1. 2,3,5,7,8,10
2. 2,3,5,6,9,11
On Thu, Jul 7, 2011 at 10:59 PM, oppilas . jatka.oppimi...@gmail.comwrote:
step:-
1) sort the array
2) remove the smallest and largest element from arary. keep the smallest
elemnt
@Sumit
lets consider the case the Egg does not break even from 100th floor
in your case u will get to know the answer in 8th trial.after 91 trying
from 100
but worst case solution is 16 for your solution.
we can do better by starting at 14 as above explained
@rajiv
Fails i think
think for 10 12 24 26
diff is 2 12 2
so do you want to say there is an AP pf 3 elements with d = 2, i can't see
any :P
your solution fails because there can be many APs in the array with the same
value of d and you will finish up by combining all those APs
On Fri,
of longest repeated element in diff i.e 2 so count =2 so
ap of 2 elem with diff 2 .
On Fri, Jul 8, 2011 at 1:03 AM, sunny agrawal sunny816.i...@gmail.comwrote:
@rajiv
Fails i think
think for 10 12 24 26
diff is 2 12 2
so do you want to say there is an AP pf 3 elements with d = 2, i can't
yes upto the step of swapping the elements it is O(m+n)
but if you need final arrays also sorted (Seems like that from your first
post)it will go nlgn
On Fri, Jul 8, 2011 at 1:25 AM, radha krishnan radhakrishnance...@gmail.com
wrote:
ok ! i got a O(n lgn) finally
i don know exact
i think DP has answer to this question
initialy compute the quality value of all the substrings of length 1,2,3
Ans[i][j] =
max(ans[i,j-2]+ans[j-1][j],ans[i,j-3]+ans[j-2][j],ans[i,i+1]+ans[i+2][j],ans[i,i+2]+ans[i+3][j])
something like that.
On Fri, Jul 8, 2011 at 1:31 AM, rajeev bharshetty
O(m) is always better than O(m^2) :) :P
Simple merge sort
hint : start from end of the arrays
select the text in white font to see the hint :)
On Fri, Jul 8, 2011 at 1:56 AM, Dumanshu duman...@gmail.com wrote:
given two sorted arrays a[m] b[2*m], each contains m elements only.
You
need to
http://ideone.com/xv73J
On Fri, Jul 8, 2011 at 2:16 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote:
@Sunny...can u post a definite algo for it??
On 7/8/11, Ravi Shukla shuklaravi...@gmail.com wrote:
@sunny , yep it looks DP. more of MCM.
solve for substrings of length 1,2,3.
and then
solution...:)
On 7/8/11, sunny agrawal sunny816.i...@gmail.com wrote:
http://ideone.com/xv73J
On Fri, Jul 8, 2011 at 2:16 AM, Piyush Sinha
ecstasy.piy...@gmail.comwrote:
@Sunny...can u post a definite algo for it??
On 7/8/11, Ravi Shukla shuklaravi...@gmail.com wrote:
@sunny
??
On Thu, Jul 7, 2011 at 10:11 PM, sunny agrawal sunny816.i...@gmail.com
wrote:
@ankit
it can be done without shifting elements
On Fri, Jul 8, 2011 at 9:52 AM, ankit sambyal ankitsamb...@gmail.com
wrote:
Algo :
Given array a[m] and b[2*m]
1. Shift the elements in the array b
@ Sathaiah Dontula
i think this won't work
Because product of m consecutive integers is divisible by m! but reverse is
not true ie.
if product of m integers is divisible by m! then they are consecutive ??
correct me if i am wrong!!
On Wed, Jul 6, 2011 at 12:55 PM, Sathaiah Dontula
For RNG in range [a,b] first thing is that all numbers should be generated
with equal probability.
in your case you are considering mid in both the ranges so you can modify it
like [a,mid],[mid+1,b]
still I think this will work fine as far as the ranges get divided equally..
like consider the
Oops ...
my method will also not work as probabilities will not be equal !!!
On Wed, Jul 6, 2011 at 11:29 PM, sunny agrawal sunny816.i...@gmail.comwrote:
For RNG in range [a,b] first thing is that all numbers should be generated
with equal probability.
in your case you are considering mid
yes Heap Build is O(n)
but after build it will be nlgn for comparision. isn't it ?
On Tue, Jul 5, 2011 at 10:07 PM, vaibhav agarwal vibhu.bitspil...@gmail.com
wrote:
@Dave bt the heap build operation is O(n) there is a proof fr this
On Tue, Jul 5, 2011 at 6:29 AM, saurabh singh
@Sagar
if it has a large no of data fields than don't u think just changing
pointers will be much better than swapping all the data contained in the
node
On Mon, Jul 4, 2011 at 11:13 AM, sagar pareek sagarpar...@gmail.com wrote:
@Anantha Krishnan
Well be specific
just read the question
I think Threaded Binary Tree solves your Problem
see this http://en.wikipedia.org/wiki/Threaded_binary_tree
On Mon, Jul 4, 2011 at 11:34 PM, Navneet Gupta navneetn...@gmail.comwrote:
Tree has an extra pointer next apart from left and right. Objective
is to set next pointer to point to node
@sandeep
if enqueue is pass by reference and dequeue as pass by value
then i think enqueue will be on headjust like stack so it will be O(1)
but for dequeue we need to traverse down the list and remove the last node
O(n)
and if enqueue is made to pass by value and dequeue as pass by
@sandeep
SET A - {0,3,4,7}
SET B - {1,2,5,6}
xor of all elements is zero
sum of both the sets is same
no of elements in both are same
overall result : all Algorithm posted above Fails
On Sun, Jul 3, 2011 at 12:59 PM, Sandeep Jain sandeep6...@gmail.com wrote:
I was thinking the same, BUT here
You should have posted the problem link
i think u are trying this one. http://www.codechef.com/problems/MULTQ3/
http://www.codechef.com/problems/MULTQ3/use RMQ or Binary Indexed Trees.
Brute Force won't work
On Sun, Jul 3, 2011 at 1:17 PM, rajeevrvis rajeev.open.1...@gmail.comwrote:
Hi Here
)
Regards,
Sandeep Jain
On Sun, Jul 3, 2011 at 1:09 PM, sunny agrawal sunny816.i...@gmail.comwrote:
@sandeep
SET A - {0,3,4,7}
SET B - {1,2,5,6}
xor of all elements is zero
sum of both the sets is same
no of elements in both are same
overall result : all Algorithm posted above
refer CLRS topic 9.1 Maximum and Minimum page no 184 :)
On Sun, Jul 3, 2011 at 2:32 PM, Nitish Garg nitishgarg1...@gmail.comwrote:
Which chapter of Sartaj Sahni are you referring to?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view
xor the length of the rope with the required length and difference between
the indexes of first set and last set bit *may* be the answer !!
On Sat, Jul 2, 2011 at 1:46 PM, cegprakash cegprak...@gmail.com wrote:
nope
On Jul 2, 1:14 pm, keyan karthi keyankarthi1...@gmail.com wrote:
yup :)
@varun
I think u want to write
while (k % m == 0)
On Sat, Jul 2, 2011 at 1:56 PM, varun pahwa varunpahwa2...@gmail.comwrote:
k - rope of desired length.
l - rope of given length
m = 2;
while(k % m)
m *= 2;
ans :: (log2(l) - log2(m) + 1).
ex.
k = 6,l = 8
so initially m = 2;
after 1st
yes i have written that only
difference between indexes of first set bit and last set bit
On Sat, Jul 2, 2011 at 2:08 PM, cegprakash cegprak...@gmail.com wrote:
whats mean by first set bit and last set bit? do you simply mean the
index of first and last bit?
On Jul 2, 1:25 pm, sunny agrawal
l = 81 0 0 0
k = 6 0 1 1 0
xor 1 1 1 0
difference = 2
l = 161 0 0 0 0
k = 4 0 0 1 0 0
xor
On Sat, Jul 2, 2011 at 2:09 PM, sunny agrawal sunny816.i...@gmail.comwrote:
yes i have written that only
difference between indexes of first set bit
why ?
On Sat, Jul 2, 2011 at 2:20 PM, cegprakash cegprak...@gmail.com wrote:
@ sunny: so your's doesn't work 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
for a number N
first set bit(From Left) is simply integer value of log(N)
last set bit can be calculated as
N = N-(N(N-1)); and then Log(N)
int i = log(n);
n -= n(n-1);
int j = log(n);
i-j will be the answer.
On Sat, Jul 2, 2011 at 2:34 PM, cegprakash cegprak...@gmail.com wrote:
oh fine..
try out with examples!!
u will surely get in 2-3 examples
N(N-1) is a very famous expression, used in counting set bits. see what
this expression return
On Sat, Jul 2, 2011 at 2:51 PM, cegprakash cegprak...@gmail.com wrote:
btw what N = N-(N(N-1)) does actually
On Jul 2, 2:11 pm, sunny
@cegprakash
Expression resets the least significant set bit
On Sat, Jul 2, 2011 at 3:20 PM, mohit goel mohitgoel291...@gmail.comwrote:
May be this can work.give any counter example...
int count;
main()
{
int l,rope,cuts;
scanf(%d%d,l,rope);
count =0;
in function it is pointer pointing to an array of 6 elements , pointer have
size equal to word size in the system which is 4bytes for 32 bit operating
system
in main it is array of 6 integers so 24 bytes
Don't get confused with same names, see the scope and type of arr in both
On Fri, Jul 1,
Take an array of size of the length of the string.
fill the array positions with one where string contains 1, and -1 where it
is 0
Now for each i (1,n-1) perform the following operation
a[i] = a[i-1] + a[i]
now a[i] will contains sum of values from a[0] to a[i] in original array.
Now only thing
is J-I = K for all queries?
On Fri, Jul 1, 2011 at 4:08 PM, oppilas . jatka.oppimi...@gmail.com wrote:
For finding maximum in a given range for an array , we need to construct a
seg tree of hight log(n).
So, for n queries out time complexity will be O(nlogn).
Now, if out query window size
:
here http://www.careercup.com/question?id=3576940.
On Fri, Jul 1, 2011 at 4:38 PM, sunny agrawal sunny816.i...@gmail.comwrote:
String = 1 0 1 1 0 1 1 1.
1. make the array = 1 -1 1 1 -1 1 1 1
2. after second operation
array = 1 0 1 2 1 2 3 4
index = 0 1 2 3 4 5 6 7
a[1] = 0 - [0,1
@gmail.com wrote:
Thanks.
Can you plz explain for input 1 0 1 1 0 1 1 1.
Also I want solution in O(n) TC and O(1) SC.
Regards
Anantha Krishnan
On Fri, Jul 1, 2011 at 4:13 PM, sunny agrawal sunny816.i...@gmail.com
wrote:
Take an array of size of the length of the string
or in other words equal no of 0's and 1's
On Sat, Jul 2, 2011 at 12:42 AM, Anika Jain anika.jai...@gmail.com wrote:
@sunny: in a[2,4] has 2 1s and one 0 then how is it a solution? i mean i
didnt get wen a[i]==a[j] then a[i,j] is a solution case..
On Fri, Jul 1, 2011 at 4:13 PM, sunny agrawal
@Muthuraj
DLL to BST back is not possible
In the first step while converting to DLLwe will create a sorted DLL
using inorder walk of the tree so DLL will represent the inorder sequence of
nodes of BST
and we know there can be many BST's for the given inorder
so we can not construct the same
it can be done without sorting(Finding any other traversal)
Do it recursively,
last element of the traversal will be head, and now if you will see in the
traversal left part of the traversal will be its LST and Right will be RST
(except Head) only thing you need to find will be the index of the
Problem Link ?
On Thu, Jun 30, 2011 at 6:48 PM, saurabh singh saurab...@gmail.com wrote:
Any idea how to solve this problem?
I am currently using graph and counting adjacent edges for the index.
1 2
\
\
3
eg for this graph structure 2 will have maximum possible friends.I am still
Because u copied the code i think :P
try writing printf statement yourself again :)
On Wed, Jun 29, 2011 at 5:05 PM, Anika Jain anika.jai...@gmail.com wrote:
int main()
{
int I =10, j=2;
int *ip = I ,*jp =j;
int k = *ip/ *jp;
printf(ā%uā,k);
return 0;
}
in this
the error is in quotes, just rewrite them
On Wed, Jun 29, 2011 at 5:24 PM, Anika Jain anika.jai...@gmail.com wrote:
hey, printf(%d ya %u in both same error cming..
On Wed, Jun 29, 2011 at 5:10 PM, sunny agrawal sunny816.i...@gmail.comwrote:
Because u copied the code i think :P
try
maintain two pointers one at the tail of even number list one at tail of odd
Number list
traverse the list and add the number at required list
On Wed, Jun 29, 2011 at 8:04 PM, Nishant Mittal
mittal.nishan...@gmail.comwrote:
segregate even and odd nodes in a singly linked list.Order of even and
At each node if we store the Number of nodes in the left subtree.we can
find kth smallest in O(lgn)
else do a inorder traversal for k nodes
On Wed, Jun 29, 2011 at 8:07 PM, Nishant Mittal
mittal.nishan...@gmail.comwrote:
how to find kth smallest element in BST...
--
You received this
solved
it using extra list...
On Jun 29, 7:38 pm, sunny agrawal sunny816.i...@gmail.com wrote:
maintain two pointers one at the tail of even number list one at tail of
odd
Number list
traverse the list and add the number at required list
On Wed, Jun 29, 2011 at 8:04 PM, Nishant Mittal
hey how r u dealing with absent cases.
for each case u r directly converting string to float
but for absent u will call atof() for ab and compare it.
On Wed, Jun 29, 2011 at 11:02 PM, kartik sachan kartik.sac...@gmail.comwrote:
any one plzz reply
--
You received this message
if N = 64 then we can convert all rows in an equivalent integer and then
sort all numbers and print distinct No.s
else
Worst case Solution would be to to check for each pair of rows and match -
O(N^3)
one more solution i can think of is to divide and conquer solution which
goes like this
based
@Ankit
if N is large how will you hash the rows, numbers will be very large
can you explain using given example ?
On Tue, Jun 28, 2011 at 11:38 AM, Ankit Agrawal
ankitmnnit.agra...@gmail.com wrote:
u can use hashing ...
hash fun can b base2 to base10
--
You received this message because
you can initialize it to (Max-Min+1)
where Max = max of all elements
Min = min of all elements
Or simple initialise it to a large integer like 0x7fff for 32 bit
numbers.
On Tue, Jun 28, 2011 at 3:32 PM, vikas mehta...@gmail.com wrote:
what will be the oldDiff initially. can u plz explain
2nd part of ankit's solution can be easily done in O(n)
after sorting of array
i = 0, j = n-1
while(i j)
if a[i]+a[j] == x , i and j are indexes of the elements
if a[i]+a[j] x decrement j
if a[i]+a[j] x increment i
On Tue, Jun 28, 2011 at 6:49 PM, Shachindra A C sachindr...@gmail.comwrote:
O(lglgn) :)
On Tue, Jun 28, 2011 at 10:52 PM, rajeev bharshetty rajeevr...@gmail.comwrote:
20% of those :)
On Tue, Jun 28, 2011 at 9:47 PM, piyush kapoor pkjee2...@gmail.comwrote:
The page is too long to read :P :P
On Tue, Jun 28, 2011 at 9:45 PM, Navneet Gupta
@Dave
i think your solution won't work
consider inorder traversal of a BST is 1 6 7 8 15 and x = 14
initially both u,v (1,1)
according to u your algorithm will proceed like
(1,1) - (1,6) - (1,7) - (1,8) - (1,15) - (6,15) - (15,15)
and clearly in second step of your solution if (u+v)
@saket - No
O(n) + O(n/2) + O(n/4)... = O(n)
sum of series
n+n/2+n/4+n/8 = 2n
On Mon, Jun 27, 2011 at 9:26 PM, Sanket vasa.san...@gmail.com wrote:
@Dave - Wouldn't your solution also become O(kn) where k = number of
bits in the number?
In this summation - O(n) +
@Bhavesh
NO there is No stupity
just a mistake in reading the question
mice die within 14 hrs.Not exactly 14 hours :)
3 is correct answer.
On Mon, Jun 27, 2011 at 10:51 PM, Bhavesh agrawal agr.bhav...@gmail.comwrote:
only ONE mouse ...consume each sample of bottles of bear with a
you can not change that
it will give error if you will try to change
if want to modify
you should declare it as
char a[] = pilani
On Sat, Jun 25, 2011 at 12:47 PM, oppilas . jatka.oppimi...@gmail.comwrote:
I was reading about how char *arr is different from char arr[].
Now, as in char
, this is independent of the word size.
Dave
On Jun 24, 11:44 pm, sunny agrawal sunny816.i...@gmail.com wrote:
@Dave it is given in Question that elements of array are integer
On Sat, Jun 25, 2011 at 7:17 AM, Dave dave_and_da...@juno.com wrote:
@Sunny: What makes you think that the integers are 32
No, Read about the return type of scanf
On Sun, Jun 26, 2011 at 4:56 AM, amit the cool amitthecoo...@gmail.comwrote:
main()
{
int i,t;
for ( t=4;scanf(%d,i)-t;printf(%d\n,i))
printf(%d--,t--);
}
inputs and corresponding outputs are:
0
4--0
1
3--1
2
2--2
3
but the loop
.
On Thu, Jun 23, 2011 at 6:51 PM, Sriganesh Krishnan 2448...@gmail.comwrote:
can you explain mewhat the logic is...behind the xor operation?...is
it like inversion or encryption?
On Thu, Jun 23, 2011 at 11:59 AM, sunny agrawal
sunny816.i...@gmail.comwrote:
initially compute xor
i am not sure about this
but when i solved this problem using simple scanf, printf and sort function
of algorithm library, my time was 0.08 so might be reading the values in
character buffer and then parsing then in ints may help
how did you implemented ?
did you implemented your own sort funtion
101 - 200 of 326 matches
Mail list logo