1. ## Mathematics: Discrete-Mathematics (Algorithems)

I am new to Discrete math and i do not know how to solve this sum if some can please help me ..

Describe an algorithm that takes as input a list of n integer and produce as out put the largest difference obtained by subracting an integer in the list from the one following it.

2. Originally Posted by bhuvan
I am new to Discrete math and i do not know how to solve this sum if some can please help me ..

Describe an algorithm that takes as input a list of n integer and produce as out put the largest difference obtained by subracting an integer in the list from the one following it.
Code:
diffmin=diffrence between first and second input
Loop over inputs from second to the (n-1)st
diffwrk=current input minus next input
if diffwrk<diffmin
diffmin=diffwrk
endif
endLoop

return diffmin
CB

3. Thank you very much but how i can write algorithm in mathematical term..??

4. Originally Posted by CaptainBlack
Code:
diffmin=diffrence between first and second input
Loop over inputs from second to the (n-1)st
diffwrk=current input minus next input
if diffwrk<diffmin
diffmin-diffwrk
endif
endLoop

return diffmin
CB
Originally Posted by bhuvan
Thank you very much but how i can write algorithm in mathematical term..??
Well I would write it in a more formal pseudo-code:

Code:
1:   input x(1..n)

2:   diffmin:=x(2)-x(1)
3:   for idx=2 to n-1
3.1:    diffwrk:=x(idx+1)-x(idx)
3.2:    if diffwrk<diffmin
3.2.1:    diffmin:=diffwrk;

4:   return diffmin
CB