Uploaded by Ahsan Zaman BCSF19BM034

BACHELOR OF COMPUTER SCIENCE-1

advertisement
BACHELOR OF COMPUTER SCIENCE
ASSIGNMENT
(3rd SEMESTER)
DATA STRUCTURE AND ALGORITHM
ASSIGNMENT OF: DATA STRUCTURE AND
ALGORITHM
ROLL NO
: BCSF19BM034
SUBMITTED TO : ASAD HUSSAIN
SUBMITTED BY
: AHSAN ZAMAN
Q.1:-What is Data Structure?
A data structure is a specialized format for organizing,
processing, retrieving and storing data. While there are several
basic and advanced structure types, any data structure is
designed to arrange data to suit a specific purpose so that it can
be accessed and worked with in appropriate ways.
Types of Data Structure:Data structure types are determined by what types of
operations are required or what kinds of algorithms are going
to be applied. These types include:
 Arrays- An array stores a collection of items at adjoining
memory locations. Items that are the same type get stored
together so that the position of each element can be
calculated or retrieved easily. Arrays can be fixed or
flexible in length.
 Stacks- A stack stores a collection of items in the linear
order that operations are applied. This order could be last
in first out (LIFO) or first in first out (FIFO).
 Queues- A queue stores a collection of items similar to a
stack; however, the operation order can only be first in
first out.
 Linked lists- A linked list stores a collection of items in a
linear order. Each element, or node, in a linked list




contains a data item as well as a reference, or link, to the
next item in the list.
Trees- A tree stores a collection of items in an abstract,
hierarchical way. Each node is linked to other nodes and
can have multiple sub-values, also known as children.
Graphs- A graph stores a collection of items in a non-linear
fashion. Graphs are made up of a finite set of nodes, also
known as vertices, and lines that connect them, also
known as edges. These are useful for representing real-life
systems such as computer networks.
Tries- A trie, or keyword tree, is a data structure that
stores strings as data items that can be organized in a
visual graph.
Hash tables- A hash table, or a hash map, stores a
collection of items in an associative array that plots keys to
values. A hash table uses a hash function to convert an
index into an array of buckets that contain the desired
data item.
Q.2:What is Algorithm?
The word Algorithm means “a process or set of rules to be
followed in calculations or other problem-solving operations”.
Therefore Algorithm refers to a set of rules/instructions that
step-by-step define how a work is to be executed upon in order
to get the expected results.
It can be understood by taking an example of cooking a new
recipe. To cook a new recipe, one reads the instructions and
steps and execute them one by one, in the given sequence. The
result thus obtained is the new dish cooked perfectly. Similarly,
algorithms help to do a task in programming to get the
expected output.
The Algorithm designed are language-independent, i.e. they are
just plain instructions that can be implemented in any
language, and yet the output will be the same, as expected.
Characteristics of an Algorithm:-
As one would not follow any written instructions to cook the
recipe, but only the standard one. Similarly, not all written
instructions for programming is an algorithm. In order for some
instructions to be an algorithm, it must have the following
characteristics:
 Clear and Unambiguous: Algorithm should be clear and
unambiguous. Each of its steps should be clear in all
aspects and must lead to only one meaning.
 Well-Defined Inputs: If an algorithm says to take inputs, it
should be well-defined inputs.
 Well-Defined Outputs: The algorithm must clearly define
what output will be yielded and it should be well-defined
as well.
 Finite-ness: The algorithm must be finite, i.e. it should not
end up in an infinite loops or similar.
 Feasible: The algorithm must be simple, generic and
practical, such that it can be executed upon will the
available resources. It must not contain some future
technology, or anything.
 Language Independent: The Algorithm designed must be
language-independent, i.e. it must be just plain
instructions that can be implemented in any language, and
yet the output will be same, as expected.
Q.3:-What is White Box Testing?
White box testing techniques analyze the internal structures
the used data structures, internal design, code structure and
the working of the software rather than just the functionality as
in black box testing. It is also called glass box testing or clear
box testing or structural testing.
Working process of white box testing:
Input: Requirements, Functional specifications, design
documents, source code.
Processing: Performing risk analysis for guiding through the
entire process.
Proper test planning: Designing test cases so as to cover entire
code. Execute rinse-repeat until error-free software is reached.
Also, the results are communicated.
Output: Preparing final report of the entire testing process.
Testing techniques:
 Statement coverage: In this technique, the aim is to
traverse all statement at least once. Hence, each line of
code is tested. In case of a flowchart, every node must be
traversed at least once. Since all lines of code are covered,
helps in pointing out faulty code.
Statement Coverage Example
 Branch Coverge: In this technique, test cases are designed
so that each branch from all decision points are traversed
at least once. In a flowchart, all edges must be traversed at
least once.
4 test cases required such that all branches of all decisions are
covered, i.e, all edges of flowchart are covered
 Condition Coverage: In this technique, all individual
