# Mathematics: Discrete-Mathematics (Algorithems)

• Nov 1st 2008, 06:02 PM
bhuvan
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.
• Nov 2nd 2008, 01:02 AM
CaptainBlack
Quote:

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
• Nov 2nd 2008, 05:40 AM
bhuvan
Thank you very much but how i can write algorithm in mathematical term..??
• Nov 2nd 2008, 06:27 AM
CaptainBlack
Quote:

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

Quote:

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