0% found this document useful (0 votes)
26 views27 pages

Data Structure Practical-1

This document is a laboratory manual for the Data Structures course (3130702) for B.E. Computer Engineering students in their third semester. It outlines the objectives, practical outcomes, and industry-relevant skills expected to be developed through hands-on experiments, emphasizing a competency-focused, outcome-based curriculum. The manual includes guidelines for faculty and students to ensure effective learning and assessment in data structures and algorithms.

Uploaded by

vishvampandya74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views27 pages

Data Structure Practical-1

This document is a laboratory manual for the Data Structures course (3130702) for B.E. Computer Engineering students in their third semester. It outlines the objectives, practical outcomes, and industry-relevant skills expected to be developed through hands-on experiments, emphasizing a competency-focused, outcome-based curriculum. The manual includes guidelines for faculty and students to ensure effective learning and assessment in data structures and algorithms.

Uploaded by

vishvampandya74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Degree Engineering

A Laboratory Manual for

Data Structures
(3130702)

[ B.E. (Computer Engineering) : Semester - 3 ]

Enrolment No
Name
Branch
Academic Term
Institute Name

Directorate of Technical Education, Gandhinagar,


Gujarat
Government Engineering College, Bhavnagar
Department of Computer Engineering

CERTIFICATE

This is to certify that Mr./Ms.__________________________________________

Enrollment No. _______________ of B.E. Semester - III from Computer

Engineering Department of this Institute (GTU Code: _021__) has satisfactorily

completed the Practical / Tutorial work for the subject Data structure (3130702) for

the academic year 2023-24.

Place: ___________

Date: ___________

Signature of Course Faculty Head of the Department


Data Structure (3130702) Enrollment No

Preface

Main motto of any laboratory/practical/field work is for enhancing required skills as well as
creating ability amongst students to solve real time problem by developing relevant competencies
in psychomotor domain. By keeping in view, GTU has designed competency focused outcome-
based curriculum for engineering degree programs where sufficient weightage is given to
practical work. It shows importance of enhancement of skills amongst the students and it pays
attention to utilize every second of time allotted for practical amongst students, instructors and
faculty members to achieve relevant outcomes by performing the experiments rather than having
merely study type experiments. It is must for effective implementation of competency focused
outcome-based curriculum that every practical is keenly designed to serve as a tool to develop
and enhance relevant competency required by the various industry among every student. These
psychomotor skills are very difficult to develop through traditional chalk and board content
delivery method in the classroom. Accordingly, this lab manual is designed to focus on the
industry defined relevant outcomes, rather than old practice of conducting practical to prove
concept and theory.

By using this lab manual students can go through the relevant theory and procedure in advance
before the actual performance which creates an interest and students can have basic idea prior to
performance. This in turn enhances pre-determined outcomes amongst students. Each experiment
in this manual begins with competency, industry relevant skills, course outcomes as well as
practical outcomes (objectives). The students will also achieve safety and necessary precautions
to be taken while performing practical.

This manual also provides guidelines to faculty members to facilitate student centric lab activities
through each experiment by arranging and managing necessary resources in order that the
students follow the procedures with required safety and necessary precautions to achieve the
outcomes. It also gives an idea that how students will be assessed by providing rubrics.

Data Structures is a core course in all computer science undergraduate curricula. The course is
the basis for understanding several data structures and also algorithms that operate on them. The
course forms the foundation for almost all computer science subjects: compilers, operating
systems, databases, AI and software engineering. The course comes with a lab in most universities
in India. The associated lab in university curricula focuses on implementation of algorithms
operating on the data structures, i.e., coding programs on the data structures and algorithms.
Data Structure (3130702) Enrollment No

DTE’s Vision

▪ To provide globally competitive technical education


▪ Remove geographical imbalances and inconsistencies
▪ Develop student friendly resources with a special focus on girls’ education and support to
weaker sections
▪ Develop programs relevant to industry and create a vibrant pool of technical professionals

