I think in this case, bubble sorting will be a better idea. just
replace the condition of comparison with the condition that earlier
number is even and later number is odd. I mean we can do sumthing lyk
this :
for i=1 to n-1
for j=1 to n-i-1
if iseven(ar[j]) AND (NOT
@amir
ur algo works only for positive elements array..
correct me if m wrong
On 23 June 2010 00:28, Amir hossein Shahriari
amir.hossein.shahri...@gmail.com wrote:
for each element find sum[i] which is the summation of all elements with
index less than or equal to i ( note that this array is
add all the elements in a trie tree and then search all the elements for
their best matching complement
--
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
Hi Jagadish,
Anurag's algo has O(n) for pre-processing. After that any sorting algorithm
will be applied there also.
On Wed, Jun 23, 2010 at 7:22 PM, Jagadish M jagadis...@gmail.com wrote:
Why not just change the definition of when one number is bigger than
another
and do normal sort ?
I
make a max-heap of size 1 million and insert the first 1 million numbers in it
for each new number from hard disk compare it to the maximum element
of the heap if it's bigger than max check next element else
extract-max from heap and insert the new element
the running time would be 1 trillion x
@Kumar: The next higher of 5 will be 7 as it comes first in the array.
On Wed, Jun 23, 2010 at 5:28 PM, Kumar Vishal kumar...@gmail.com wrote:
hi the number should be just next higher element or any higher element
like
if my arr is like
arr= 2 5 1 3 7 6
the next higher element for 5
let n be the number.
a) if n is zero, then it is of the form 2^k-1.
b) if n is negative then replace n with -n.
c) take m=n+1.
d) check if m(m-1)==0
then n is of the form 2^k-1, otherwise not.
On 6/23/10, divya sweetdivya@gmail.com wrote:
u are given any binary no.. u have to check its
Use median, it solves the problem I think.
Thanks,
Sathaiah
On Thu, Jun 24, 2010 at 12:21 AM, Dave dave_and_da...@juno.com wrote:
Let the given points be x_i, i = 1, 2, ..., n. For any point x on the
line, let
f(x) = sum_{i=1}^n | x - x_i |.
Then, from calculus, we know that f(x) attains
sorry my solution is wrong
i missed that the number should be divisible by a number of that type.
On 6/24/10, nisha goyal nisha.goyal1...@gmail.com wrote:
let n be the number.
a) if n is zero, then it is of the form 2^k-1.
b) if n is negative then replace n with -n.
c) take m=n+1.
d)
sort the array
for each element a[i]
find two elements that sum to -a[i] (this can be done in O(n) )
the overall time is O(n^2)
On 6/23/10, Raj N rajn...@gmail.com wrote:
Given a list of n integers?(negative and positive), not sorted and
duplicates allowed, you have to output the triplets
Keep a pointer list1 at the beginning of one of the lists, and call the
function below on the other list.
int reverseCheck(NODE *p)
{
list2=p;
if(list2-next==NULL)
return;
reverseCheck(list2-next);
if(list2-next-data==list1-data)
list1=list1-next;
else
flag=0;
return
Hi Raj,
What if the boxes are given in some different order. The solution given
depends very much on the order in which boxes are given.
On Wed, Jun 23, 2010 at 2:10 PM, Raj N rajn...@gmail.com wrote:
Given a lot of cuboid boxes with different length, breadth and height.
We need to find the
@ above can u plz specify how to sort a 1 Tb file with 64 bytes of Ram. I
got this heap methodbut ur approach seems interesting ..if u can
give some links dat wud be very appreciated..
On Thu, Jun 24, 2010 at 1:01 AM, Douglas Diniz dgdi...@gmail.com wrote:
If you have a memory that has
Hi,
Can anyone explain me the implementation of trie. I would be grateful
if one could provide me the link to a good learning resource.
Thanks!!
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
push the elements into stack , when the element to be pushed is greater than
the 'top' element.. pop the elements and write then
eg : if array is 1 2 3 4 5 8 6
insert 1
-
stack : 1
insert 2 ( as 2 top i.e 1)
-
output 1 - 2
stack : 2
insert 3 ( as 3 top i.e 2)
-
output 1-2, 2-3
@Dave
Can u plz explain the logic behind this..
Mohit
On Thu, Jun 24, 2010 at 12:44 AM, Dave dave_and_da...@juno.com wrote:
c = 1
repeat
d = n and c
n = n xor c
c = d left shifted by 1
until c = 0
Dave
On Jun 23, 11:05 am, vijay auvija...@gmail.com wrote:
Find the next
Think of a datastructure where you can search any alphabetic string in the X
steps (X = number of characters in string). So basically it can be a tree
with 27 childs per internal node. So according to binary search rule and
help of one simple link list, this tree can fetch you any string in X
Sorry, this point is already pointed out by Sharad.
Anurag Sharma
On Thu, Jun 24, 2010 at 4:42 PM, Anurag Sharma anuragvic...@gmail.comwrote:
@jalaj
Your approach will not work, what I perceived from your solution, as in
question the maximum difference S is defined as:-
S = a[i] - a[j]
Its a repeated question. Kindly search the archives for detailed discussion.
Anurag Sharma
On Wed, Jun 23, 2010 at 10:55 PM, Amir hossein Shahriari
amir.hossein.shahri...@gmail.com wrote:
sort the array
for each element a[i]
find two elements that sum to -a[i] (this can be done in O(n) )
@jalaj
Your approach will not work, what I perceived from your solution, as in
question the maximum difference S is defined as:-
S = a[i] - a[j] where* ij
*Perhaps you forgot that the 'order' of the max and min also matters :)
Anurag Sharma
On Mon, Jun 21, 2010 at 10:34 PM, jalaj jaiswal
call mobile from internet for free
http://voip-sofa.blogspot.com/
--
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
Hi, how about this -
Do a merge sort, now, while merging two sorted list, give more priority to
odd numbers :)
I believe this falls into the right solutions :)
Any breaking cases?
On 24 June 2010 09:41, Gaurav Singh gogi.no...@gmail.com wrote:
I think in this case, bubble sorting will be a
I think in-order traversal would solve the problem.
On Thu, Jun 24, 2010 at 4:24 PM, Anurag Sharma anuragvic...@gmail.comwrote:
I once posted it to my blog. Perhaps its the same you are asking :
http://anuragsharma-sun.blogspot.com/2010/03/converting-bst-to-circular-doubly.html
Anurag
23 matches
Mail list logo