46267037 Data Structures PPT (1)
-
Upload
parveen-k-thakur -
Category
Documents
-
view
218 -
download
0
Transcript of 46267037 Data Structures PPT (1)
-
8/2/2019 46267037 Data Structures PPT (1)
1/17
Data Structures
-
8/2/2019 46267037 Data Structures PPT (1)
2/17
Agenda
Introduction
Arrays
Linked list Single linked list
Double linked list
Stack
Queue
-
8/2/2019 46267037 Data Structures PPT (1)
3/17
Introduction
Data Structure:
a way to store and organize data in the structuredmanner.
Computer's memory is divided into small parts, weuse different data structures to store data in thosesmall blocks.
Example: Arrays, Linked list, Trees ..........
-
8/2/2019 46267037 Data Structures PPT (1)
4/17
Arrays
Array is basic data structure in which we store datain continues memory locations.
Array is variable which holds mulitiple elements ofsame 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
-
8/2/2019 46267037 Data Structures PPT (1)
5/17
Arrays
Every element will have index value
If you want to access any element we must use indexvalue of the element.
Disadavantages:
Capable of holding only one type of elements.
Insertion and deletion is very difficult
Waste of memory is very high
-
8/2/2019 46267037 Data Structures PPT (1)
6/17
Linked list
Linked list: collection of nodes which or connectedtogether
Node: is just like variable but it holds data andaddress of the next node or null.
Adavantages:
Memory efficincy is very high
Insertion and deletion is very easy and fast.
-
8/2/2019 46267037 Data Structures PPT (1)
7/17
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 fastbecause of index)
You can move only in one direction in singlelinked list
If one link is corrupted remain data will be lost.
-
8/2/2019 46267037 Data Structures PPT (1)
8/17
Example program on linked list
-
8/2/2019 46267037 Data Structures PPT (1)
9/17
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 herenode is contains more than 2 fields.
Node: one field holds data, second field holdsaddress of next node or null and third field holds
address of previous node or null.
-
8/2/2019 46267037 Data Structures PPT (1)
10/17
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 listis called circular linked list.
Application of linked list: Stacks and Queues.
-
8/2/2019 46267037 Data Structures PPT (1)
11/17
Example program
-
8/2/2019 46267037 Data Structures PPT (1)
12/17
Stack
Stack
New nodes can be added and removed only at thetop
Similar to a pile of dishes
Last-in, first-out (LIFO)
Bottom of stack indicated by a link member toNULL
Constrained version of a linked list
-
8/2/2019 46267037 Data Structures PPT (1)
13/17
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 ifpop was successful
-
8/2/2019 46267037 Data Structures PPT (1)
14/17
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
-
8/2/2019 46267037 Data Structures PPT (1)
15/17
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 toprocess each person ahead of you?
You wait 45 minutes.
-
8/2/2019 46267037 Data Structures PPT (1)
16/17
References
http://ccodings.blogspot.com
http://afizafiz.blogspot.com/2010/10/linked-list-in-c-programming.html
-
8/2/2019 46267037 Data Structures PPT (1)
17/17