Lab Manual DSA
Lab Manual DSA
Lab Manual
Department of Computer Science and Engineering
The NorthCap University, Gurugram
EWA Lab Manual (CSL 273) | i
2019-20
Data Structures
Lab Manual
CSL 209
Pooja Sapra
Session 2021-22
Published by:
Copying or facilitating copying of lab work comes under cheating and is considered as use
of unfair means. Students indulging in copying or facilitating copying shall be awarded zero
marks for that particular experiment. Frequent cases of copying may lead to disciplinary
action. Attendance in lab classes is mandatory.
Labs are open up to 7 PM upon request. Students are encouraged to make full use of labs
beyond normal lab hours.
PREFACE
Data Structures Lab Manual is designed to meet the course and program requirements of
NCU curriculum for B.Tech II year students of CSE branch. The concept of the lab work is to
give brief practical experience for basic lab skills to students. It provides the space and
scope for self-study so that students can come up with new and creative ideas.
The Lab manual is written on the basis of “teach yourself pattern” and expected that
students who come with proper preparation should be able to perform the experiments
without any difficulty. Brief introduction to each experiment with information about self-
study material is provided. The laboratory exercises will include familiarization with linear
and non-linear data structures starting with the basics of Arrays, Linked Lists to advanced
data structures like Trees & Graphs along with their implementation in Java programming
language that covers all the basic operations. Students would attain the practical
understanding of different kinds of data structures along with their implementation and
operations performed. Finally, the students would require applying the practical concepts
of data structures learned in solving real time problems that involves their basic usage and
applicability. At the start of each experiment a question bank for preparation and practice
is suggested which may be used to test the basic understanding of the students about the
experiment. Students are expected to come thoroughly prepared for the lab. General
disciplines, safety guidelines and report writing are also discussed.
The lab manual is a part of curriculum for the TheNorthCap University, Gurugram.
Teacher’s copy of the experimental results and answer for the questions are available as
sample guidelines.
We hope that lab manual would be useful to students of CSE, IT, ECE and BSc branches and
author requests the readers to kindly forward their suggestions / constructive criticism for
further improvement of the work book.
Author expresses deep gratitude to Members, Governing Body-NCU for encouragement and
motivation.
Authors
The NorthCap University
Gurugram, India
CONTENTS
S.N. Details Page No.
Syllabus
1 Introduction
2 Lab Requirement
3 General Instructions
4 List of Experiments
6 List of Projects
7 Rubrics
COURSE TEMPLATE
6. Type of Course
(Check one): Programme Core ü Programme Elective Open Elective
9. Brief Syllabus:
Solving computational problems requires the knowledge of efficient data organization and the ability to make
effective choices among multiple solutions. In this course, we will explore several fundamental data structures in
computer science and learn to implement them in Java. The course aims to teach the fundamentals of data
structures, their design, implementation and effective use in problem solving approach. With the knowledge of data
structures and practical experience in implementing them, students can become much more effective designer and
developer. The course will start with the basic introduction of linear as well as non-linear data structures and further
proceeds with the programming intensive task of implementing them. This course will also cover file organization
and different hashing techniques in its last module.
Total lecture, Tutorial and Practical Hours for this course (Take 15 teaching weeks per semester): 75
Practice
Lectures: 45 hours
Tutorials : 0 hours Lab Work: 30 hours
To understand and implement various data structures like Arrays, Linked Lists, Stack, Queues,
CO 1
Tree, Graphs and File Organization
CO 2 To be able to illustrate the basic operations of data structures Arrays and Linked List using Java
To apply mathematical functions, Algorithmic principles and theoretical concepts to the modelling
CO 4
and designing of solutions for Non-linear Data Structures Trees and Graphs
To use sound development principles to implement various linear and non-linear data structures of
CO 5
varying complexities for Sorting the elements and organization of files
Unit Number: 1 Title: Object Oriented Programming and Data Structure No. of hours: 8
Content Summary:
Java Software Development Tools, Wrapper Classes, The ArrayList, Interfaces, Data & its meaning, Types of data
structures, Linear and Non-linear data structures, Introduction to Algorithms and analyzing time complexities
Unit Number: 2 Title: Arrays and Linked Lists No. of hours: 8
Content Summary:
Introduction to Arrays, Representation in Row major and Column major order, Array traversal, Linear and Binary
search, Linked list introduction, Insertion and Deletion, Doubly Linked list, Circular Linked list and their
implementation
Unit Number: 3 Title: Stacks & Queues No. of hours: 10
Content Summary:
Stack operations Push, pop, peek, Implementation using arrays and linked list, Stack applications, Polish Notations,
Introduction to Queues, Implementation using Arrays and Linked Lists, Circular Queues, Doubly ended queues
(Dqueues), Priority Queues applications and implementation
Unit Number: 4 Title: Trees & Graphs No. of hours: 12
Content Summary:
Introduction to Binary Trees, Expression trees, Tree traversal: Inorder, Preorder & Postorder, Tree implementation
using Array and Linked List, Introduction to Binary Search Tree, Insertion and Deletion in BST, AVL Trees, Insertion
and Deletion, B Trees: Insertion and traversal
Introduction to Graphs, Representation, Graph traversal: Breadth First Search & Depth First Search, Applications
Unit Number: 5 Title: Sorting Algorithms & File Organization No. of hours: 7
Content Summary:
Sorting introduction, Bubble Sort, Quick Sort, Merge Sort and Heap Sort Implementation and analysis, File
Organization: File representation on hard disks, Indexing and Hashing techniques, Linear probing & Quadratic
probing
12. Brief Description of Self-learning components by students (through books/resource material etc.):
Object-Oriented Design with UML
GUI Programming
Books Recommended :
Text Books:
1) Robert Lafore, “Data Structures and Algorithms in Java”, SAMS publications, 2 nd Edition, 2002
2) Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser, “Data Structures and Algorithms in Java”,
Wiley Publications, 6th Edition, 2014
Reference Books:
3) Seymour Lipschutz, “Data Structures”, Schaum’s Outlines, McGraw Hill Education, 1 st Edition, 2014
4) Aaron M. Tannenbaum, Yedidyah Langsam, Moshe J.Augenstein, “Data Structure using C”, Pearson India,
1st Edition, 2018
Reference Websites: (nptel, swayam, coursera, edx, udemy, lms, official documentation weblink)
https://canvas.asu.edu/courses/58080
https://lms.ncuindia.edu/course/view.php?id=323
https://www.coursera.org/learn/data-structures?specialization=data-structures-algorithms
https://swayam.gov.in/nd2_cec19_cs04/preview
https://www.edx.org/course/data-structures-an-active-learning-approach
1. NA
TYPE OF ALLOT
S. No. PARTICULAR PASS CRITERIA
COURSE TED
1 Theory+ Minor Test RANG
15% Must Secure 30% Marks Out of
Practical
Major Test 35% Combined Marks of Major Test
(L-T-P/L-0-P)
Continuous Evaluation 10% Plus Minor Test with Overall 40%
Through Class Marks in Total.
Tests/Practice/Assign
ments/Presentation/Q
uiz
Online Quiz 5%
Lab Work 35%
Mapping of PO’s and CO’s
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1 2 2 2 1 1 1 1 1 2 2 3 3 2 2 1
CO2 1 2 1 1 1 1 1 1 2 3 2 2 2 1 2
CO3 3 3 2 2 2 1 1 1 2 3 3 2 3 2 2
CO4 3 3 3 3 3 2 2 2 2 3 3 3 3 3 3
CO5 2 2 2 2 2 1 2 1 2 2 2 2 3 2 2
1. INTRODUCTION
To understand and implement various data structures like Arrays, Linked Lists,
Stack, Queues, Tree and Graphs
Reporting and analysing their complexities.
To illustrate the basic functionality and operations performed
To use sound development principles to implement various non-linear data
structures of varying complexities.
Hands on experience on the experimental setup and software tools
2. LAB REQUIREMENTS
Requirements Details
Required Bandwidth NA
3. GENERAL INSTRUCTIONS
Students must turn up in time and contact concerned faculty for the experiment
they are supposed to perform.
Students will not be allowed to enter late in the lab.
Students will not leave the class till the period is over.
Students should come prepared for their experiment.
Experimental results should be entered in the lab report format and
certified/signed by concerned faculty/ lab Instructor.
Students must get the connection of the hardware setup verified before
switching on the power supply.
Students should maintain silence while performing the experiments. If any
necessity arises for discussion amongst them, they should discuss with a very
low pitch without disturbing the adjacent groups.
Violating the above code of conduct may attract disciplinary action.
Damaging lab equipment or removing any component from the lab may invite
penalties and strict disciplinary action.
3.2 Attendance
Attendance in the lab class is compulsory.
Students should not attend a different lab group/section other than the one
assigned at the beginning of the session.
On account of illness or some family problems, if a student misses his/her lab
classes, he/she may be assigned a different group to make up the losses in
consultation with the concerned faculty / lab instructor. Or he/she may work
in the lab during spare/extra hours to complete the experiment. No attendance
will be granted for such case.
EàFàGàHàAàBàCàD
10 Write a program to implement Sublime 2 CO2
stack using arrays and linked Text/Notepad++
lists.
11 Write a program to reverse a Sublime 2 CO2
sentence using stack. Text/Notepad++
12 Write a program to check for Sublime 2 CO2
balanced parenthesis in a given Text/Notepad++
expression.
13 Write a program to convert infix Sublime 2 CO2
1. Write a Java program to swap the first and last elements of an array (length must be at
least 5) and create a new array.
2. Write a Java program to segregate all 0s on left side and all 1s on right side of a given
array of 0s and 1s.
3. Write a program to rearrange a given list such that it consists of alternating minimum
maximum elements
4. Write a program for calculating the frequency of different values in a linked list of
integers with multiple entries.
5. Write a program in java to Check if stack elements are pairwise consecutive or not.
6. Write a program to reverse the first m elements from the queue, where m < n, n is the
total number of elements in queue.
7. Write a Java program to construct a binary tree using the given In-Order and Pre-Order
traversal
a. Example:
b. Input :
i. in[] = {4, 8, 2, 5, 1, 6, 3, 7}
ii. pre[] = {1, 2, 4, 8, 5, 3, 6, 7}
6. RUBRICS
Marks Distribution
Continuous Evaluation(50 Marks) End Semester Exam (20 Marks)
Each experiment shall be evaluated for 10 End semester practical evaluation
marks and at the end of the semester including Mini project (if any) carries 20
proportional marks shall be awarded out of marks.
50.
Following is the breakup of 10 marks for
each
4 Marks: Observation & conduct of
experiment. Teacher may ask questions
about experiment.
3 Marks: For report writing
3 Marks: For the 15 minutes quiz to be
conducted in every lab.
Annexure 1
(Student Lab Report)
Data Structures
(CSL 209)
Link to Code:
Date: 12/08/2021
Faculty Signature:
Marks:
Objective(s):
To familiarize the students with linear data structure array and its basic operations
Outcome:
The students will be able to implement and use arrays for solving various problems
Problem Statement:
Create an array of integer with size n. Return the difference between the largest and the smallest value inside
that array.
Background Study:
5.max_val = arr[i]
7.min= arr[i]
8.Print difference(max_val-min).
import java.util.*;
public class Difference {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.println("Enter the size of array : ");
int i;
int n = sc.nextInt();
int arr[] = new int[n];
System.out.println("Enter " + n + " elements of the array : ");
for(i = 0; i < n; i++)
{
arr[i] = sc.nextInt();
}
Data Structure Lab Manual (CSL 209) | 3
2021-22
int max_val = arr[0];
int min = arr[0];
for(i = 1; i < n; i++)
{
if(arr[i] > max_val)
max_val = arr[i];
else if(arr[i] < min)
min = arr[i];
}
System.out.println("Difference between the largest and smallest values of the said array: "+
(max_val-min));
}
}
Question Bank:
It is called linear ds because the memory allocation of the data in array is contiguous unlike
list and trees.the memory is allocated initially and the elements are fed into it in a linear order till
the limit of array is encountered. Insertion in between is not possible.
Presence Index
Equality Index
Substring Index
Browsing Index
Approximate Index
International Index
Data Structure Lab Manual (CSL 209) | 4
2021-22
EXPERIMENT NO. 2
Semester /Section:
Link to Code:
Date:
Faculty Signature:
Marks:
Objective(s):
To familiarize the students with linear data structure array and its basic operations
Outcome:
The students will be able to implement and use arrays for solving various problems
Problem Statement:
1. Write a program that initializes an array with ten random integers and then prints four lines of
output, containing:
Every element at an even index
Every odd element
All elements in reverse order
Only the first and last element
Data Structure Lab Manual (CSL 209) | 5
2021-22
Background Study:
Question Bank:
1. How we can segregate all 0s on left side and all 1s on right side of a given array of 0s and
1s.
2. How to reverse the array elements.
3. How to find the index of an array element
4. How to remove a specific element from an array.
5. How to insert an element (specific position) into an array.
Data Structure Lab Manual (CSL 209) | 6
2021-22
EXPERIMENT NO. 3
Semester /Section:
Link to Code:
Date:
Faculty Signature:
Marks:
Objective(s):
To familiarize the students with linear data structure array and its basic operations
Outcome:
The students will be able to implement and use arrays for solving various problems
Problem Statement:
3 Write a program to read numbers in an integer array of size 5 and display the following:
Sum of all the elements
Sum of alternate elements in the array
Second highest element in the array
Background Study:
Question Bank:
1. How we can count occurrence of a given number in the array and its frequency.
2. How we can print the following in 2-D integer array with each element of maximum 2 digits
3. Given an array of integers, return the number of times that two 6's are next to each other in
the array. Also count instances where the second element is 7
4. Write a method called swapPairs() that accepts an array of integers and swaps the elements at
adjacent indexes. That is, elements 0 and 1 are swapped, elements 2 and 3 are swapped, and so
Data Structure Lab Manual (CSL 209) | 8
2021-22
on. If the array has an odd length, the final element should be left unmodified. For example, the
list {10, 20, 30, 40, 50} should become {20, 10, 40, 30, 50} after a call to your method.
5. Write a method called median() that accepts an array of integers as its argument and returns
the median of the numbers in the array. The median is the number that will appear in the middle
if you arrange the elements in order.