DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
III SEMESTER - R 2017
--- Content provided by FirstRanker.com ---
CS8381– DATA STRUCTURES LABORATORY
LABORATORY MANUAL
Name :
Register No :
Section :
--- Content provided by FirstRanker.com ---
VISION
is committed to provide highly disciplined, conscientious and enterprising professionals conforming to global standards through value based quality education and training.
MISSION
- To provide competent technical manpower capable of meeting requirements of the industry
- To contribute to the promotion of Academic excellence in pursuit of Technical Education at different levels
- To train the students to sell his brawn and brain to the highest bidder but to never put a price tag on heart and soul
--- Content provided by FirstRanker.com ---
PROGRAM EDUCATIONAL OBJECTIVES
- FUNDAMENTALS
To impart students with fundamental knowledge in Mathematics, Science and fundamentals of engineering that will mould them to be successful professionals
- CORE COMPETENCE
To provide students with sound knowledge in engineering and experimental skills to identify complex software problems in industry and to develop practical solutions for them
--- Content provided by FirstRanker.com ---
- BREADTH
To provide relevant training and experience to bridge the gap between theory and practice this enables them to find solutions for real time problems in industry and organization, and to design products requiring interdisciplinary skills
- PROFESSIONALISM SKILLS
To bestow students with adequate training and provide opportunities to work as team that will build up their communication skills, individual leadership and supportive qualities, and to enable them to adapt and work in ever changing technologies
- LIFELONG LEARNING
To develop the ability of students to establish themselves as professionals in Computer Science and Engineering and to create awareness about the need for lifelong learning and pursuing advanced degrees
--- Content provided by FirstRanker.com ---
PROGRAM OUTCOMES
- To apply the basic knowledge of Mathematics, Science and engineering fundamentals in Computer Science and Engineering field
- To design and conduct experiments as well as to analyze and interpret data and apply the same in the career
- To design and develop innovative and creative software applications
- To understand a complex real world problem and develop an efficient practical solution
- To create, select and apply appropriate techniques, resources, modern engineering and IT tools
- To understand their roles as a professionals and give the best to the society
- To develop a system that will meet expected needs within realistic constraints such as economical, environmental, social, political, ethical, safe and sustainable
- To communicate effectively and make others understand exactly what they are trying to convey in both verbal and written forms
- To work in a team as team member or a leader and make unique contributions and work with coordination
- To exhibit confidence in self-education and ability for lifelong learning
- To develop and manage projects in multidisciplinary environments
--- Content provided by FirstRanker.com ---
--- Content provided by FirstRanker.com ---
CS8381 - DATA STRUCTURES LABORATORY
--- Content provided by FirstRanker.com ---
SYLLABUS
COURSE OBJECTIVES
- To implement linear and non-linear data structures
- To understand the different operations of search trees
- To implement graph traversal algorithms
- To get familiarized to sorting and searching algorithms
--- Content provided by FirstRanker.com ---
LIST OF EXPERIMENTS:
- Array implementation of Stack and Queue ADTs
- Array implementation of List ADT
- Linked list implementation of Stack, Queue and List ADTs
- Applications of List, Stack and Queue ADTs
- Implementation of Binary Trees and operations of Binary Trees
- Implementation of Binary Search Trees
- Implementation of AVL Trees
- Implementation of Heaps using Priority Queues.
- Graph representation and Traversal algorithms
- Applications of Graphs
- Implementation of searching and sorting algorithms
- Hashing – any two collision techniques
--- Content provided by FirstRanker.com ---
--- Content provided by FirstRanker.com ---
TOTAL: 60 PERIODS
--- Content provided by FirstRanker.com ---
COURSE OUTCOMES
Upon completion of the course, students will be able to:
- Write functions to implement linear and non-linear data structure operations
- Suggest appropriate linear / non-linear data structure operations for solving a given problem
- Appropriately use the linear / non-linear data structure operations for a given problem
- Apply appropriate hash functions that result in a collision free scenario for data storage and retrieval
--- Content provided by FirstRanker.com ---
CS8381 – DATA STRUCTURES LABORATORY
CONTENTS
SI.No. | Name of the Experiment | Page No. |
---|---|---|
1.a) | Array implementation of Stack ADT | |
1.b) | Array implementation of Queue ADT | |
2. | Array implementation of List ADT | |
3. a) | Linked list implementation of Stack ADT | |
3. b) | Linked list implementation of Queue ADT | |
3. c) | Linked list implementation of List ADT | |
4. a) | Application of Stack ADT | |
4. b) | Application of Queue ADT | |
5. | a. Graph Representation b. Graph Traversal – DFS and BFS | |
6. | Implementation of Searching algorithms - Linear Search and Binary Search | |
7. | Implementation of Sorting algorithms - Bubble Sort, Shell Sort, Radix Sort | |
8. | Implementation of Heaps | |
9. | Implementation of Binary Trees and operations of Binary trees | |
10. | Implementation of Binary Search Tree | |
11 | Implementation of Hashing Technique |
Ex. No: 1a
--- Content provided by FirstRanker.com ---
Date:
IMPLEMENTATION OF STACK ADT
Aim:
To write a C program to implement Stack ADT by using arrays
Algorithm:
--- Content provided by FirstRanker.com ---
- Create a Stack[ ] with MAX size as your wish.
- Write function for all the basic operations of stack - PUSH(), POP() and DISPLAY().
- By using Switch case, select push() operation to insert element in the stack.
- Step 1: Check whether stack is FULL. (top == SIZE-1)
- Step 2: If it is FULL, then display "Stack is FULL!!! Insertion is not possible!!!" and terminate the function.
- Step 3: If it is NOT FULL, then increment top value by one (top++) and set stack[top] to value (stack[top] = value).
--- Content provided by FirstRanker.com ---
- Similarly, By using Switch case, select pop() operation to delete element from the stack.
- Step 1: Check whether stack is EMPTY. (top == -1)
- Step 2: If it is EMPTY, then display "Stack is EMPTY!!! Deletion is not possible!!!" and terminate the function.
- Step 3: If it is NOT EMPTY, then delete stack[top] and decrement top value by one (top--).
- Similarly, By using Switch case, select display() operation to display all element from the stack.
- Step 1: Check whether stack is EMPTY. (top == -1)
- Step 2: If it is EMPTY, then display "Stack is EMPTY!!!" and terminate the function.
- Step 3: If it is NOT EMPTY, then define a variable 'i' and initialize with top. Display stack[i] value and decrement i value by one (i--).
- Step 3: Repeat above step until i value becomes '0'.
- Close the program
--- Content provided by FirstRanker.com ---
--- Content provided by FirstRanker.com ---
Sample output:
Enter the size of STACK[MAX=100]:10
STACK OPERATIONS USING ARRAY
1.PUSH
--- Content provided by FirstRanker.com ---
2.POP
3.DISPLAY
4.EXIT
Enter the Choice:1
Enter a value to be pushed:12
--- Content provided by FirstRanker.com ---
Enter the Choice:1
Enter a value to be pushed:24
Enter the Choice:1
Enter a value to be pushed:98
Enter the Choice:3
--- Content provided by FirstRanker.com ---
The elements in STACK
98
24
12
Press Next Choice
--- Content provided by FirstRanker.com ---
Enter the Choice:2
The popped elements is 98
Enter the Choice:3
The elements in STACK
24
--- Content provided by FirstRanker.com ---
12
Press Next Choice
Enter the Choice:4
EXIT POINT
Result:
--- Content provided by FirstRanker.com ---
Thus the C program to implement Stack ADT by using array is executed successfully and the output is verified.
Program Outcome:
Thus the student can know to implement Linear Data Structure – Stack by using array
Applications:
- Expression evaluation
- Function call and return process.
--- Content provided by FirstRanker.com ---
Ex. No: 1b
Date:
IMPLEMENTATION OF QUEUE ADT
Aim:
--- Content provided by FirstRanker.com ---
To write a C program to implement Queue ADT by using arrays
Algorithm:
- Create a Queue[ ] with MAX size as your wish.
- Write function for all the basic operations of stack - Enqueue(), Dequeue() and Display().
- By using Switch case, select Enqueue() operation to insert element in to the rear/back end of the queue.
- Check whether queue is FULL. (rear == SIZE-1)
- If it is FULL, then display "Queue is FULL!!! Insertion is not possible!!!" and terminate the function.
- If it is NOT FULL, then increment rear value by one (rear++) and set queue[rear] = value
--- Content provided by FirstRanker.com ---
- Similarly, by using Switch case, select Dequeue() function is used to remove the element from the front end of the queue.
- Check whether queue is EMPTY. (front == rear)
- If it is EMPTY, then display "Queue is EMPTY!!! Deletion is not possible!!!" and terminate the function.
- Step 3: If it is NOT EMPTY, then increment the front value by one (front ++). Then display queue[front] as deleted element. Then check whether both front and rear are equal (front == rear), if it TRUE, then set both front and rear to '-1' (front = rear = -1).
--- Content provided by FirstRanker.com ---
- Similarly, by using Switch case, select display() operation to display all element of the queue.
- Step 1: Check whether queue is EMPTY. (front == rear)
- Step 2: If it is EMPTY, then display "Queue is EMPTY!!!" and terminate the function.
- Step 3: If it is NOT EMPTY, then define an integer variable 'i' and set 'i = front+1'.
- Step 3: Display 'queue[i]' value and increment 'i' value by one (i++). Repeat the same until 'i' value is equal to rear (i <= rear)
--- Content provided by FirstRanker.com ---
- Close the program
Output:
1.Insert element to queue
--- Content provided by FirstRanker.com ---
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice : 1
Inset the element in queue : 10
--- Content provided by FirstRanker.com ---
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice : 1
--- Content provided by FirstRanker.com ---
Inset the element in queue : 15
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
--- Content provided by FirstRanker.com ---
Enter your choice : 1
Inset the element in queue : 20
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
--- Content provided by FirstRanker.com ---
4.Quit
Enter your choice : 1
Inset the element in queue : 30
1.Insert element to queue
2.Delete element from queue
--- Content provided by FirstRanker.com ---
3.Display all elements of queue
4.Quit
Enter your choice : 2
Element deleted from queue is : 10
1.Insert element to queue
--- Content provided by FirstRanker.com ---
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice : 3
Queue is :
--- Content provided by FirstRanker.com ---
15 20 30
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
--- Content provided by FirstRanker.com ---
Enter your choice : 4
Result:
Thus the C program to implement Stack ADT by using array is executed successfully and the output is verified.
Program Outcome:
Thus the student can know to implement Linear Data Structure – Queue by using array
--- Content provided by FirstRanker.com ---
Applications:
- Queue is used by Operating systems for job scheduling.
- Queue is used in networking to handle congestion.
Viva Voce:
- What is linear and Non-linear data structure?
- What is array?
- Define ADT.
- What is Stack and list the operations of stack?
- What is Queue and list the operations of queue?
- How the insertion and deletion takes plays in stack?
- How the insertion and deletion takes plays in queue?
- What is push in stack?
- What is pop in stack?
- What is enqueue?
- What is dequeue?
--- Content provided by FirstRanker.com ---
--- Content provided by FirstRanker.com ---
--- Content provided by FirstRanker.com ---
EX NO: 2
IMPLEMENTATION OF LIST ADT
DATE
Aim:
To write a C program to implement List ADT by using arrays
--- Content provided by FirstRanker.com ---
Algorithm:
- Create an array[] with MAX size as your wish.
- Write function for all the basic operations of list - create(), insert(), deletion(), search(), display().
- By using Switch case, select create() operation to create the list.
- List Will be in the form: A1, A2, A3, .... An
- First Element of the List: A1
- Last Element of the List: An
- ith Element of the List: Ai,
- Position of Element A¡ : i, Position ranges from 0 to N
- Size of the List: N
- Empty List: If Size of the list is Zero (i.e N=0), it is Empty List.
- Precedes and Succeeds: For any list except empty list, we say that Ai+1 follows (or succeeds) Ai (i<N) and that Ai-1 precedes Ai (i>1)
--- Content provided by FirstRanker.com ---
--- Content provided by FirstRanker.com ---
- Similarly, by using Switch case, select insert() operation to insert element in the list.
- Insert x at position p in list L
- If p = END(L), insert x at the end
- If L does not have position p, result is undefined
--- Content provided by FirstRanker.com ---
- Similarly, by using Switch case, select delete() function is used to remove the element from the list.
- delete element at position p in L
- undefined if p = END(L) or does not exist
- Similarly, by using Switch case, select search() function is used to retrieve the required element from the list if it is available.
- returns element at position p on L
- undefined if p does not exist or p = END(L)
--- Content provided by FirstRanker.com ---
- Similarly, by using Switch case, select display() operation to display all element of the list
- print the elements of L in order of occurrence
- Close the program
--- Content provided by FirstRanker.com ---
Output:
Main Menu
1. Create
2. Delete
3. Search
--- Content provided by FirstRanker.com ---
4. Insert
5.Display
6.Exit
Enter your Choice: 3
Enter the number of nodes 3
--- Content provided by FirstRanker.com ---
Enter the element: 67
Enter the element: 69
Enter the element: 71
Do You Want to continue: y
Main Menu
--- Content provided by FirstRanker.com ---
1. Create
2. Delete
3. Search
4. Insert
5.Display
--- Content provided by FirstRanker.com ---
6.Exit
Enter your Choice: 4
Enter the position u need to insert: 2
Enter the element to insert: 56
The list after insertion:
--- Content provided by FirstRanker.com ---
The elements of the list ADT are:
67
69
56
71
--- Content provided by FirstRanker.com ---
Do You Want to continue: y
Main Menu
1.Create
2. Delete
3. Search
--- Content provided by FirstRanker.com ---
4. Insert
5.Display
6.Exit
Enter your Choice: 2
Enter the position u want to delete: 2
--- Content provided by FirstRanker.com ---
The elements after deletion: 67 69 71
Do You Want to continue: y
Main Menu
1.Create
2. Delete
--- Content provided by FirstRanker.com ---
3. Search
4. Insert
5.Display
6.Exit
Enter your Choice: 3
--- Content provided by FirstRanker.com ---
Enter the element to be searched: 69
Value is in 1 position
Do You Want to continue: y
Main Menu
1.Create
--- Content provided by FirstRanker.com ---
2. Delete
3. Search
4. Insert
5.Display
6.Exit
--- Content provided by FirstRanker.com ---
Enter your Choice: 5
The elements of the list ADT are:
67
69
71
--- Content provided by FirstRanker.com ---
Do You Want to continue: N
Result:
Thus the C program to implement List ADT by using array is executed successfully and the output is verified.
Program Outcome:
Thus the student can know to implement Linear Data Structure – List by using array
--- Content provided by FirstRanker.com ---
Applications:
- It is very much useful in sorting algorithms.
- Example: Selection sort
Viva Voce:
- What is array?
- Define ADT.
- What is List?
- Differentiate List and Array.
- What are the different operations involved in List?
- How the search operation works in list?
- How will you find the list is full?
- How will you find the list is empty?
- Is the list belongs to linear data structure? Justify
- Differentiate List and Linked list.
--- Content provided by FirstRanker.com ---
--- Content provided by FirstRanker.com ---
Ex. No.: 3a
--- Content provided by FirstRanker.com ---
LINKED LIST IMPLEMENTATION OF STACK ADT
Date:
Aim:
To write a C program to implement Stack ADT by using linked list
Algorithm:
--- Content provided by FirstRanker.com ---
- Include all the header files which are used in the program. And declare all the user defined functions.
- Define a 'Node' structure with two members data and next.
- Define a Node pointer 'top' and set it to NULL.
- Implement the main method by displaying Menu with list of operations and make suitable function calls in the main method.
- push(value) - Inserting an element into the Stack
- Create a newNode with given value.
- Check whether stack is Empty (top == NULL)
- If it is Empty, then set newNode ? next = NULL.
- If it is Not Empty, then set newNode ? next = top.
- Finally, set top = newNode.
--- Content provided by FirstRanker.com ---
- pop() - Deleting an Element from a Stack
- Check whether stack is Empty (top == NULL).
- If it is Empty, then display "Stack is Empty!!! Deletion is not possible!!!" and terminate the function
- If it is Not Empty, then define a Node pointer 'temp' and set it to 'top'.
- Then set 'top = top ? next'.
- Finally, delete 'temp' (free(temp)).
--- Content provided by FirstRanker.com ---
- display() - Displaying stack of elements
- Check whether stack is Empty (top == NULL).
- If it is Empty, then display 'Stack is Empty!!!' and terminate the function.
- If it is Not Empty, then define a Node pointer 'temp' and initialize with top.
- Display 'temp ? data --->' and move it to the next node. Repeat the same until temp reaches to the first node in the stack (temp ? next != NULL).
- Finally! Display 'temp ? data ---> NULL'.
--- Content provided by FirstRanker.com ---
--- Content provided by FirstRanker.com ---
Output
****** MENU ******
1. Push
--- Content provided by FirstRanker.com ---
2. Pop
3. Display
4. Exit
Enter your choice:1
Enter the value to be insert: 3
--- Content provided by FirstRanker.com ---
Insertion Success
****** MENU ******
1. Push
2. Pop
3. Display
--- Content provided by FirstRanker.com ---
4. Exit
Enter your choice:1
Enter the value to be insert: 5
Insertion Success
****** MENU ******
--- Content provided by FirstRanker.com ---
1. Push
2. Pop
3. Display
4. Exit
Enter your choice:2
--- Content provided by FirstRanker.com ---
Deleted Element: 5
****** MENU ******
1. Push
2. Pop
3. Display
--- Content provided by FirstRanker.com ---
4. Exit
Enter your choice:3
3->?NULL
****** MENU ******
1. Push
--- Content provided by FirstRanker.com ---
2. Pop
3. Display
4. Exit
Enter your choice:4
...Program finished with exit code 0
--- Content provided by FirstRanker.com ---
Result:
Thus the C program to implement Stack ADT by using linked list is executed successfully and the output is verified.
Program Outcome:
Thus the student can know to implement Linear Data Structure – Stack by using linked list
Applications:
--- Content provided by FirstRanker.com ---
- It is very much useful in memory management
Ex. No.: 3b
Date:
LINKED LIST IMPLEMENTATION OF QUEUE ADT
Aim:
--- Content provided by FirstRanker.com ---
To write a C program to implement Queue ADT by using linked list
Algorithm:
- Include all the header files which are used in the program. And declare all the user defined functions.
- Define a 'Node' structure with two members data and next.
- Define two Node pointers 'front' and 'rear' and set both to NULL.
- Implement the main method by displaying Menu of list of operations and make suitable function calls in the main method to perform user selected operation.
- enqueue(value) - Inserting an element into the queue
- Create a newNode with given value and set 'newNode ? next' to NULL.
- Check whether queue is Empty (rear == NULL)
- If it is Empty then, set front = newNode and rear = newNode.
- If it is Not Empty then, set rear ? next = newNode and rear = newNode.
--- Content provided by FirstRanker.com ---
- dequeue() - Deleting an Element from queue
- Check whether queue is Empty (front == NULL).
- If it is Empty, then display "Queue is Empty!!! Deletion is not possible!!!" and terminate from the function
- If it is Not Empty then, define a Node pointer 'temp' and set it to 'front'.
- Then set 'front = front ? next' and delete 'temp' (free(temp)).
--- Content provided by FirstRanker.com ---
- display() - Displaying queue of elements
- Check whether queue is Empty (front == NULL).
- If it is Empty then, display 'Queue is Empty!!!' and terminate the function.
- If it is Not Empty then, define a Node pointer 'temp' and initialize with front.
- Display 'temp ? data --->' and move it to the next node. Repeat the same until 'temp' reaches to 'rear' (temp ? next != NULL).
- Finally! Display 'temp ? data ---> NULL'.
--- Content provided by FirstRanker.com ---
--- Content provided by FirstRanker.com ---
Sample Output
:: Queue Implementation using Linked List ::
****** MENU ******
--- Content provided by FirstRanker.com ---
1. Insert
2. Delete
3. Display
4. Exit
Enter your choice: 1
--- Content provided by FirstRanker.com ---
Enter the value to be insert: 5
Insertion is Success!!!
****** MENU ******
1. Insert
2. Delete
--- Content provided by FirstRanker.com ---
3. Display
4. Exit
Enter your choice: 1
Enter the value to be insert: 7
Insertion is Success!!!
--- Content provided by FirstRanker.com ---
****** MENU ******
1. Insert
2. Delete
3. Display
4. Exit
--- Content provided by FirstRanker.com ---
Enter your choice: 2
Deleted element: 5
****** MENU ******
1. Insert
2. Delete
--- Content provided by FirstRanker.com ---
3. Display
4. Exit
Enter your choice: 3
7 >>> NULL
--- Content provided by FirstRanker.com ---
This download link is referred from the post: Anna University B.Tech Lab Manual