conditions must be covered as shown in the following
example:
READ X, Y
IF(X == 0 || Y == 0)
PRINT ‘0’
In this example, there are 2 conditions: X == 0 and Y == 0. Now,
test these conditions get TRUE and FALSE as their values. One
possible example would be:
 #TC1 – X = 0, Y = 55
 #TC2 – X = 5, Y = 0
 Multiple Condition Coverage: In this technique, all the
possible combinations of the possible outcomes of
conditions are tested at least once. Let’s consider the
following example:
READ X, Y
IF(X == 0 || Y == 0)
PRINT ‘0’




#TC1: X = 0, Y = 0
#TC2: X = 0, Y = 5
#TC3: X = 55, Y = 0
#TC4: X = 55, Y = 5
Hence, four test cases required for two individual conditions.
Similarly, if there are n conditions then 2n test cases would be
required.
 Basis Path Testing: In this technique, control flow graphs
are made from code or flowchart and then Cyclomatic
complexity is calculated which defines the number of
independent paths so that the minimal number of test
cases can be designed for each independent path.
Steps:
Make the corresponding control flow graph
Calculate the cyclomatic complexity
Find the independent paths
Design test cases corresponding to each independent path
 Flow graph notation: It is a directed graph consisting of
nodes and edges. Each node represents a sequence of
statements, or a decision point. A predicate node is the
one that represents a decision point that contains a
condition after which the graph splits. Regions are
bounded by nodes and edges.
 Cyclomatic Complexity: It is a measure of the logical
complexity of the software and is used to define the
number of independent paths. For a graph G, V(G) is its
cyclomatic complexity.
Calculating V(G):
V(G) = P + 1, where P is the number of predicate nodes in the
flow graph
V(G) = E – N + 2, where E is the number of edges and N is the
total number of nodes
V(G) = Number of non-overlapping regions in the graph
Example:
V(G) = 4 (Using any of the above formulae)
No of independent paths = 4





#P1: 1 – 2 – 4 – 7 – 8
#P2: 1 – 2 – 3 – 5 – 7 – 8
#P3: 1 – 2 – 3 – 6 – 7 – 8
#P4: 1 – 2 – 4 – 7 – 1 – . . . – 7 – 8
Loop Testing: Loops are widely used and these are
fundamental to many algorithms hence, their testing is
very important. Errors often occur at the beginnings and
ends of loops.
 Simple loops: For simple loops of size n, test cases are
designed that:
 Skip the loop entirely
 Only one pass through the loop
 2 passes
 m passes, where m < n
 n-1 ans n+1 passes
 Nested loops: For nested loops, all the loops are set to
their minimum count and we start from the innermost
loop. Simple loop tests are conducted for the innermost
loop and this is worked outwards till all the loops have
been tested.
 Concatenated loops: Independent loops, one after
another. Simple loop tests are applied for each.
If they’re not independent, treat them like nesting.
Advantages: White box testing is very thorough as the entire code and
structures are tested.
 It results in the optimization of code removing error and
helps in removing extra lines of code.
 It can start at an earlier stage as it doesn’t require any
interface as in case of black box testing.
 Easy to automate.
Disadvantages: Main disadvantage is that it is very expensive.
 Redesign of code and rewriting code needs test cases to
be written again.
 Testers are required to have in-depth knowledge of the
code and programming language as opposed to black box
testing.
 Missing functionalities cannot be detected as the code
that exists is tested.
 Very complex and at times not realistic.
Q.4:-What is Non-Linear Data structure?
A non-linear data structure is a data structure in which a data
item is connected to several other data items. So that a given
data item has the possibility to reach one-or-more data items.
 Pros
Uses memory efficiently that the free contiguous memory
in not an requirement for allocating data items
The length of the data items is not necessary to be known prior
to allocation
 Cons
Overhead of the link to the next data item.
Types of Non-Linear Data Structure:
 Graphs
A Graph is a non-linear data structure consisting of nodes and
edges. The nodes are sometimes also referred to as vertices
and the edges are lines or arcs that connect any two nodes in
the graph. More formally a Graph can be defined as,
A Graph consists of a finite set of vertices(or nodes) and set of
Edges which connect a pair of nodes.
In the above Graph, the set of vertices V = {0,1,2,3,4} and the
set of edges E = {01, 12, 23, 34, 04, 14, 13}.
Graphs are used to solve many real-life problems. Graphs are
used to represent networks. The networks may include paths in
a city or telephone network or circuit network. Graphs are also
used in social networks like linkedIn, Facebook.
 Trees.
A tree is a nonlinear data structure, compared to arrays, linked
lists, stacks and queues which are linear data structures. A tree
can be empty with no nodes or a tree is a structure consisting
of one node called the root and zero or one or more subtrees.
THE END
Download