Pre-requisites CS2360 Java Programming /or Not known java? Spend the rest of 8-10 days to study java Read textbook p1-p53 Design a class with two integers C1 and C2 and a method fo to calculate the average value of c1 and c2 If you cannot do that, you should worry Stacks 6
Pre-requisites: • CS2360 Java Programming /or • Not known java? – Spend the rest of 8-10 days to study Java. – Read textbook p1-p53 – Design a class with two integers C1 and C2 and a method f() to calculate the average value of c1 and c2. – If you cannot do that, you should worry… Stacks 6
Data structures a systematic way of organizing and accessing data No single data structure works well for ALl purposes Data stored operation on data Algorithms an effective method expressed as a finite list of well-defined instructions for calculating a function Algorithms are used for calculation, data processing and automated reasonIng In simple words an algorithm is a step-by-step procedure for calculations Stacks
• Data Structures – A systematic way of organizing and accessing data. --No single data structure works well for ALL purposes. – Data stored – operation on data • Algorithms – an effective method expressed as a finite list of well-defined instructions for calculating a function. – Algorithms are used for calculation, data processing, and automated reasoning. – In simple words an algorithm is a step-by-step procedure for calculations. Stacks 7
How to describe algorithm? Nature languages Chinese, english, etc Not accurate · Pseudo-code Codes close to computer languages Omits details that are not essential for human understanding Intended for human reading rather than machine reading Programs C/C++ programs, Java programs Pseudo-code is preferred Allow a well-trained programmer to be able to implement Stacks
How to describe algorithm? • Nature languages – Chinese, English, etc. – Not accurate. • Pseudo-code – Codes close to computer languages • Omits details that are not essential for human understanding – Intended for human reading rather than machine reading • Programs – C /C++ programs, Java programs. • Pseudo-code is preferred – Allow a well-trained programmer to be able to implement. – Allow an expert to be able to analyze the running time. Stacks 8
An Example of an algorithm Algorithm sorting(X, n Algorithm sorting(x, n) Input array X of n integers Input array X of n integers Output array X sorted in a non- Output array X sorted in a non- decreasing order ecreasing order for it0 to n-do forj←-计+ton-ldo for i fromo to n- do fori from i+l to n-1 do if (Xixlilthen if X/i is largerthan Xil S- swap(X/i,xn i/, return X return X lafter i-th round, the i-th smallest after i-th round, the i-th smallest number is at i-th position number is at i-th position Stacks
An Example of an Algorithm Algorithm sorting(X, n) Input array X of n integers Output array X sorted in a nondecreasing order for i 0 to n − 1 do for j i+1 to n-1 do if (X[i]>X[j])then { s=X[i]; X[i]=X[j]; X[j]=s; } return X // after i-th round, the i-th smallest number is at i-th position. Stacks 9 Algorithm sorting(X, n) Input array X of n integers Output array X sorted in a nondecreasing order for i from 0 to n − 1 do for j from i+1 to n-1 do if X[i] is larger than X[j] swap(X[i], X[j]) return X // after i-th round, the i-th smallest number is at i-th position
Variables. Primitives a variable has its value a type is associated, E. g, int, boolean, float, long, etc A value is assigned to the variable The value is stored in the memory The size of the value is determined umbigously; 64 bit machine, int 8 bytes, double 8 bytes, etc Examples int y=50; char, ZA; Stacks
Variables, Primitives • A variable has its value – A type is associated, • E.g., int, boolean, float, long, etc. – A value is assigned to the variable • The value is stored in the memory • The size of the value is determined umbigously; 64 bit machine, int 8 bytes, double 8 bytes, etc – Examples • int x; • int y=50; • char c, z=‘A’; Stacks 10