Data structures
Array
Linked List
Stack
Queue
Binary Tree
Binary Search Tree
Heap
Hashing
Graph
Matrix
Misc
Advanced Data Structure
Linked list ->
A linked list is a sequence of data structures, which are connected together via links.
Linked List is a sequence of links which contains items.
Each link contains a connection to another link.
Linked list is the second most-used data structure after array.
Stack DS ->
Stack is a linear data structure which follows a particular order in which
the operations are performed.
The order may be LIFO(Last In First Out) or FILO(First In Last Out).
ex:- Plates arranged after they are been washed.
Queue DS ->
A Queue is a linear structure which follows a particular order in which
the operations are performed.
The order is First In First Out (FIFO).
ex:- A good example of a queue is any queue of consumers for a resource
where the consumer that came first is served first.
The difference between stacks and queues is in removing.
In a stack we remove the item the most recently added;
in a queue, we remove the item the least recently added.
Binary Tree DS ->
A tree whose elements have at most 2 children is called a binary tree.
Since each element in a binary tree can have only 2 children,
we typically name them the left and right child
A Binary Tree node contains the following parts.
Data
Pointer to left child
Pointer to right child
Binary Search Tree->
node-based binary tree data structure which has the following properties:
The left subtree of a node contains only nodes with keys lesser than the node’s key.
The right subtree of a node contains only nodes with keys greater than the node’s key.
The left and right subtree each must also be a binary search tree.
Heap DS ->
A Heap is a special Tree-based data structure in which the tree is a complete binary tree.
Generally, Heaps can be of two types:
Max-Heap: In a Max-Heap the key present at the root node must be greatest
among the keys present at all of it’s children.
The same property must be recursively true for all sub-trees in that Binary Tree.
Min-Heap: In a Min-Heap the key present at the root node must be minimum
among the keys present at all of it’s children.
The same property must be recursively true for all sub-trees in that Binary Tree.
//Node Creation
// A simple C program to introduce
// a linked list
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
// Program to create a simple linked
// list with 3 nodes
int main()
{
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
// allocate 3 nodes in the heap
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
/* Three blocks have been allocated dynamically.
We have pointers to these three blocks as head,
second and third
head second third
| | |
| | |
+---+-----+ +----+----+ +----+----+
| # | # | | # | # | | # | # |
+---+-----+ +----+----+ +----+----+
# represents any random value.
Data is random because we haven’t assigned
anything yet */
head->data = 1; // assign data in first node
head->next = second; // Link first node with
// the second node
/* data has been assigned to the data part of the first
block (block pointed by the head). And next
pointer of first block points to second.
So they both are linked.
head second third
| | |
| | |
+---+---+ +----+----+ +-----+----+
| 1 | o----->| # | # | | # | # |
+---+---+ +----+----+ +-----+----+
*/
// assign data to second node
second->data = 2;
// Link second node with the third node
second->next = third;
/* data has been assigned to the data part of the second
block (block pointed by second). And next
pointer of the second block points to the third
block. So all three blocks are linked.
head second third
| | |
| | |
+---+---+ +---+---+ +----+----+
| 1 | o----->| 2 | o-----> | # | # |
+---+---+ +---+---+ +----+----+ */
third->data = 3; // assign data to third node
third->next = NULL;
/* data has been assigned to data part of third
block (block pointed by third). And next pointer
of the third block is made NULL to indicate
that the linked list is terminated here.
We have the linked list ready.
head
|
|
+---+---+ +---+---+ +----+------+
| 1 | o----->| 2 | o-----> | 3 | NULL |
+---+---+ +---+---+ +----+------+
Note that only head is sufficient to represent
the whole list. We can traverse the complete
list by following next pointers. */
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: