Вы находитесь на странице: 1из 83

Types of data structure

1. Linear V/S Non Linear A data structure is said to be linear if its elements form a sequence like array or linked list And the data structure where there is no such sequence are called non linear like tree and graph 2. Homogeneous V/S Non-Homogeneous The data structure where we store similar type of data, is called homogeneous data structure otherwise it is called non homogeneous

Put some analogies

Insertion of an element at the start of array: Consider the Array 3 0 10 1 7 2 6 3 4 Element Values Index of Elements

Insert new element 15 at start of array(i.e. at index 0) Step 1: Shift all the values to next index to make space at index 0 for new element: Shift 6 from index 3 to index 4. 3 0 10 1 7 2 3 6 4 Element Values Index of Elements

Shift 7 from index 2 to index 3.


3 0 10 1 2 7 3 6 4 Element Values Index of Elements

Shift 10 from index 1 to index 2. 3 0 1 10 2 7 3 6 4 Element Values Index of Elements

Shift 3 from index 0 to index 1. 3 0 1 10 2 7 3 6 4 Element Values Index of Elements

Now there is space for new element at index 0. Step 2: Copy the new element at index 0. 15 0 3 1 10 2 7 3 6 4 Element Values Index of Elements

Deletion of an element from start of array:Consider the Array 15 3 10 7 6 Element Values 0 1 2 3 4 Index of Elements Delete element 15 from start of array(i.e. from index 0) Step 1: Move the deleted element(i.e. 15) from index 0 to any location like item. 15 Item

3 10 7 6 Element Values 0 1 2 3 4 Index of Elements Step2: Shift all the remaining values from current index location to immediate previous index location: Shift 3 from index 1 to index 0. 3 10 0 1 2 Shift 10 from index 2 to index 1. 3 10 0 1 2 Shift 7 from index 3 to index 2. 3 10 7 0 1 2 Shift 6 from index 4 to index 3. 7 3 6 4 Element Values Index of Elements

7 3

6 4

Element Values Index of Elements

6 4

Element Values Index of Elements

3 10 7 6 0 1 2 3 Now this is final state of array after deletion.

Element Values Index of Elements

Insertion of an element at starting of the list Step 1: Create a new node with the element value 13 in information part Step 2: Update the link value of new node with head value(address of node having element 13). Step 3: Update the head value with the address of new node. Now recently inserted node will be First Node for new list.

Insertion of an element at end of the list Step 1: Create a new node with the element value 35 in information part. Step 2: Update the link value of recently inserted node with the link value of previous last node(which is NULL in this case). Step 3: Update the link value of previous last node with the address of new node. Now recently inserted node will be Last Node for new list.

Insertion of an element in the middle of the list Step 1: Create a new node with the element value 35 in information part. Step 2: Update the link value of new node with the link value of node having element value 25(which is address of 55 in this case). Step 3: Update the link value of node having value 25 with the address of new node. No modification in first and last node positions.

Deletion of an element from start of the list Node to be deleted is having 13 value in this case. Step 1: Update head node value with the link value of the node, to be deleted(address of node having value 25 in this case). Step 2: Remove the element 13 from the list. Now node having value 25 will be first node of new list.

Deletion of an element from end of the list Node to be deleted is having 32 value in this case. Step 1: Update link value of the node having value 55 with link value of Last node(which is NULL in this case). Step 2: Remove the element 32 from the list. Now node having value 55 will be last node of new list.

Deletion of an element from middle of the list Delete the Node which is having value 32. Step 1: Update link value of the node having value 25 with link value of node to be deleted(which is address of node having value 32 in this case). Step 2: Remove the element 55 from the list. No modification in first and last node positions.

48

74

75

79

80

81

82

83

Вам также может понравиться