Data Structures and Algorithms
i | P a g e
Data Structures and Algorithms
Laboratory Manual
School of Engineering
Department of Computer Science and Engineering
G D Goenka University
Gurgaon, Haryana
Name:
Roll Number:
Section/Group:
Data Structures and Algorithms
ii | P a g e
The document is for internal circulation only.
Copyright © 2014 G D Goenka University. All rights reserved.
All materials on these pages are copyrighted by the G D Goenka University. All rights reserved. Reproduction, modification, retransmission, in any form or by any means, electronic, mechanical or otherwise, for reasons other than personal use, is strictly prohibited without prior written permission.
First Edition July, 2014
Published by:
SCHOOL OF ENGINEERING
Department of Computer Science and Engineering
G D Goenka University
Data Structures and Algorithms
iii | P a g e
PREFACE
The School of Engineering (SoE), GDGU has prepared this laboratory manual. It is designed as
an instruction book for purposes listed in order of importance as follows:
1.
To provide techniques, procedures and precautions related to the experiments.
2.
To provide the laboratory safety and general rules and instructions.
3.
To provide a general reference book that will give information which will assist in the
understanding of details about the laboratory and the experiment to be performed.
The manual is prepared with the idea that the revisions must be made periodically in order to
have the available text that represents the experiments. It has been tried to maintain the format
with diagrams, tables and illustrations.
It is believed that the information in the manual will enhance the practical skills of the students
along with developing the base of the subject.
Any suggestions and comments for further improvement of this manual will be gratefully
acknowledged.
Authors
G D Goenka University, Gurgaon
Data Structures and Algorithms
Data Structures and Algorithms
v | P a g e
General Rules and Instructions:
Instruction for Students
To complete all the experiments within time, to understand them completely and effectively, each student must obey the following points:
General discipline in the Lab
Discipline is always given the highest precedence for maintaining the quality standard of your lab. Any misconduct will be seriously dealt with and immediately responded without prior notification.
To ensure a pleasant, productive and comfortable experience for all of our users, you are directed to adhere to the following guidelines:
Students will not be allowed after ten minutes from the scheduled time.
Students will not leave the lab till the period is over.
Attendance in the lab class is compulsory.
Students should maintain silence while performing the experiments.
Students should not attend a different lab group/section other than the one assigned at the beginning of the session.
Please help us to keep the facility (Equipments- etc.) clean by discarding trash in the receptacles.
Please respect the sensitivities of your peers and refrain from viewing any inappropriate content.
Any attempt on Hacking information will be reciprocated with serious consequences.
Please abide by the rules and make appropriate use of all facilities. Users found to be damaging computer configurations, accessing content or systems illegally or attempting to compromise security may be deprived of the facility or will be fined.
Preparations and Performance
Students should come to the lab thoroughly prepared on the experiments they are assigned to perform on that day.
Data Structures and Algorithms
vi | P a g e
Students should save the results (Screenshots) of their programs performed during lab session.
Students must bring the lab manual on each practical class with Algorithm, Flowchart, Program and Results (Screenshots) of the last experiments performed complete in all respect.
Students without lab manual will not be allowed to do the experiments and hence lose their attendance.
Lab Report
Each student is required to write a complete report of the experiment he has performed and bring to lab class for evaluation in the next working lab.
Report should be written very clearly and lab record should be maintained neatly.
The lab report must contain the following:
Duly completed title page
Algorithms
Flowcharts
Code of Program
Screenshots of Results
Safety Measures
Do not leave your personal belongings unattended. The Computing Labs and Staff will not be responsible for any lost personal items.
Data Structures and Algorithms
vii | P a g e
Table of Contents
1.
Programs based on Arrays ………
1.1Write a program to find the smallest and largest number out of n numbers using array.
1.2Write a program to insert a number at a given location in an array of n numbers
1
2.
Programs based on Functions ……….
2.1Write a function to display the sum and multiplication of all the integer elements stored in the array.
2.2Write a program to implement tower of Hanoi.
3
3.
Programs based on Pointers ………
3.1Write a program to test whether a given number is positive, negative or equal to zero.
3.2Write a program to pass a character array in a function and function should compute the total number of occurrences of a particular character in the character array.
5
4.
Programs based on Structures ………...
4.1Write a program to maintain the records of 50 students with the following details (name, age, roll no, branch, DOB) and print the details of only those students whose branch is computer science and engineering.
7
5.
Programs based on Stacks ………....
5.1Write a program for static implementation of various stack operations. 5.2Write a program for dynamic implementation of various stack operations
9
6.
Programs based on Queues ………..
6.1Write a program for static implementation of various operations on linear queue. 6.2Write a program for dynamic implementation of various operations on linear queue
11
7.
Programs based on Linked Lists ………..…….
7.1Write a program to create a linked list and perform insertion and deletion operation on it.
Data Structures and Algorithms
viii | P a g e
8.
Programs based on Sorting Techniques ………..
8.1Write a program to perform bubble sort. 8.2Write a program for insertion sort. 8.3Write a program for selection sort. 8.4Write a program for quick sort. 8.5Write a program for merge sort
15
9.
Programs based on Searching Techniques ………...
9.1Write a program to perform linear search on n elements in an array. 9.2Write a program to perform binary search on n elements in an array.
20
10.
Programs based on Trees ………..
10.1Write a program for preorder tree traversal techniques. 10.2Write a program for postorder tree traversal techniques. 10.3Write a program for inorder tree traversal techniques.
22
11.
Programs based on Graphs ………
11.1Write a program to implement graph traversal using BFS. 11.2Write a program to implement graph traversal using DFS.
25
12.
Value Added Programs ………
12.1Write a program to implement call by value and call by reference. 12.2Write a program to search an element in a 2-D array using linear search.
12.3Write a program to perform insertion, deletion and updating operations on BST (Binary Search Tree)
12.4Write a program to delete an element on the nth location in the array.
Data Structures and Algorithms
1 | P a g e
1.
Programs Based on Arrays
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
Data Structures and Algorithms
Data Structures and Algorithms
3 | P a g e
2.
Programs Based on Functions
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
Data Structures and Algorithms
Data Structures and Algorithms
5 | P a g e
3.
Programs Based on Pointers
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
3.1Write a program to test whether a given number is positive, negative or equal to zero.
Data Structures and Algorithms
Data Structures and Algorithms
7 | P a g e
4.
Programs Based on Structures
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
Data Structures and Algorithms
Data Structures and Algorithms
9 | P a g e
5.
Programs Based on Stacks
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
Data Structures and Algorithms
Data Structures and Algorithms
11 | P a g e
6.
Programs Based on Queues
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
Data Structures and Algorithms
Data Structures and Algorithms
13 | P a g e
7.
Programs Based on Linked Lists
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
Data Structures and Algorithms
Data Structures and Algorithms
15 | P a g e
8.
Programs Based on Sorting Techniques
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
20 | P a g e
9.
Programs Based on Searching Techniques
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
Data Structures and Algorithms
Data Structures and Algorithms
22 | P a g e
10.
Programs Based on Trees
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
25 | P a g e
11.
Programs Based on Graphs
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
Data Structures and Algorithms
Data Structures and Algorithms
27 | P a g e
12.
Value Added Programs
Date of Performance__________ Date of Submission ____________Faculty’s Signature ______________
12.1 Write a program to implement call by value and call by reference. 12.2 Write a program to search an element in a 2-D array using linear search.
12.3 Write a program to perform insertion, deletion and updating operations on BST (Binary Search Tree)
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
Data Structures and Algorithms
32 | P a g e
Data Structures and Algorithms
Data Structures and Algorithms
34 | P a g e