Institute’s Vision
To transform the students into good human beings, employable engineering graduates
and continuous learners by inculcating human values and imparting excellence in technical
education.

Institute’s Mission
To provide education to students from the local and rural areas, so that they become enlightened
individuals and improve the living standards of their families, and their contribution to industry and
society. To foster a learning environment with technology integration and individual attention, so
that the students imbibe quality technical knowledge, skill-development and character building.

Department’s Vision

To achieve excellence for providing value based education in computer science and Information
Technology through innovation, team work and ethical practices.

Department’s Mission

• To produce graduates according to the need of industry, government, society and


scientific community and to develop partnership with industries, government agencies
and R & D Organizations for knowledge sharing and overall development of faculties
and students.
• To motivate students/graduates to be entrepreneurs.
• To motivate students to participate in reputed conferences, workshops, symposiums,
seminars and related technical activities.
• To impart human and ethical values in our students for better serving of society.

Programme Outcomes (POs)


Data Structure (3130702) Enrollment No

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of
the information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.1
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change
Data Structure (3130702) Enrollment No

Program Specific Outcomes (PSOs)


• An ability to design solutions by simulating computer engineering problems in absence of
real time environment.
• An ability to learn and use of open source tools in the areas like operating systems, computer
programming, computer networks and database management.
• An ability to face competitive examinations for higher education and PSUs.

Program Educational Objectives (PEOs)

• Have careers in industry, research & academics focusing on the application of the
information technologies and take leadership positions in the industry and also initiate
businesses offering innovative solutions.
• Capable of adapting to new technologies and constantly upgrade their skills with an
attitude towards lifelong learning.
• Act conscientiously about the potentials and the responsibilities of the computing
profession in the context of science, technology, society and humanity.
Data Structure (3130702) Enrollment No

Practical – Course Outcome matrix

Course Outcomes (COs)


Define and classify various data structures, storage structures and common
CO_3130702.1
operations on them
Create various linear data structures with their representation and perform
CO_3130702.2
different operations on them
Create various nonlinear data structures with their representation and perform
CO_3130702.3
different operations on them
CO_3130702.4 Apply various searching sorting techniques on data set
Solve the given a problem using an appropriate data structure to achieve
CO_3130702.5 optimal performance and compare its performance with other possible data
structures

Sr. CO CO CO CO CO
Practical Outcome/Title of experiment
No. 1 2 3 4 5

1. Classification of Data Structure and Stack

1.1 Classify various data structures


1.2 Implement a program for stack that performs
following operations using array. (a) PUSH (b) POP
(c) PEEP (d) CHANGE (e) DISPLAY
1.3 Implement a program to convert infix notation to
√ √ √
postfix notation using stack.
1.4 Write a program to implement Tower of Hanoi
problem.
1.5 Identify widely used application which use stack data
structure for implementation of its important feature.

2. Queue

2.1 Write a program to implement QUEUE using arrays


that performs following operations (a) INSERT (b)
DELETE (c) DISPLAY
2.2 Write a program to implement Circular Queue using
arrays that performs following operations. (a) √ √
INSERT (b) DELETE (c) DISPLAY
2.3 Identify widely used application which use Queue
data structure for implementation of its important
feature.

3. Singly linked list

3.1 Write a menu driven program to implement


following operations on the singly linked list. √ √
(a) Insert a node at the front of the linked list.
Data Structure (3130702) Enrollment No

(b) Insert a node at the end of the linked list.


(c) Insert a node such that linked list is in ascending
order.(according to info. Field)
(d) Delete a first node of the linked list.
(e) Delete a node before specified position.
(f) Delete a node after specified position.
3.2 Write a program to implement stack using linked list.
3.3 Write a program to implement queue using linked
list.

4. Doubly linked list

4.1 Write a program to implement following operations


