Open In App

Slicing – Software Engineering

Last Updated : 22 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This article focuses on discussing Slicing in Software Engineering.

What is Slicing?

Slicing or program slicing is a technique used in software testing that takes a slice or a group of program statements in the program for testing particular test conditions or cases that may affect a value at a particular point of interest.

  1. It can also be used to debug to find the bugs more easily and quickly. 
  2. Slicing techniques were originally defined by Mark Weiser and they were only static at that time.
  3. Afterward, Bogdan Korel and Janusz Laski introduced dynamic slicing, which can work for a particular execution of the program. 

Below is the C++ program to implement Slicing:

C++

// C++ program to implement slicing
#include <iostream>
using namespace std;

int main() 
{
  int n = 12;
  int sum = 0;
  if (n > 10)
    sum = sum + n;
  else
    sum = sum - n;
  cout << "Hey";
}

Output

Hey

There are 2 types of Slicing:

slicing-types
Types of Slicing

Static Slicing

  1. A static slice of a program contains all statements that may impact the value of a variable at any point for any arbitrary execution of the program.
  2. Static slices are generally larger.
  3. It considers every possible execution of the program.

Below is the C++ program to implement static slicing:

C++

// C++ program to implement static
// slicing
#include <iostream>
using namespace std;

// Driver code
int main() 
{
  int n = 12;
  int sum = 0;
  if (n > 10)
    sum = sum + n;
  else
    sum = sum - n;
  cout << sum;
}

Output

12

Dynamic Slicing  

  1. A dynamic slice of a program contains all the statements that actually impact the value of a variable at any point for a particular execution of the program.
  2. Dynamic slices are mostly smaller.
  3. Considers only a particular execution of the program.

Below is the C++ program to implement dynamic slicing for the variable sum when n = 22:

C++

// C++ program to implement dynamic
// slicing 
#include <iostream>
using namespace std;

// Driver code
int main() 
{
  int n = 22;
  int sum = 0;
  if (n > 10)
    sum = sum + n;
  cout << sum;
}

Output

22

Explanation:

  1. As it can be observed in the above example the static slice takes all the possible execution (in this case it is 2) of the program which may affect the value of the variable sum.
  2. Whereas in the case of dynamic slicing, it considers only a particular execution (when n = 22) of the program which actually impacts the value of the variable sum. 

Hence, the dynamic slice is always smaller than a static slice.


Similar Reads

Introduction to Software Engineering - Software Engineering
Software is a program or set of programs containing instructions that provide desired functionality. Engineering is the process of designing and building something that serves a particular purpose and finds a cost-effective solution to problems. Table of Content What is Software Engineering?Key Principles of Software EngineeringMain Attributes of S
8 min read
Reverse Engineering - Software Engineering
Software Reverse Engineering is a process of recovering the design, requirement specifications, and functions of a product from an analysis of its code. It builds a program database and generates information from this. This article focuses on discussing reverse engineering in detail. What is Reverse Engineering?Reverse engineering can extract desig
6 min read
Requirements Engineering Process in Software Engineering
Requirements Engineering is the process of identifying, eliciting, analyzing, specifying, validating, and managing the needs and expectations of stakeholders for a software system. Table of Content What is Requirements Engineering?Requirements Engineering ProcessTools Involved in Requirement EngineeringAdvantages of Requirements Engineering Process
12 min read
Difference between Software Engineering process and Conventional Engineering Process
Software Engineering Process and Conventional Engineering Process, both are processes related to computers and development. In this article, we will see the similarities as well as differences between both, that is Software Engineering Process and the Conventional Engineering Process. Table of Content Software Engineering ProcessConventional Engine
4 min read
Re-engineering - Software Engineering
Software Re-engineering is a process of software development that is done to improve the maintainability of a software system. Re-engineering is the examination and alteration of a system to reconstitute it in a new form. This process encompasses a combination of sub-processes like reverse engineering, forward engineering, reconstructing, etc.  Tab
8 min read
Difference between Software Engineering and Computer Engineering
Software engineering and Computer engineering are two distinct disciplines that focus on different aspects of computer systems. While both fields require a strong foundation in computer science and mathematics, software engineering is focused on software development processes, while computer engineering is focused on the physical components and sys
6 min read
Evolution of Software Engineering: From an Art To Engineering Discipline
Software Engineering is a systematic and cost-effective technique for software development. It is an engineering approach to developing software. For example: If someone wants to travel from Punjab to Delhi. There are two approaches one can follow to achieve the same result: The normal approach is to go out and catch the bus/train that is available
13 min read
Difference between Forward Engineering and Reverse Engineering
Forward engineering and reverse engineering are two approaches to software development, with different goals and processes. Table of Content What is Forward Engineering?Characteristics of forward engineeringWhat is Reverse Engineering?Key Elements of Forward engineering and reverse engineeringDifference between Forward Engineering and Reverse Engin
5 min read
Software Engineering | Schick-Wolverton software reliability model
Prerequisite - Jelinski Moranda software reliability model The Schick-Wolverton (S-W) model is a modification to the J-M model. It is similar to the J-M model except that it further assumes that the failure rate at the ith time interval increases with time ti since the last debugging. In the model, the program failure rate function between the (i-1
4 min read
Software Engineering | Responsibilities of Software Project Manager
Software Project Management (SPM) is a sub-field of Project Management in which software projects are planned, implemented, monitored and controlled. It consists of three terms: Software, Project and Management. So, let us understand each term separately. Software includes a set of programs, documentation and user manual for a particular software p
3 min read
Article Tags :