@tech.
OK.
The person asked to insert the node at 3rd position and given a pointer to
4th position.
If you go by the objective of question,
e.g 3-->4--->5>7.
I am starting as index 0(which is key value 3 in this case)
I have given a pointer to node having key value 7.I have to insert 6(n
@Rahul: u r rite dat swapping can b done wid only 1 pointer and a
variable. But evn doin insertion n swapping won't solve d problem bcoz new
element is to b inserted at 3rd position bt acc 2 ur method new element
wud come at 4th position. so, I think its not possible 2 do this in a single
l
@Akarsh.
for inserting only,we need a new node and it is not possible without having
new pointer(we have to ref. the new node with some pointer.) once insertion
complete, we left with one pointer which point to old node.
swapping can be done with 1 pointer only,if nodes are adjacent(in this
case).
@Rahul : I think the swapping method will work. But still have to use two
pointers.
On Thu, Oct 7, 2010 at 12:34 AM, sajj wrote:
> In a single linked list its is not at all possible i hope correct me
> if im wrong ... with given one pointer and with out knowing where head
> is.. even if u know t
In a single linked list its is not at all possible i hope correct me
if im wrong ... with given one pointer and with out knowing where head
is.. even if u know the position of the head it ll help you out for
arriving the solution if and only if it is pointing to any of the
following nodes 1 or 2 or
@Rahul:
we have to insert the element to the position previous to where the
given pointer is pointing... inserting nest to the element and
swapping wont work i think correct me if im wrong...
On Oct 6, 11:14 pm, RAHUL KUJUR wrote:
> @shobhan: Ya,I got it!!
--
You received this message becaus
May be this helps
http://ds-gyan.blogspot.com/2009/12/two-numbers-with-minimum-difference.html
On Sep 28, 10:28 am, "coolfrog$"
wrote:
> @ sorurav
> yes , the basic logic is required so that the code can be understood in
> single Run..
> i also request the same to all dear friends.
>
@ sorurav
yes , the basic logic is required so that the code can be understood in
single Run..
i also request the same to all dear friends.
Regards..
On Tue, Sep 28, 2010 at 8:11 PM, sourav wrote:
> Hi Friends
>
> This is an interesting problem and request you all to give a brief
> i
Hi Friends
This is an interesting problem and request you all to give a brief
intro to your code before putting the code. Or you may just mention
the under lying concept in the code. This will be of great help and
others will find it more ready to improve by adding there approach.
Coming back to
If their is no constrain on assumptions.
1.Sort the array.
2. check the dif between 2 elements.
{ 99,35,45,33,88,9098,112,33455,678,3}
sorted arrary : { } would be something.
now update the min_diff.
another example : { 7,8,1,3,5,4}
sorted arrary : { 1,3,4,5,7,8}
min diff is 1.
Please correct
step1>construct heap using siftdown. // time complexity wil be O(n) and
space complexity O(1).
step2>take mindifference=a[1].
step3>for i=1 ,i<=n/2 do
{ find the difference of (root,root-left),(root,root->right)and
(root->left,root->right).and maintain mindifference is the smallest
d
You are solving the wrong problem. The problem is not asking for the
difference between the two minimum elements, but for the minimum
difference between any pair of elements. In the case
int array[10]={99,35,45,33,88,9098,112,33455,678,3};
the minimum difference is |35-33| = 2.
Dave
On Sep
Printing the Array:
99 35 45 33 88 9098 112 33455 678 3
Min elements are 1: 3 2: 33
Absolute difference between two minimum elements are 30
On Fri, Sep 24, 2010 at 9:39 AM, Dave wrote:
> @Rishi: Try it on the original data with a[1] changed from 12 to 35:
>
>int array[10]={99,3
I got the problem statement wrong.
For a input of 7,8,5,1,3,4 the answer should be 1 due to the
difference between 3 and 4 or 7 and 8 or 4 and 5.
Rather than 2 due to difference between 1 and 3
Sorry every one :-(
--
You received this message because you are subscribed to the Google Groups
"A
check for this input {7,8,5,1,3,4}
On Sep 23, 10:36 pm, Rishi Agrawal wrote:
> @Dave, I check for the values you suggested but the code worked fine. There
> were other errors in the code. I have rectified them now.
>
> The following code seems to be working fine and in O(n) time.
>
> #include
>
@Rishi: Try it on the original data with a[1] changed from 12 to 35:
int array[10]={99,35,45,33,88,9098,112,33455,678,3};
What do you get as a result?
Dave
On Sep 23, 12:36 pm, Rishi Agrawal wrote:
> @Dave, I check for the values you suggested but the code worked fine. There
> were other e
@Dave, I check for the values you suggested but the code worked fine. There
were other errors in the code. I have rectified them now.
The following code seems to be working fine and in O(n) time.
#include
#include
void find_two_mins(int array[], int size)
{
int i,t;
int min1, min2;
Your comment brings to mind that we could do an O(n) sort such as a
Radix Sort. Any ordinary implementation will be O(n) as a fixed number
of passes will be required based on the word size.
Dave
On Sep 23, 11:21 am, nishaanth wrote:
> i dont think there exists a o(n) solution for this
> the best
i dont think there exists a o(n) solution for this
the best we can do is sort in o(nlogn) and then do a o(n) traversal
On Thu, Sep 23, 2010 at 8:48 PM, Dave wrote:
> @Yellow: Change the 12 in a[1] in your test case to 35 and see what
> you get.
>
> Dave
>
> On Sep 23, 10:09 am, Yellow Sapphire
@Yellow: Change the 12 in a[1] in your test case to 35 and see what
you get.
Dave
On Sep 23, 10:09 am, Yellow Sapphire wrote:
> I hope this will work. It finds the two minimum numbers and then prints the
> difference.
>
> #include
> #include
> void find_two_mins(int array[], int size)
> {
>
I hope this will work. It finds the two minimum numbers and then prints the
difference.
#include
#include
void find_two_mins(int array[], int size)
{
int i,t;
int min1=array[0], min2=array[1];
for (i=2; ihttp://groups.google.com/group/algogeeks?hl=en.
try for this {100,6,101,11}
On Sep 23, 7:40 pm, Nishant Agarwal
wrote:
> int minDiff(int arr[], int arr_size)
> {
> int min_diff = arr[1] - arr[0];
> int max_element = arr[0];
> int i;
> for(i = 1; i < arr_size; i++)
> {
> if(arr[i] - max_element < min_diff)
> min_diff = arr[i
Modeling Expert 's code is greedyit won't work for the test cases
in which the optimal answer is does not lie between first two
numbers..
On 9/23/10, Srinivas wrote:
> can anyone post this answer pls??
>
> --
> You received this message because you are subscribed to the Google Groups
> "
can anyone post this answer pls??
--
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
Guyswe need to find two numbers in a array with minimum difference ah
On Tue, Sep 21, 2010 at 8:52 PM, Rahul Singal wrote:
> try running it on [ 11 , 6 , 100, 101]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to
try running it on [ 11 , 6 , 100, 101]
--
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
Trying to put down a method, I think would work ( with a small running
example )
//! Assuming non--negative numbers and difference is MOD of difference
of numbers
Let array be A[1..n]//! e.g. { 11 , 6 , 17 , 9 ]
Start with pari ( A[1], A[2] ) and difference be D = | A[1] - A[2]
|/// A[1]
Yeah, you're right. It'll work only for consecutive elements.
And by swapping only consecutive elements, it'll take many swaps to
sort the array.
Another way would be to start from the left and every time you hit an
element larger than the previous one, call
reverse successively until all elements
@Minotauras:
There are some problems in you swap(x,y)
in your example : for reverse(3) you have considered 0 based indexing
and for reverse(2) 1 based index !!
see:
Original array : 1 8 3 4 5 and we want to swap(2,3) // swap 3 and 4.
Means, 0 BASED INDEX
reverse(3): 4 3 8 1 5
reverse(2): 8 3 4 1
write a function swap(x, y)
which does:
reverse(y)
reverse(1)
reverse(y)
so 1 8 3 4 5, swap (2, 3) // swap 3 and 4
reverse(3) gives: 4 3 8 1 5
reverse(2) : 3 4 8 1 5
reverse(3): 1 8 3 4 5 //thus we have swapped 3, 4 using the reverse(x)
function.
Use any sorting algorithm and you'll need 3k * n(l
its similar to performing a right rotatate within the specifie boundary the
number of times specified by argument
On Thu, Sep 16, 2010 at 11:49 PM, Aurelian Tutuianu wrote:
> A naive way to implement that is:
>
>int[] v = new int[100]; // this is my vector with values
>
>for (int
A naive way to implement that is:
int[] v = new int[100]; // this is my vector with values
for (int i = v.length - 1; i >= 0; i++) {
// get maximum value
int max = Integer.MIN_VALUE;
for (int j = 0; j < v.length; j++) {
if (max <
32 matches
Mail list logo