on the doubly linked list.
(a) Insert a node at the front of the linked list.
√ √
(b) Insert a node at the end of the linked list.
(c) Delete a last node of the linked list.
(d) Delete a node before specified position.

5. Circular linked list

5.1 Write a program to implement following operations


on the circular linked list.
(a) Insert a node at the end of the linked list.
(b) Insert a node before specified position.
√ √
(c) Delete a first node of the linked list.
(d) Delete a node after specified position.
5.2 Identify widely used application which use Linked
List for implementation of its important feature.

6. Tree

6.1 Write a program which create binary search tree.


6.2 Implement recursive tree traversing methods in-
order, pre-order and post-order traversal √ √
6.3 Identify widely used application which use Tree data
structure for implementation of its important feature.

7. Graph

7.1 Write a program to perform BFS and DFS on given


graph.
7.2 Identify widely used application which use Graph √ √
data structure for implementation of its important
feature.

8. Searching

8.1 Write a program to implement Linear Search.


√ √
8.2 Write a program to implement Binary Search.
Data Structure (3130702) Enrollment No

8.3 Identify widely used application which use


Searching technique for implementation of its
important feature.

9. Sorting

9.1 Write a program to implement Quick Sort


9.2 Write a program to implement Merge Sort
9.3 Write a program to implement Bubble Sort
√ √
9.4 Identify widely used application which use Sorting
technique for implementation of its important
feature.

10 Hashing and File Structure

10.1 Write a program to create hash table and handle


the collision using linear probing.
10.2 Write a program to demonstrate the file primitives
such as fopen, fclose, fprintf. √ √
10.3 Identify widely used application which use
Hashing technique for implementation of its
Important feature.
Data Structure (3130702) Enrollment No
Industry Relevant Skills

The following industry relevant competencies are expected to be developed in the student by
undertaking the practical work of this laboratory.
1. Will be able to classify data structures and identify storage representation of primitive
and non-primitive data structures
2. Will be able to implement various operations on Stack, Queue, Link list, Tree, Graph,
Hashing and File operations.
3. Will be able to understand need of sorting and searching for various applications
4. Will be able to apply various data structure to design real time applications in efficient
manner.

Guidelines for Faculty members

1. Teacher should provide the guideline with demonstration of practical to the students
with all features.
2. Teacher shall explain basic concepts/theory related to the experiment to the students before
starting of each practical
3. Involve all the students in performance of each experiment.
4. Teacher is expected to share the skills and competencies to be developed in the
students and ensure that the respective skills and competencies are developed in the
students after the completion of the experimentation.
5. Teachers should give opportunity to students for hands-on experience after the
demonstration.
6. Teacher may provide additional knowledge and skills to the students even though not
covered in the manual but are expected from the students by concerned industry.
7. Give practical assignment and assess the performance of students based on task
assigned to check whether it is as per the instructions or not.
8. Teacher is expected to refer complete curriculum of the course and follow the
guidelines for implementation.

Instructions for Students

1. Students are expected to carefully listen to all the theory classes delivered by the faculty
members and understand the COs, content of the course, teaching and examination scheme,
skill set to be developed etc.
2. Students will have to perform experiments on computer system on which C/C++ compiler
is installed to execute programs of data structure.
3. Students should develop programs and execute all the programs using C/C++ compiler.
Students have to show output of each program in their practical file.
4. Students are instructed to submit practical list as per given sample list shown on next page.
5. Student should develop a habit of submitting the experimentation work as per the schedule
and s/he should be well prepared for the same.
Data Structure (3130702) Enrollment No
Common Safety Instructions

Students are expected to

1. switch on the PC carefully (not to use wet hands)


2. shutdown the PC properly at the end of your Lab
3. carefully handle the peripherals (Mouse, Keyboard, Network cable etc)
4. use Laptop in lab after getting permission from Teacher
5. carefully handle all lab resources
Data Structure (3130702) Enrollment No

Index
(Progressive Assessment Sheet)

