Data may be single valued or may be multiple values, the data to be proceed must be organized in a particular structure. Which is structuring of data and hence the data structures are studied.
Now, what is a data structure? Exactly? Well as you know the data may be organized in many different forms such as linear form, tree form and stuff that we'll discuss later on.
Alternatively, The logical or mathematical model of a particular organization of data is known as a data structure.
There are mainly two types of data structure - Linear data structure and Non-linear data structure.
Linear data structure: In this type of data structure, the processing of data is done in linear way, which means the data can be proceed by the compiler in a sequential manner.
Linear data structures are : 1. Array
Arrays are most frequently used in programming. Mathematical problems like matrix, algebra and etc can be easily handled by arrays. An array is a collection of homogeneous data elements described by a single name. Each element of an array is referenced by a sub-scripted variable or value, called subscript or index enclosed in parenthesis. If an element of an array is referenced by single subscript, then the array is known as one dimensional array or linear array and if two subscripts are required to reference an element, the array is known as two dimensional array and so on. Analogously the arrays whose elements are referenced by two or more subscripts are called multi dimensional arrays.
Example of one dimensional array and multidimensional array:
2. Stack:
A stack is one of the most important and useful non-primitive linear data structure in computer science. It is an ordered collection of items into which new data items may be added/inserted and from which items may be deleted at only one end, called the top of the stack. As all the addition and deletion in a stack is done from the top of the stack, the last added element will be first removed from the stack. That is why the stack is also called Last-in-First-out (LIFO) .Note that the most frequently accessible element in the stack is the top most elements, whereas the least accessible element is the bottom of the stack. The operation of the stack can be illustrated as in figure below:
The insertion (or addition) operation is referred to as push, and the deletion (or remove) operation as pop. A stack is said to be empty or underflow, if the stack contains no elements. At this point the top of the stack is present at the bottom of the stack. And it is overflow when the stack becomes full, i.e., no other elements can be pushed onto the stack. At this point the top pointer is at the highest location of the stack.
3. Queues:
A queue is logically a first in first out (FIFO or first come first serve) linear data structure. The concept of queue can be understood by our real life problems. For example a customer come and join in a queue to take the train ticket at the end (rear) and the ticket is issued from the front end of queue. That is, the customer who arrived first will receive the ticket first. It means the customers are serviced in the order in which they arrive at the service centre. It is a homogeneous collection of elements in which new elements are added at one end called rear, and the existing elements are deleted from other end called front. The basic operations that can be performed on queue are 1. Insert (or add) an element to the queue (push)
2. Delete (or remove) an element from a queue (pop)
Non-linear data structure: The data structures in which insertion, deletion and processing of data can not be done in linear way are called non-linear data structures.
types of non-linear data structure:
1. Trees:
A tree is an ideal data structure for representing hierarchical data. A tree can be theoretically defined as a finite set of one or more data items (or nodes) such that : 1. There is a special node called the root of the tree. 2. Removing nodes (or data item) are partitioned into number of mutually exclusive (i.e., dis-joined) subsets each of which is itself a tree, are called sub tree.
2. Graphs: Graphs representations have found application in almost all subjects like geography, engineering and solving games and puzzles. A graph G consist of 1. Set of vertices V (called nodes), (V = {v1, v2, v3, v4......}) and 2. Set of edges E (i.e., E {e1, e2, e3......cm} A graph can be represents as G = (V, E), where V is a finite and non empty set at vertices and E is a set of pairs of vertices called edges. Each edge ‘e’ in E is identified with a unique pair (a, b) of nodes in V, denoted by e = [a, b].
No comments:
Post a Comment