What Is A Data Structure
What Is A Data Structure
CHAPTER 1
ROAD MAP
Data representation Abstract data type Need of data structure Data type Difference between ADT, DT and DS Classification of data structure
Data
Data is collection of numbers, alphabets & symbols combined to represent information. Atomic data: it is non-decomposable entity. Example: integer or char Composite data: it is a composition of day atomic data. month Example: date
year
DATA REPRESENTATION
Data is represented using different methods like hierarchical method.
let us discuss how the primitive or basic data types of any language are internally represented in memory.
Integer Representation
The positive data is represented using binary number system. 8 4 2 1 2^3 2^2 2^1 2^0 For negative binary numbers the methods of representation used are ones complement and twos complement.
The method used to represent real numbers in computers is floating-point notation. Real number is represented by a mantissa and exponent. For example, if the base is fixed as 10, 209.52 could be represented as 20952 x 10-2. The mantissa is 20952 and exponent is 2. Both the mantissa and exponents are twos complement binary integers. For example, 20952 can be represented as 1 0 1 0 0 0 111 0 1 1 in binary form.
Character Representation
It is used to store character as well as numeric information i.e. alpha-numeric data. 1 1 0 0 0 0 0 0 -> A and 1 1 0 0 0 0 0 1 -> B. Then, finally AB -> 11 0 0 0 0 0 0 11 0 0 0 0 0 1.
ROAD MAP
Data representation Abstract data type Need of data structure Data type Difference between ADT, DT and DS Classification of data structure
ADT
An ADT is defined as a mathematical model of the data objects that make up a data type as well as the functions that operate on these objects. ADT acts as a useful guideline to implement a data type correctly.
IMPLEMENTATION
The implementation of an ADT involves the translation of the ADTs specification into syntax of a particular programming language. The important step is the definition of ADT that involves mainly two parts: 1. Relationship of components with each other 2. List of operations that can be performed on that data type.
STACK ADT
abstract typedef <1, 2, 3 n, top> STACK; condition top == NULL abstract STACK PUSH (data) Preconditions: top != NULL Operation: insert(data) top->data /* as top points to most recently inserted element*/ abstract Pop ( ) Precondition: top!=null Operation: Remove (top) top >current data
ROAD MAP
Data representation Abstract data type Need of data structure Data type Difference between ADT, DT and DS Classification of data structure
In a general sense, any data representation is a data structure. Example: An integer More typically, a data structure is meant to be an organization for a collection of data items.
15
Organizing Data
Any organization for a collection of records can be searched, processed in any order, or modified. The choice of data structure and algorithm can make the difference between a program running in a few seconds or many days.
ROAD MAP
Data representation Abstract data type Need of data structure Data type Difference between ADT, DT and DS Classification of data structure
DATA TYPE
A method of interpreting a bit pattern is often called a data type. Data type can be defined as an abstract concept that defines an internal representation of data in the memory. A data type is an abstract concept defined by a set of logical properties.
Think of a universal data type - has two disadvantages: Large volume of memory will be occupied by even a small size of data. Different interpretations for different types of data would become very difficult. Data type - optimum use of memory
- defined way to interpret
Primitive data types are basic data type of any language that forms the basic unit for the data structure defined by the user. A primitive type defines how the data will be internally represented in, stored, and retrieved from the memory
EXAMPLES:
Date data type may be implemented using combination of different primitive data types. Following are primitive data typesInteger Character2^(n-1) + 1 to 2^(n+1) 1 09, AZ, az and other special
symbols Real/Float Numbers - mantissa and characteristic. m*n^r where m is the mantissa and n is the base (which is fixed 10) and r is the exponent
These are non-primitive data type which are derived from primitive data type. Examples: array structure union
ROAD MAP
Need of data structure Data representation Abstract data type Data type Difference between ADT, DT and DS Classification of data structure
An abstract data type is the specification of the data type which specifies the logical a mathematical model of the data type.
A data type is the implementation of an abstract data type. Data structure refers to the collection of computer variables that are connected in some specific manner.
Relationship:
ADT is specification of data type, DT is implementation of ADT DS is collection of variables of same or different data types. ADT DT DS
ROAD MAP
Need of data structure Data representation Abstract data type Data type Difference between ADT, DT and DS Classification of data structure
Primitive
Non-primitive
integer
char
float
pointer
Stacks
Queue
Array
Linked List
Trees
Graph
Non- primitive data structures are categorized into two classes: linear non-linear. In linear data structure, member elements form a sequence. Various types of linear data structure are stacks queue list Such linear structures can be represented in memory by using two basic strategies: arrays & linked list
Arrays are useful when the number of elements to he stored is fixed. Operations like traversal, searching and sorting can easily be performed on arrays. On the other hand, linked lists are useful when number of data items in the collection is likely to change. In non-linear data structure, a member element does not form sequence. There are various non-linear structures, such as trees graphs
Various operations can be performed on these data structures such as: Traversal: One of the most important operations which involves processing each element in the list. Searching: Searching or finding any element with a given value or the record with a given key. Insertion: Adding a new element to the list. Deletion: Removing an element from the list. Sorting: Arranging the elements in some order. Merging: Combining two lists into a single list.