Date
Date of Assessme Sign. of
Sr. Page of Remar
Objective(s) of Experiment submiss nt Teacher
No. No. perfor ks
ion Marks with date
mance

1. Classification of Data Structure and Stack


1.1 Classify various data structures
1.2 Implement a program for stack that
performs following operations using array.
(a) PUSH (b) POP (c) PEEP (d) CHANGE
(e) DISPLAY
1.3 Implement a program to convert infix
notation to postfix notation using stack.
1.4 Write a program to implement Tower of
Hanoi problem.
1.5 Identify widely used application which use
stack data structure for implementation of
its important feature.
2. Queue
2.1 Write a program to implement QUEUE
using arrays that performs following
operations (a) INSERT (b) DELETE (c)
DISPLAY
2.2 Write a program to implement Circular
Queue using arrays that performs following
operations. (a) INSERT (b) DELETE (c)
DISPLAY
2.3 Identify widely used application which use
Queue data structure for implementation of
its important feature.
3. Singly linked list
3.1 Write a menu driven program to implement
following operations on the singly linked
list.
(a) Insert a node at the front of the linked
list.
(b) Insert a node at the end of the linked list.
(c) Insert a node such that linked list is in
ascending order.(according to info.
Field)
(d) Delete a first node of the linked list.
Data Structure (3130702) Enrollment No

(e) Delete a node before specified position.


(f) Delete a node after specified position.
3.2 Write a program to implement stack using
linked list.
3.3 Write a program to implement queue using
linked list.
4. Doubly linked list
4.1 Write a program to implement following
operations on the doubly linked list.
(a) Insert a node at the front of the linked
list.
(b) Insert a node at the end of the linked
list.
(c) Delete a last node of the linked list.
(d) Delete a node before specified position.
5. Circular linked list
5.1 Write a program to implement following
operations on the circular linked list.
(a) Insert a node at the end of the linked
list.
(b) Insert a node before specified position.
(c) Delete a first node of the linked list.
(d) Delete a node after specified position.
5.2 Identify widely used application which use
Linked List for implementation of its
important feature.
6. Tree
6.1 Write a program which create binary search
tree.
6.2 Implement recursive tree traversing
methods in-order, pre-order and post-order
traversal.
6.3 Identify widely used application which use
Tree data structure for implementation of its
important feature.
7. Graph
7.1 Write a program to perform BFS and DFS
on given graph.
7.2 Identify widely used application which use
Graph data structure for implementation of
its important feature.
Data Structure (3130702) Enrollment No

8. Searching
8.1 Write a program to implement Linear
Search.
8.2 Write a program to implement Binary
Search.
8.3 Identify widely used application which use
Searching technique for implementation of
its important feature.
9. Sorting
9.1 Write a program to implement Quick Sort
9.2 Write a program to implement Merge Sort
9.3 Write a program to implement Bubble Sort
9.4 Identify widely used application which use
Sorting technique for implementation of its
important feature.
10. Hashing and File Structure
10.1Write a program to create hash table and
handle the collision using linear probing.
10.2Write a program to demonstrate the file
primitives such as fopen, fclose, fprintf.
10.3Identify widely used application which use
Hashing technique for implementation of
its important feature.
Total
Data Structure (3130702) Enrollment No
Experiment No – 1
AIM : Classification of Data Structure and Stack

1.1 Classify various data structures


1.2 Implement a program for stack that performs following operations using array. (a) PUSH (b)
POP (c) PEEP (d) CHANGE (e) DISPLAY
1.3 Implement a program to convert infix notation to postfix notation using stack.
1.4 Write a program to implement Tower of Hanoi problem.
1.5 Identify widely used application which use stack data structure for implementation of its
important feature.

Date: // Write date of experiment here

Competency and Practical Skills: Logic building and programming

Relevant CO: CO1, CO2, CO5

Objectives: (a) To analyze various data structures


(b) To understand the concepts of stack
(c) To implement various applications of the stack

