Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
VCE - UNIT-II.pptx
1. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
UNIT-2
Strings-ADT, Pattern Matching, Linked Lists: Singly Linked Lists and Chains, Linked Stacks and Queues, Polynomials,
Operations for Circularly linked lists, Equivalence Classes, Sparse matrices, Doubly Linked Lists
WHAT IS STRING?
❖ Collection of one or more characters enclosed inside the double quotes
❖ A single alphabet or digit or special symbol enclosed inside single quote is called a character
❖ Every string is terminated by a null character by default (‘0’ back slash-zero)
❖ Header file for string built-in functions is #include
❖ There is no built-in string data type in C
❖ But we can declare string as an array of characters
Syntax: char str-name[size];
Ex: char name[10];
2. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
Initialization:
char name[10]=”raghu”; or
char name[10]={‘r’,’a’,’g’,’h’,’u’,’0’}; or
char *name=”Raghu”;
char date [ ] =”13-04-2017”;
char *name=”NIKHIL”;
int i;
for(i=0;name[i]!=’0’;i++)
putchar(name[i]);
char *name=”NIKHIL”; I
nt i;
for(i=0;name[i]!=0;i++)
putchar(name[i]);
char *name=”NIKHIL”;
int i;
for(i=0;name[i]!=NULL;i++)
putchar(name[i]);
3. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
READING STRINGS:
FUNCTION NAME DESCRIPTION DESCRIPTION
scanf( ) Terminates reading string when encounter a space
gets( ) Terminates reading string when encounter a newline
PRINTING STRINGS:
FUNCTION NAME DESCRIPTION DESCRIPTION
printf( ) Displays character and strings
printf(“%c”, char-variable);
printf(“%s”, string-variable);
puts( ) Displays only strings
puts(string-variable);
4. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
WHAT IS PATTERN MATCHING?
❖It is the process of checking whether a specific sequence of characters/tokens/data exists among the given data
❖Regular programming languages make use of regular expressions for pattern matching
❖Pattern matching is used in identifying the matching pattern or substituting the matching pattern with another token
sequence
❖These algorithms are also known as string searching algorithms
APPLICATIONS
⮚ Searching in notepad
⮚ Searching in word
⮚ Searching in browser
⮚ Searching in database etc.
5. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
NAIVE ALGORITHM FOR PATTERN SEARCHING
Ex: Input: given_text[] = "IT IS C. C IS A PROGRAMMING LANGUAGE"
pat[] = "IS"
Output: Pattern found at index 3
Pattern found at index 11
❖ In this search, place the pattern at the beginning of the given text
❖ If all characters matches with given text then return the location
❖ If does not match move pattern one character right side of the given text
❖ Continue this process till reach the end of the given text
Example
Text : A A B A A C A A D A A B A A B A
Pattern : A A B A
A A B A A A B A
A A B A A C A A D A A B A A B A
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
A A B A
Pattern Found at 0, 9 and 12
6. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
NAIVE ALGORITHM STEPS
STEP-1 Place the search pattern at the beginning of the input string
STEP-2 Initialize i=first character of given text, j=first character of pattern
STEP-3 Compare both i and j, if match move both i and j to the next character
STEP-4 Now goto step-3 repeat for all pattern characters
STEP-5
If i and j does not match then move j to the beginning of the pattern, i to the second
character of given text. Now goto step-3 repeat till pattern match or i reached end
Example-1:
Given Text: IT IS C. C IS EASY
Search Pattern: IS
O(i) 1 2 3 4 5 6 7 8 9 10 11
I T I S C C I S E A S Y
I S
O(j) 1
7. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
I J Checking
0 0 Matches I==I so move i=1, j=1
1 1 Not matches T==S so move i=1, j=0
1 0 Not matches T==I so move i=2, j=0
2 0 Matches I==I so move i=3, j=1
3 1 Matches S==S so move i=4, j=0
4 0 Not matches C==I so move i=5, j=0
5 0 Not matches C==I so move i=6, j=0
6 0 Matches I==I so move i=7, j=1
7 1 Matches S==S so move i=8, j=0
KMP (Knuth-Morris-Pratt) PATTERN SEARCH ALGORITHM
❖In this construct Pi(π) table for given pattern
Pattern: a b c d a b c
Prefix: a, ab, abc, abcd
Suffix: c, bc, abc, dabc
8. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
Example-1:
Pi(π) table:
INDEX 1 2 3 4 5 6 7 8 9 10
PATTERN A B C D A B E F A B
VALUES 0 0 0 0 1 2 0 0 1 2
❖Here the string AB is repeated, so write its index for values
❖In KMP we never go back to the string like in Naïve search algorithm
1(i) 2 3 4 5 6 7 8 9 10 11 12 13 14 15A
A B A B C A B C A B A B A B D
INDEX 0(j) 1 2 3 4 5
PATTERN A B A B D
VALUES 0 0 1 2 0
9. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
KMP (Knuth-Morris-Pratt) ALGORITHM
STEP-1 Initialize i=first character of input, j=0
STEP-2
Compare both i and next character of j, if match move both i and j to the
next character
STEP-3 Now goto step-2 repeat for all pattern characters
STEP-4
If i and j does not match then move j to the PI table index of j Here we no
need to move i to the beginning
Step-5 Repeat from step-2 till find pattern or reach end of the input string
Example
1(i) 2 3 4 5 6 7 8 9 10 11 12 13 14 15
A B A B C A B C A B A A A B D
10. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
INDEX O(j) 1 2 3 4 5
PATTERN A B A B D
VALUES 0 0 1 2 0
I J Checking
1 0 Matches A==A so move i=2, j=1 (next char of j)
2 1 Matches B==B so move i=3, j=2
3 2 Matches A==A so move i=4, j=3
4 3 Matches B==B so move i=5, j=4
5 4 Not Matches C==D so move only j=2 (j is now at PI table value 2)
5 2 Not matches C==A so move only j=0 (j is now at PI table value 0)
5 0 Not matches C==A so move i=6 (j is already at 0)
6 0 Matches A==A so move i=7, j=1
a 1 Matches B==B so move i=8, j=2
⮚ Do not move i back to the beginning here like naïve pattern search algorithm
⮚ Its time complexity is O(M+N) where M is number of characters in PI table, N is number of characters in given
input text
11. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
DATA STRUCTURES
❖ Data structure is a process of storing and organizing the data in different ways
❖ Data structures can be used to solve many real time problems
❖ Each data structure is useful in different situations
TYPES OF DATA STRUCTURES
12. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
DIFFERENCES BETWEEN LINEAR AND NON-LINEAR DATA STRUCTURES:
PRE REQUISITE FOR DATA STRUCTURES:
To do operations on data structures, everyone should have good skills over the following concepts
❖ Pointers
❖ Structures
❖ Dynamic memory allocation
❖ Recursion
13. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
LINKED LIST
❖ It is a linear data structure with collection of similar elements
❖ Each element in a linked list is known as node
❖ In this it consist set of nodes
❖ Each node contains a relation with next node using node’s address
❖ Compared to arrays, linked list are used when number of elements are unknown
❖ Compared to arrays memory is efficiently used in linked list because of dynamic nature
❖ Types of linked list are
• Single linked list
• Double linked list
• Circular linked list
• Double circular linked list
APPLICATIONS OF LINKED LIST
❖ To implement other data structures like stack, queue, trees and graphs
❖ To perform arithmetic operations on long integers
❖ To perform arithmetic operations on polynomials
❖ To maintain directory of names
❖ To represent sparse matrices etc.
14. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
SINGLE LINKED LIST
❖ In this each node consist two fields. They are data field and address field. They areEach element in a linked list is
known as node
I) Data field: Consist value to be stored
II) Address field: Consist address of the next node
❖ In this we can traverse only in forward direction
❖ A head/start pointer consist address of the first node
❖ Initially head==NULL
❖ Every node address field consist address of its next node
❖ Last node address is NULL to indicate end of the list
❖ NULL is a pre-defined macro. It’s value is 0
❖ printf(“null value=%d”,NULL); //null value=0
16. SINGLE LINKED LIST DECLARATION
struct node
{
int data;
struct node *next;
};
struct node *newnode, *head=NULL;
newnode=(struct node*)malloc(sizeof(struct node));
17. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
OPERATIONS ON LINKED LIST:
❖ Inserting at the beginning of the list
❖ Inserting at the end of the list
❖ Inserting at the particular position of the list
❖ Deleting from the beginning
❖ Deleting from the end
❖ Deleting from the specified location
❖ Displaying list of values
❖ Counting number of nodes
❖ Printing list in reverse order
❖ Finding cycle in the list
❖ Finding merge point of the two lists etc.
19. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
20. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
21. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
INSERT AT END OF SINGLE LINKED LIST ALGORITHM:
22.
23.
24. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
DISPLAYING SINGLE LINKED LIST ALGORITHM:
STEP-1 Check whether list is EMPTY or not with condition (head==NULL)
STEP-2
If list is EMPTY, then display "List is empty, cannot display element”,
and terminate the function
STEP-3
If list is NOT EMPTY, then define a pointer called temp, and initialize it
with head i.e., temp=head
STEP-4 Display the node data with print(temp🡪data)
STEP-5
Now move temp to the next node using address
temp=temp🡪next, until it reaches end of list i.e., while(temp!=NULL)
25.
26. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
Deleting from Beginning of the list
We can use the following steps to delete a node from beginning of the single linked list...
• Step 1 - Check whether list is Empty (head == NULL)
• Step 2 - If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function
• Step 3 - If it is Not Empty then, define a Node pointer 'temp' and initialize with head.
• Step 4 - Check whether list is having only one node (temp → next == NULL)
• Step 5 - If it is TRUE then set head = NULL and delete temp (Setting Empty list conditions)
• Step 6 - If it is FALSE then set head = temp → next, and delete temp.
27. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
Deleting from END of the list
We can use the following steps to delete a node from end of the single linked list...
• Step 1 - Check whether list is Empty (head == NULL)
• Step 2 - If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function.
• Step 3 - If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and initialize 'temp1' with head.
• Step 4 - Check whether list has only one Node (temp1 → next == NULL)
• Step 5 - If it is TRUE. Then, set head = NULL and delete temp1. And terminate the function. (Setting Empty list
condition)
• Step 6 - If it is FALSE. Then, set 'temp2 = temp1 ' and move temp1 to its next node. Repeat the same until it reaches
to the last node in the list. (until temp1 → next == NULL)
• Step 7 - Finally, Set temp2 → next = NULL and delete temp1.
28. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
Delete a Particular Node
The steps below can be used to remove a specific node from the single linked list:
• Step 1 - Check to see if the list is empty (head == NULL).
• Step 2 - If the list is empty, display the message ‘List is Empty!!!’ Deletion is not possible’, and the function is
terminated.
• Step 3 - If it’s not empty, create two Node pointers, ‘temp1’ and ‘temp2,’ and set ‘temp1’ to head.
• Step 4 - Continue dragging the temp1 until it approaches the last node or the particular node to be deleted. And
before moving ‘temp1’ to the next node, always set ‘temp2 = temp1’.
• Step 5 - Once you’re at the last node, the message “Given node not found in the list! Deletion Not Pssible” appears.
Finally, the function is terminated.
• Step 6 - If you’ve reached the particular node which you want to delete, check to see if the list has only one node.
29. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
• Step 7: Set head = NULL and remove temp1 (free(temp1)) if list contains just one node and that is the node to be
deleted.
• Step 8: Check if temp1 is the first node in the list (temp1 == head) if the list has several nodes.
• Step 9: If temp1 is the initial node, remove temp1 and shift the head to the next node (head = head→next).
• Step 10: If temp1 isn’t the first node in the list (temp1→next == NULL), see if it’s the final one.
• Step 11: Set temp2→next = NULL and remove temp1 (free(temp1)) if temp1 is the final node.
• Step 12: Set temp2→next = temp1 →next and remove temp1 (free(temp1)) if temp1 is not the first or last node.
30. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
CIRCULAR LINKED LIST
❖ In CLL the last node does not consist NULL pointer
❖ Last node consist address of the first node
CLL ADVANTAGES
❖ Any node can be a starting point
❖ We don’t need to maintain two pointers for front and rear if we use circular linked list. We can maintain a pointer to
the last inserted node and front can always be obtained as next of last
❖ Circular lists are useful in applications to repeatedly go around the list.
31. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
CLL REPRESENTATION
❖In CLL take a pointer tail instead of head for easy access
struct Node
{
int data;
struct Node *next;
}
*tail=NULL, *temp;
32. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
INSERT AT BEGINNING OF CIRCULAR LL ALGORITHM
33. STEP-1
Create a newnode, store value add NULL address
newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data=value;
newNode->next=NULL;
STEP-2 Check whether list is EMPTY or not with condition (tail==NULL)
STEP-3
If list is EMPTY, then assign newnode address to tail and
tail->next
tail=newnode
tail->next=newnode
STEP-4
If list is NOT EMPTY, then in the newnode->next store tail- >next address and make
newnode as first node with tail
newNode->next=tail->next;
tail->next=newNode;
STEP-5 Display value is inserted in Circular LL
34. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
INSERT AT END OF CIRCULAR LL ALGORITHM
35. STEP-1
Create a newnode, store value add NULL address newNode = (struct
Node*)malloc(sizeof(struct Node));
newNode->data=value;
newNode->next=NULL;
STEP-2 Check whether list is EMPTY or not with condition (tail==NULL)
STEP-3
If list is EMPTY, then assign newnode address to tail and
tail->next
tail=newnode
tail->next=newnode
STEP-4
If list is NOT EMPTY, then in the newnode->next store tail- >next address and make
newnode as last node with tail
newNode->next=tail->next;
tail->next=newNode;
tail=newNode;
STEP-5 Display value is inserted in Circular LL
36. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
INSERT AT SPECIFIC LOCATION OF CIRCULAR LL ALGORITHM
These methods are used to put data into a circular linked list at a specified point.
1. Terminate the function if the circular linked list is empty.
1. If not, create two node pointers.
1. Create a new node to store the data. Now, navigate to the desired location and place this new
node there.
1. Connect the pointer of this new node to the node that was previously existing at this location.
1. To observe the outcome, print the new circular linked list.
37. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
DELETION OF THE FIRST NODE
The instructions below can be used to remove a node from the circular linked list’s beginning:
Step 1: Check for Overflow
if start = Null then
print list is empty
Exit
End if
Step 2: set ptr = start
Step 3: set start = start -> next
Step 4: print Element deleted is , ptr -> info
Step 5: set last -> next = start
Step 6: free ptr
Step 7: EXIT
38. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
DELETION OF THE LAST NODE
The instructions below can be used to remove a node from the circular linked list’s end:
Step 1: IF START = NULL
Write UNDERFLOW
Go to Step 8
[END OF IF]
Step 2: SET PTR = START
Step 3: Repeat Steps 4 and 5 while PTR NEXT != START
Step 4: SET PREPTR = PTR
Step 5: SET PTR = PTR NEXT [END OF LOOP]
Step 6: SET PREPTR NEXT = START
Step 7: FREE PTR
Step 8: EXIT
39. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
START is used to initialize the pointer variable PTR, i.e., PTR now points to the linked list’s first node. We
use another pointer variable PREPTR in the while loop so that PREPTR always refers to one node
before PTR. We set the next pointer of the second last node to START after we reach the last node and
the second last node, making it the (new) final node of the linked list.
40. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
Deletion from specific point
Deletion from the nth place in a circular linked list is one of the deletion operations that we commonly execute on
this type of list. We utilize pointers to traverse the circular linked list and conduct deletion from a specified position.
These instructions are used to delete a specified place in a circular linked list:
1. Initialize the p and q node pointers.
2. Create a variable called k that will serve as a counter variable.
3. Set the value of del to pos-1.
4. Repeat step 5 until k does not equal del.
5. Make q=p and p=p->next in this loop.
6. After each successful repetition, increase the value of k by one.
7. Make the next of q equal to the next of p.
8. Delete the node referred to by the node pointer p.
41. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
DOUBLE LINKED LIST
❖ In SLL it is possible to move only in the forward direction
❖ You cannot move back in SLL because every node consist only address of next node
❖ But in DLL we can move in the forward and backward directions
❖ In DLL every node consist 3 three fields. They are
I) Data field: stores value
II) Previous pointer field: stores address of previous node
III) Next pointer field: stores address of next node
❖ First node previous field consist NULL value
❖ Last node next field consist NULL value
42. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
INSERT AT BEGINNING OF DOUBLE LL ALGORITHM
43. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
STEP-1
Create a newnode, store value in data field and NULL in previous field of
newnode
newnode -> data = value;
newnode -> previous = NULL;
STEP-2
If head==NULL, make the newnode as first node with assigning NULL in next
field, and make head as newnode
newnode -> next = NULL;
head = newnode;
STEP-3
Else store head address in next field of newnode
And make it as first node
newnode -> next = head;
head->prev=newnode;
head = newnode;
STEP-4 Display node is inserted
45. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
STEP-1
Create a newnode, store value in data field and NULL in next field of newnode
newNode -> data = value;
newNode -> next = NULL;
STEP-2
If head==NULL, make the newnode as last node with assigning NULL in
previous field, and make head as newnode
newnode -> previous = NULL;
head = newNode;
STEP-3
Else create a temp node, and assign head address in it. Move temp node to
the last node. Then store temp address in previous and next fields
struct Node *temp = head;
while(temp -> next != NULL)
temp = temp -> next;
temp -> next = newNode;
newNode -> previous = temp;
STEP-4 Display node is inserted
46. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
Deletion
In a double linked list, the deletion operation can be performed in three ways as follows...
1. Deleting from Beginning of the list
2. Deleting from End of the list
3. Deleting a Specific Node
DELETING FROM BEGINNING OF THE LIST
47. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
We can use the following steps to delete a node from beginning of the double linked list...
• Step 1 - Check whether list is Empty (head == NULL)
• Step 2 - If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function.
• Step 3 - If it is not Empty then, define a Node pointer 'temp' and initialize with head.
• Step 4 - Check whether list is having only one node (temp → previous is equal to temp → next)
• Step 5 - If it is TRUE, then set head to NULL and delete temp (Setting Empty list conditions)
• Step 6 - If it is FALSE, then assign temp → next to head, NULL to head → previous and delete temp.
DELETING FROM END OF THE LIST
48. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
We can use the following steps to delete a node from end of the double linked list...
Step 1 - Check whether list is Empty (head == NULL)
Step 2 - If it is Empty, then display 'List is Empty!!! Deletion is not possible' and terminate the function.
Step 3 - If it is not Empty then, define a Node pointer 'temp' and initialize with head.
Step 4 - Check whether list has only one Node (temp → previous and temp → next both are NULL)
Step 5 - If it is TRUE, then assign NULL to head and delete temp. And terminate from the function. (Setting Empty list
condition)
Step 6 - If it is FALSE, then keep moving temp until it reaches to the last node in the list. (until temp → next is equal to NULL)
Step 7 - Assign NULL to temp → previous → next and delete temp.
49. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
DELETING A SPECIFIC NODE FROM THE LIST
We can use the following steps to delete a specific node from the double linked list...
• Step 1 - Check whether list is Empty (head == NULL)
• Step 2 - If it is Empty then, display 'List is Empty!!! Deletion is not possible' and terminate the function.
• Step 3 - If it is not Empty, then define a Node pointer 'temp' and initialize with head.
• Step 4 - Keep moving the temp until it reaches to the exact node to be deleted or to the last node.
50. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
• Step 5 - If it is reached to the last node, then display 'Given node not found in the list! Deletion not possible!!!' and
terminate the fuction.
• Step 6 - If it is reached to the exact node which we want to delete, then check whether list is having only one node or not
• Step 7 - If list has only one node and that is the node which is to be deleted then set head to NULL and delete temp
(free(temp)).
• Step 8 - If list contains multiple nodes, then check whether temp is the first node in the list (temp == head).
• Step 9 - If temp is the first node, then move the head to the next node (head = head → next), set head of previous to NULL
(head → previous = NULL) and delete temp.
• Step 10 - If temp is not the first node, then check whether it is the last node in the list (temp → next == NULL).
• Step 11 - If temp is the last node then set temp of previous of next to NULL (temp → previous → next = NULL) and delete
temp (free(temp)).
• Step 12 - If temp is not the first node and not the last node, then set temp of previous of next to temp of next (temp →
previous → next = temp → next), temp of next of previous to temp of previous (temp → next → previous = temp →
previous) and delete temp (free(temp)).
51. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
DISPLAYING A DOUBLE LINKED LIST
We can use the following steps to display the elements of a double linked list...
• Step 1 - Check whether list is Empty (head == NULL)
• Step 2 - If it is Empty, then display 'List is Empty!!!' and terminate the function.
• Step 3 - If it is not Empty, then define a Node pointer 'temp' and initialize with head.
• Step 4 - Display 'NULL <--- ‘.
• Step 5 - Keep displaying temp → data with an arrow (<===>) until temp reaches to the last node
• Step 6 - Finally, display temp → data with arrow pointing to NULL (temp → data ---> NULL).
52. CCC Digital India Pvt Ltd. 2nd Floor, Quantum Hub, Siripuram Jn, Visakapatnam-530003
EQUIVALENCE CLASSES
It is a finite collection of objects in this each object is related to itself and the relationship is symmetric; also, if two objects
are related to the same third object, the two objects themselves must also be related.
Equivalence Relation: It consist 3 properties
1) Reflexive: (a R a), for all a
1) Symmetric: (a R b) if and only if (b R a)
1) Transitive: (a R b) and (b R c) implies (a R c)
1) Equivalence Class: The set of elements that are all related to each other via an equivalence relation
❖ Equivalence classes in the test case design are used to reasonably reduce the number of test cases.