Upcoming SlideShare
×

# Algorithmic Notations

10,709 views
10,311 views

Published on

For Students of Computer Science

2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
10,709
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
116
0
Likes
2
Embeds 0
No embeds

No notes for slide

### Algorithmic Notations

1. 1. Muhammad Muzammal E – Mail : hello_hi99@hotmail.com Gc University Faisalabad
2. 2. Intro uc n d tio • An algorithm, named after the ninth century Muslim scholar Abu Jafar Muhammad Ibn Musu Al- Khowarizmi, is defined as follows: • An algorithm is a finite step-by-step procedure to achieve a required result. • An algorithm is a sequence of computational steps that transform the input into the output. • An algorithm is a sequence of operations performed on data that have to be organized in data structures.
3. 3. Algorithmic Notations • variable:=expression • if condition then statements {elsif condition then statements} [else statements] • case switch of {sub case: statements} • while condition do statements • repeat statements until condition • for variable:=initial value [step step] to final value do statements • proc procedure name (parameters) [returns type] statements • procedure name (arguments) • return expression • read variable • write expression
4. 4. Algorithmic Notations 1. Programming notation 2. Specification notation
5. 5. Programming notation General purpose algorithmic notations Pascal, C, C++, Java • Declarations: int i, j = 3; double sum = 0; real x; int a[n] // array of n integers int b[1:n] # array of n integers5 double c[n,n] = ([n] ([n] 1.0))
6. 6. Programming notation (2) • Sequential statements (look: Java) for [quantifier1, quantifier2 , ….] { (list of statements) } quantifiers: i=0 to N i=1 to N by 2 i=0 to n-1 st i!=x #every value except x
7. 7. Programming notation (3) • Concurrent statements – co statement1; #N parallel processes // ... // statementN; oc – process foo { # a process in the ... (list of statements) # ... background } process bar [i=1 to n] # n processes
8. 8. Programming notation (4) • Functions and Procedures • int addone(int v) { # an integer fnct return (v+1); } • main () { # a “void" procedure int n, sum; read(n); for [i = 1 to n] sum = sum + addone(i); write (“the final value is”, sum); }
9. 9. Specification notation (1) • Specifying atomic transactions process_state_1 #state of computation <S1; … Sn;> #list of statements process_state_2 #state of computation the execution is atomic: the other processes see either state_1 or state_2 • Example: x = 0; y = 10; < x = x+1; y = y + 1; > For other processes: either x==0 & y==10 or x==1 & y==11
10. 10. Specification notation (2) • Specification of await < await (B) S; > – B delay condition – S sequence of statements • B is guaranteed to be true when execution of S begins • S is guaranteed to terminate • No internal state of S is visible to other processes • Example: <await ( s>0 ) s = s - 1; >