Equipment/Instruments: Computer System with C/C++ compiler

Safety and necessary Precautions:

✓ Operate computer system carefully and responsibly.


✓ Use required lab resources cautiously

Theory:

Data Structure

Data structures are a fundamental concept in computer science that enable efficient storage and
manipulation of data. They are used to organize and store data in a manner that allows for optimal
performance of algorithms. The selection of a suitable data structure begins with the choice of an
abstract data type, which defines the operations that can be performed on the data. Well-designed
data structures can perform a wide range of critical operations while using minimal resources such
as execution time and memory space. In essence, data structure introduction refers to the
arrangement of data in a computer's memory in a way that enables rapid access by the processor for
the required calculations.

Stack

A stack is a data structure that follows the last-in first-out (LIFO) principle, meaning that objects
are inserted and removed from the container in a particular order. In pushdown stacks, only two
Page No
Data Structure (3130702) Enrollment No

operations are allowed: pushing an item onto the stack, and popping an item off the top of the stack.
Access to the stack is limited, as elements can only be added and removed from the top. When an
item is pushed onto the stack, it becomes the new top item. Conversely, when an item is popped off
the stack, it is removed from the top.

To illustrate this concept, consider a stack of books. Just as you can only remove the top book, you
can only add a new book to the top of the stack. A stack can also have a limited capacity. If the
stack is already full and there is no space to add a new item, it is said to be in an overflow state. On
the other hand, if the stack is empty and an item is removed, it is in an underflow state, meaning
that no items are present in the stack to be removed.

A stack is an abstract data structure that operates on the LIFO principle, where the last item added
is the first item to be removed. Items can be inserted and deleted at one end called the top, creating
a structure that resembles a closed tube on one side.

✓ The add operation of the stack is called push operation


✓ The delete operation is called as pop operation.
✓ Push operation on a full stack causes stack overflow.
✓ Pop operation on an empty stack causes stack underflow.
✓ SP is a pointer, which is used to access the top element of the stack.
✓ If you push elements that are added at the top of the stack;
✓ In the same way when we pop the elements, the element at the top of the stack is deleted.

There are two operations applied on stack they are

(1) PUSH
(2) POP

In-fix- to Postfix Conversion:

Procedure to convert from infix expression to postfix expression is as follows:

1. Start scanning the infix expression from left to right.


2. If the symbol scanned is a left parenthesis, push it onto the stack.
3. If the scanned symbol is an operand, place it directly into the postfix expression output.
4. If the symbol scanned is a right parenthesis, continue to pop all items from the stack and
place them into the postfix expression output until a matching left parenthesis is found.
5. If the scanned symbol is an operator, remove all operators from the stack and place them in
the postfix expression output if and only if the precedence of the operator on top of the stack
is greater than or equal to the precedence of the scanned operator. Then push the scanned
operator onto the stack; otherwise, push the scanned operator onto the stack.

Page No
Data Structure (3130702) Enrollment No

1.1 Classify various data structures

Classification of Data Structures:

Data structures can be classified as

1. Primitive data structure


2. Non-Primitive data structure
(a) Linear data structure
(b) Non-linear data structure

1. Primitive data structures: Primitive data structures are simple data structures
constructed using the standard data types of a computer language. Examples of primitive
data structures include variables, arrays, pointers, structures, unions, and more. These
structures are used to build more complex data structures

2. Non-primitive data structures: Non-primitive data structures are constructed using


primitive data structures and have specific functionality. They can be designed by a user
and are classified into two categories: linear data structures and non-linear data structures.

(a) Linear data structures

Linear data structures are arranged as a continuous set of data elements in the memory
and can be constructed using array data types. In linear data structures, the adjacency
relationship between data elements is maintained.

Operations applied on linear data structure:

The following list of operations applied on linear data structures

✓ Add an element
✓ Delete an element
✓ Traverse
✓ Sort the list of elements
✓ Search for a data element

