Data Type, Abstract Data Type and Data Structure Algorithm

J.E.D.I medium – bits, bytes, words, etc – consists of serially arranged bits that are addressable as a unit. The processing units allow us to perform basic operations that include arithmetic, comparison and so on. Solution domain, on the other hand, links the problem and machine domains. It is at the solution domain where structuring of higher level data structures and synthesis of algorithms are of concern.

1.4 Data Type, Abstract Data Type and Data Structure

Data type refers to the to the kind of data that variables can assume, hold or take on in a programming language and for which operations are automatically provided. In Java, the primitive data types are: Keyword Description byte Byte-length integer short Short integer int Integer long Long integer float Single-precision floating point double Double-precision floating point char A single character boolean A boolean value true or false Abstract Data Type ADT, on the other hand, is a mathematical model with a collection of operations defined on the model. It specifies the type of data stored. It specifies what its operations do but not how it is done. In Java, ADT can be expressed with an interface, which contains just a list methods. For example, the following is an interface of the ADT stack, which we will cover in detail in Chapter 2: public interface Stack{ public int size; returns the size of the stack public boolean isEmpty; checks if empty public Object top throws StackException; public Object pop throws StackException; public void pushObject item throws StackException; } Data structure is the implementation of ADT in terms of the data types or other data structures. A data structure is modeled in Java by a class. Classes specify how operations are performed. In Java, to implement an ADT as a data structure, an interface is implemented by a class. Abstraction and representation help us understand the principles behind large software systems. Information-hiding can be used along with abstraction to partition a large system into smaller subsystems with simple interfaces that makes them easier to Data Structures 10 J.E.D.I understand and use.

1.5 Algorithm

Algorithm is a finite set of instructions which, if followed, will accomplish a task. It has five important properties: finiteness, definiteness, input, output and effectiveness. Finiteness means an algorithm must terminate after a finite number of steps. Definiteness is ensured if every step of an algorithm is precisely defined. For example, divide by a number x is not sufficient. The number x must be define precisely, say a positive integer. Input is the domain of the algorithm which could be zero or more quantities. Output is the set of one or more resulting quantities which is also called the range of the algorithm. Effectiveness is ensured if all the operations in the algorithm are sufficiently basic that they can, in principle, be done exactly and in finite time by a person using paper and pen. Consider the following example: public class Minimum { public static void mainString[] args { int a[] = { 23, 45, 71, 12, 87, 66, 20, 33, 15, 69 }; int min = a[0]; for int i = 1; i a.length; i++ { if a[i] min min = a[i]; } System.out.printlnThe minimum value is: + min; } } The Java code above returns the minimum value from an array of integers. There is no user input since the data from where to get the minimum is already in the program. That is, for the input and output properties. Each step in the program is precisely defined. Hence, it is definite. The declaration, the for loop and the statement to output will all take a finite time to execute. Thus, the finiteness property is satisfied. And when run, it returns the minimum among the values in the array so it is said to be effective. All the properties of an algorithm must be ensured in writing an algorithm.

1.6 Addressing Methods