What is Data Structure?
A data structure is a particular way of organizing data in a computer so that it can be used effectively. The idea is to reduce the space and time complexities of different tasks. In other words, A data structure is a specialized format for organizing and storing data. General data structure types include the array, the file, the record, the table, the tree, and so on. Any data structure is designed to organize data to suit a specific purpose so that it can be accessed and worked with in appropriate ways.
Primitive Data Structures
Primitive Data Structures are the basic data structures that directly operate upon the machine instructions. They have different representations on different computers.
1. Integers:-
An integer (pronounced IN-tuh-jer) is a whole number (not a fractional number) that can be positive, negative, or zero. Examples of integers are: -5, 1, 5, 8, 97, and 3,043.
2. Floating point numbers:-
A real number (that is, a number that can contain a fractional part). The following are floating-point numbers: 3.0. -111.5. ½. 3E-5.
3. Character constants:-
A character constant is one or more characters enclosed in single quotes, such as 'A', '+', or '\n'.
OR
Text enclosed in single quotes as in 'a' is a character constant. The type of a character constant is int. Its value is the ASCII code for the character. Instead of a single character, an escape sequence can appear between the quotes.
4. String constants:-
The maximum length of a character constant can be one character. A string constant can be any length. A single character string constant has an equivalent integer value.
5. Pointers:-
A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address.
Non-primitive Data Structures
Non-primitive data structures are more complicated data structures and are derived from primitive data structures.They emphasize on grouping same or different data items with relationship between each data item.
* Linear Data Structure:
A data structure is said to be linear where all the elements form a sequence or a linear list. Linear Data Structure are:
* Non- Linear Data Structure:
A data structure is said to be Non- linear where all the elements are not form a sequence or a linear list. Linear Data Structure are:
** Tree
Tree is Non-linear data structure that simulates a hierarchical tree structure, with a root value and sub trees of children with a parent node, represented as a set of linked nodes.
** Graph
A graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed graph.
1. Arrays
Array used to store fix number of items and these items should be of the same type. Mostly, data structures use array to implement their algorithms/program. Following are the important terms to understand the concept of Array.
Element − Each item stored in an array is called an element.
Index − Each location of an element in an array has a numerical index, which is used to identify the element.
2. List
A List is a number of connected items or names written or printed consecutively, typically one below the other. Types of List:
A data structure is said to be linear where all the elements form a sequence or a linear list. Linear Data Structure are:
** Stack
Stack is linear data structure which works on LIFO (Last in First out). where insertion and deletion of items takes place at one end called top of the stack. Basically Stack performed three operations.
They are
1) inserting an item into a stack (Push).
2) deleting an item from the stack (Pop).
3) displaying the contents of the stack(Pip).
** Queue
Queue is linear data structure which works on FIFO (First in First out). where insertion of items takes place at one end called Rear and Deletion of items takes place another end called Front of the Queue.
** Linked List
A linked list is a linear data structure where each element is a separate object. Each element (we will call it a node) of a list is comprising of two items - the data and a reference to the next node.
A data structure is said to be Non- linear where all the elements are not form a sequence or a linear list. Linear Data Structure are:
** Tree
Tree is Non-linear data structure that simulates a hierarchical tree structure, with a root value and sub trees of children with a parent node, represented as a set of linked nodes.
** Graph
A graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed graph.
3. Files
A data structure is a specialized format for organizing and storing data. General data structure types include the array, the file, the record, the table, the tree, and so on. Any data structure is designed to organize data to suit a specific purpose so that it can be accessed and worked with in appropriate ways.