Examples of linear data structure

✓ Stack
✓ Queue
✓ Tables
✓ List
✓ Linked Lists.

Page No
Data Structure (3130702) Enrollment No
(b) Non-linear Data Structure:

Non-linear data structures are not arranged in a continuous manner and include data
structures such as trees and graphs. These structures can be used to represent complex
relationships between data elements.

Operations applied on non-linear data structures:

The following list of operations applied on non-linear data structures.

✓ Add elements
✓ Delete elements
✓ Display the elements
✓ Sort the list of elements
✓ Search for a data element

Examples of non-linear data structure

✓ Tree
✓ Decision tree
✓ Graph
✓ Forest

1.2 Implement a program for stack that performs following operations using array.
(a) PUSH (b) POP (c) PEEP (d) CHANGE (e) DISPLAY

Program:

#include <stdio.h>

int stack[20];
int top=-1;

int isfull()
{
if (top==20-1)
{
return 1;
}
else
{
return 0;
}
}

int isempty()
{
Page No
Data Structure (3130702) Enrollment No
if (top==-1)
{
return 1;
}
else
{
return 0;
}
}

void push(int x)
{
if (isfull())
{
printf("-->stack is full");
}
else
{
top++;
stack[top]=x;
}
}

int pop()
{
if (isempty())
{
return 0;
}
else
{
return stack[top--];
}
}

int peep()
{
if (isempty())
{
return 0;
}
else
{
return stack[top];
}

Page No
Data Structure (3130702) Enrollment No
}

void change(int pos,int x)


{
if(isempty())
{
printf("-->stack is empty");
}
else
{
stack[pos]=x;
}
}

void display()
{
int n=0;
printf("-->stack:");
while (n<=top)
{
printf("%d ", stack[n]);
n++;
}
printf("\n");
}

int main()
{
int ch;
do
{
printf("\n1.PUSH 2.POP 3.PEEP 4.CHANGE 5.DISPLAY 0.STOP\n");
printf("enter a choice for given operation:");
scanf("%d", &ch);

switch (ch)
{
case 0:
printf("-->exited successfully");
break;
case 1:
int n;
printf("enter an integer element:");
scanf("%d", &n);
push(n);
break;

Page No
Data Structure (3130702) Enrollment No
case 2:
if(top==-1)
{
printf("-->stack is empty\n");
}
else
{
printf("-->%d\n", pop());
}
break;
case 3:
if(peep())
{
printf("-->%d\n", peep());
}
else
{
printf("-->stack is empty\n");
}
break;
case 4:
int i,new;
printf("enter index and new number:");
scanf("%d%d", &i, &new);
change(i,new);
break;
case 5:
display();
break;
default:
printf("-->enter a valid number");
break;
}
}while(ch!=0);

return 0;
}

Page No
Data Structure (3130702) Enrollment No
Output:

1.3 Implement a program to convert infix notation to postfix notation using stack.

Program:

#include <stdio.h>
#define size 20

char stack[size];
int top = -1;

int isfull()
{
if (top == size - 1)
{
return 1;
}
else
{
return 0;
}
}

int isempty()
{
if (top == -1)
{
return 1;
}
Page No
Data Structure (3130702) Enrollment No
else
{
return 0;
}
}

void push(char x)
{
if (isfull())
{
printf("-->stack is full");
}
else
{
top++;
stack[top] = x;
}
}

char pop()
{
if (isempty())
{
return 0;
}
else
{
return stack[top--];
}
}

int stp(char c)
{
switch (c)
{
case '#':
return 0;
case '(':
return 1;
case '+':
case '-':
return 3;
case '*':
case '/':
return 5;
case '^':

Page No
Data Structure (3130702) Enrollment No
return 6;
default:
return 8;
}
}

int np(char c)
{
switch (c)
{
case ')':
return 1;
case '+':
case '-':
return 2;
case '*':
case '/':
return 4;
case '^':
return 7;
case '(':
return 9;
default:
return 8;
}
}

