3. Introduction
Data Structure:
a way to store and organize data in the structured
manner.
Computer's memory is divided into small parts, we
use different data structures to store data in those
small blocks.
Example: Arrays, Linked list, Trees ..........
4. Arrays
Array is basic data structure in which we store data
in continues memory locations.
Array is variable which holds mulitiple elements of
same type.
Arrays reduce the redendency
Generic form of arrays:
data type array_name[size];
Data type: what type of data(int, float, char...)
Size: number elements you want to store
5. Arrays
Every element will have index value
If you want to access any element we must use index
value of the element.
Disadavantages:
Capable of holding only one type of elements.
Insertion and deletion is very difficult
Waste of memory is very high
6. Linked list
Linked list: collection of nodes which or connected
together
Node: is just like variable but it holds data and
address of the next node or null.
Adavantages:
Memory efficincy is very high
Insertion and deletion is very easy and fast.
7. Linked list
When linked list is useful:
Do not know the number of data elements
Your list need to be sorted quickly
Disadvantages:
Traversal is very slow
If you want to access 10th element in the list you
need to cross 9 elements (arrays are very fast
because of index)
You can move only in one direction in single
linked list
If one link is corrupted remain data will be lost.
9. Double Linked list
In single linked we can move only in one direction
Double linked list allow us to move in direction.
Double linked is also collection of nodes, but here
node is contains more than 2 fields.
Node: one field holds data, second field holds
address of next node or null and third field holds
address of previous node or null.
10. Double linked list
Disadvantages:
Need extra space for holding references.
Still it is very slow to travel across the list.
Circular linked list:
If the head of linked list is connected to tail that list
is called circular linked list.
Application of linked list:
Stacks and Queues.
12. Stack
Stack
New nodes can be added and removed only at the
top
Similar to a pile of dishes
Last-in, first-out (LIFO)
Bottom of stack indicated by
a link member to NULL
Constrained version
of a linked list
13. Operations on Stack
push
Adds a new node to the top of the stack
pop
Removes a node from the top
Stores the popped value
Returns true if pop was successful
14. Queue
Queue
Similar to a supermarket checkout line
First-in, first-out (FIFO)
Nodes are removed only from the head
Nodes are inserted only at the tail
15. Operations on Queue
Insert and remove operations
Enqueue (insert) and dequeue (remove)
Disadvantages:
What happens if you're 10th in line at the supermarket and it takes 5 minutes to
process each person ahead of you?
You wait 45 minutes.