Hot Topics
Data Structure
Data structure is a specialized way for organizing and storing data so that user can perform different operations on it.
Types of Data Structure
Data Structure can be classified into two categories:
1)Primitive: It can only store single datatype
1.Character
It can store single character value.The char keyword is used to initialize it and size of char is 2 bytes.
Example: char letter=’b’;
2.Integer
It can store positive and negative numeric whole numbers.The int keyword is used to initialize it and size of int is 4 bytes.
Example: int a=2;
3.Float
Float is used to initialize decimal values with 7 digits precision.The float keyword is used to initialize it and size of float is 4 bytes.
Example: float a=3.1231;
Double is used to initialize decimal values with 15 digits precision.The double keyword is used to initialize it and size of double is 8 bytes.
Example: double b=3.9875627;
4.Boolean
It can store only True or False values.The bool keyword is used to initialize it and size of bool is 2 bytes.
Example: bool c=True;
2)Non-Primitive: It is a kind of data structure which can store values in contiguous or random memory location.
This can be further divided into:
1.Linear Data Structure: The data structure in which elements are connected to previous and next adjacent element linearly or sequentially. Some linear data structures are:-
1.Array
It is a linear data structure that can store elements of same datatype in contiguous memory allocation . To access elements which are inside array we can do so using index value which are positive numbers. Index value starts from 0 and goes till one less than the size of array.
2.Stack
It follows the principle called LIFO (Last In First Out) that means the element which is added first in the stack will be the last one to go out of the stack.Stack has some operations such as push() which allows us to push elements inside the stack,pop() allows us to remove elements from the stack and top() to give the top most value in the stack or the first value while seeing the stack from the top. Example: You keep books one upon another in a shelf. To get the book at the bottom you need to remove all the books on top of it.
3.Queue
It is similar to stack but the only difference is that it follows the principle called FIFO (First In First Out) which is the element which we entered into the queue at first will be removed first from queue. It also has some operations like push() required to push element in queue, pop() to remove elements from the front side of queue and front() which gives you the front most element present in queue. Example: Suppose you’re in a queue to buy tickets, the person who gave line first will get the ticket first and go out of of the queue first.
4.Linked List
It stores data in form of nodes which are divided into two parts, the first part contains data and second part contains a pointer variable used to store the address of next node. It can store any datatype such as string, character, integer, etc.
5.Hash Table
Often called as hash map used to store values with respect to their key values.
2.Non-Linear Data Structure: The data structure which has not arranged in sequential or linear manner. Efficiency of these kind of data structures are high as it uses less memory.
Types of non-linear data structures are:-
1.Trees
It contains various nodes attached to all other different nodes. Here we establish a relation between the parent and child nodes where the node to which other nodes is attached is called parent node and the nodes attached to parent node is called child node. We have AVL tree, Binary Tree ,etc.
2.Graph
This data structure consists two components vertices / nodes and edges . The nodes/vertices are connected with edges. Each node has a relation with other nodes.