void itop(char infix[])


{
char next, t, post[20];
int i = 0, j = 0;
push('#');
while (infix[i])
{
next = infix[i++];
while (np(next) < stp(stack[top]))
{
post[j++] = pop();
}
if (np(next) == stp(stack[top]))
{
t = pop();
}
else
{
push(next);

Page No
Data Structure (3130702) Enrollment No
}
}
while (stack[top] != '#')
{
post[j++] = pop();
}
post[j] = '\0';
printf("postfix operation: %s", post);
}

int main()
{
char infix[20];
printf("enter infix expression without space:");
scanf("%s", infix);
itop(infix);
return 0;
}
Output:

1.4 Write a program to implement Tower of Hanoi problem.

Program:

#include<stdio.h>

void toh(int n,char s,char d,char a)


{
if (n==1)
{
printf("move disk:%c to %c\n", s, d);
}
else
{
toh(n-1,s,a,d);
toh(1,s,d,a);
toh(n-1,a,d,s);
}

int main()

Page No
Data Structure (3130702) Enrollment No
{
int n;
printf("enter no of rings:");
scanf("%d", &n);
toh(n,'S','D','A');

return 0;
}

Output:

1.5 Identify widely used application which use stack data structure for implementation of its
important feature.

Stack Applications:

1. Stack is used by compilers to check for balancing of parentheses, brackets and braces.
2. Stack is used to evaluate a postfix expression.
3. Stack is used to convert an infix expression into postfix/prefix form.
4. In recursion, all intermediate arguments and return values are stored on the processor’s
stack.
5. During a function call the return address and arguments are pushed onto a stack and on
return they are popped off.
6. Depth first search uses a stack data structure to find an element from a graph.

Observations:

1.Stack Implementation: The stack was successfully implemented using a specific


programming language (c language). The structure was defined as a collection of elements with
two primary operations, push and pop.
2.Characteristics: The stack followed the Last-In-First-Out (LIFO) order, where the most
recently added element is the first one to be removed.It was limited in size, and attempting to push
elements beyond this limit resulted in a stack overflow.Similarly, trying to pop from an empty
Page No
Data Structure (3130702) Enrollment No
stack resulted in a stack underflow.
3.Push Operation:The push operation allowed adding elements to the top of the stack.
The implementation correctly handled cases where the stack was full, preventing further
additions.
4. Pop Operation:The pop operation successfully removed the top element from the
stack.The implementation correctly handled cases where the stack was empty, preventing pop
operations.
5. Peep Operation:If implemented, the peep operation allowed us to view the top element
without removing it from the stack.

Conclusion:
A Stack can be used for evaluating expressions consisting of operands and operators.
Stacks can be used for Backtracking, i.e., to check parenthesis matching in an expression. It can
also be used to convert one form of expression to another form. It can be used for systematic
Memory Management.

Quiz:

(1) List various stack operations


(2) Differentiate FIFO and LIFO
(3) Explain infix, prefix and postfix expressions

Suggested Reference:

1. An Introduction to Data Structures with Applications. by Jean-Paul Tremblay & Paul G.


Sorenson Publisher-Tata McGraw Hill.
2. Data Structures using C & C++ -By Ten Baum Publisher – Prenctice-Hall International
3. Fundamentals of Computer Algorithms by Horowitz, Sahni,Galgotia Pub. 2001 ed.
4. http://www.geeksforgeeks.org/data-structures/
5. http://www.coursera.org/specializations/data-structures-algorithms

References used by the students:

Rubric-wise marks obtained:

Problem Coding Completeness


Logic
Understanding Standards and accuracy Q&A
Rubrics Building (2) Total
(2) (2) (2)
Avg. Good Avg. Good Avg. Good Avg. Good Avg. Good
(1) (2) (1) (2) (1) (2) (1) (2) (1) (2)

Marks

Page No

You might also like