0% found this document useful (0 votes)
18 views13 pages

Dsa Cat 2 QP & kEY

Uploaded by

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

Dsa Cat 2 QP & kEY

Uploaded by

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

ACHARIYA

COLLEGE OF ENGINEERING TECHNOLOGY


(Approved by AICTE New Delhi & Affiliated to Pondicherry University)
An ISO 9001 : 2008 Certified Institution
DEPARTMENT OF ARTIFICIAL INTELLIGENCE & DATA SCIENCE

CONTINUOUS ASSESSMENT TEST-II


ACADEMIC YEAR 2023-24
Subject Name: DSA Time : 2 Hrs
Subject Code: ADES304 Max. Marks : 50
Date of Exam: YEAR / SEM : II/III

Course Outcomes:
To realize the properties of tree data structure and its importance in searching large
CO3
database.
CO4 To understand graph data structure and its applications.
Knowledge Level: K1-Knowledge, K2-Understand, K3-Apply, K4-Analyze, K5-Synthesis K6 - Evaluate

Q.No Ms CO’s B.L


PART A (10 × 2 = 20 Marks)
Answer all the Questions
1. Define tree? 2 CO3 K1
2. What is an AVL tree? 2 CO3 K1
3. Define B tree? 2 CO3 K1
4. State the properties of tree? 2 CO3 K2
5. Define a binary search tree. 2 CO3 K1
6. Define graph 2 CO4 K1
7. Define a weighted graph. 2 CO4 K1
8. Define set. 2 CO4 K1
9. Differentiate depth first traversal and Breadth first traversal 2 CO4 K1
10. What is a spanning tree? 2 CO4 K1

PART B (3× 10 = 30 Marks)

Answer ANY THREE Questions


CO3
11. Explain about the B+Trees 10 K1, K2
CO3
12. Explain about the Trie trees? 10 K2
CO4
13. How graph is represented? 10 K1
CO4
14. Explain transitive closure with examples 10 K2
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)
An ISO 9001 : 2008 Certified Institution
DEPARTMENT OF ARTIFICIAL INTELLIGENCE & DATA SCIENCE

ANSWER KEY
PART A
1. Define tree?
Tree is a non linear data structure. There is no linear relation between the data items.
It can be defined as finite set of more than one node.
There is a special node designated as root node.

2. What is an AVL tree?


An AVL tree (Adelson-Velskii and Landis' tree, named after the inventors) is a self-balancing binary
search tree.
3. Define B tree?
B-tree is a tree data structure that keeps data sorted and allows searches, sequential access, insertions, and
deletions in logarithmic time
4. State the properties of tree?
Any node can be the root of the tree.If the root is identified; then that tree is called as the rooted node.
If it is not identified; then that tree is called as the free tree.
5. Define a binary search tree.
A binary search tree is a special binary tree which s either empty or I it is empty it should satisfy the following
characteristics.
Every node has a value and no two nodes should have the same value.
The values in any left subtree are less than the value of its parent node.
The values in any right subtree are greater than the values of its parent node.
The left and right subtrees of each nod are again binary search trees.
6. Define graph
A graph consists of two sets V, E.

o V is a finite and non empty set of vertices.

o E is a set of pair of vertices; each pair is called an edge.


7. Define a weighted graph.
Linked list is a dynamic and linear data structure.
A graph is said to be a weighted graph if every edge in the graph is assigned some weight or value. The weight
of an edge is a positive value that may be representing the distance between the vertices or the weights of the
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)
An ISO 9001 : 2008 Certified Institution
DEPARTMENT OF ARTIFICIAL INTELLIGENCE & DATA SCIENCE

edges along the path.

8. Define set.
A set is an abstract data structure that can store certain values, without any particular order, and no repeated
values. It is a computer implementation of the mathematical concept of a finite set. Unlike most other
collection types, rather than retrieving a specific element from a set, one typically tests a value for
membership in a set.

9. Differentiate depth first traversal and Breadth first traversal


Both are graph traversal algorithms. They differ in the order they reach the nodes. Depth first explores
all of the nodes reachable from X before moving on to any of X’s siblings, whereas breadth first search explores
siblings before children. For a depth first use a stack implementation and for breadth first queue can be used.

10. . What is a spanning tree?


A spanning tree is any tree that consists only of edges in a graph G and that includes all the vertices in G.

PART B
11. Explain about the B+Trees
A B-tree is very efficient with respect to search and modification operations that involve a single
record –For example, let m = 100 and N = 1000000; in such case the search of a key requires at most 4
disk accesses
A B-tree however is not particularly suited for sequential operations nor for range searches The
retrieval of the next key value may requires accessing a large number of nodes
To address such problem a variation to the B-tree structure has been proposed, known as B+-tree
Main idea
In a B-tree, the key values have two functions: separatorso determine the path to follow during the
search
Key values to allow accessing the information associated with them (that is, the pointers to the data)
In a B+-tree such functions are kept distinct:
The leaf nodes contain all the key values (and the associated information)
The internal nodes (organized as a B-tree) store some separators which have the only function of
determining the path to follow when searching for a key value
In addition the leaf nodes are linked in a list, in order to efficiently support range searches or
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)
An ISO 9001 : 2008 Certified Institution
DEPARTMENT OF ARTIFICIAL INTELLIGENCE & DATA SCIENCE

sequential searches (there is also a pointer to the first element of such list to support fast accesses to
the minimum key value) partial duplication of the keys
T\he index entries (keys and data references) are only stored in the leaf nodes
A search for a given key value must always determine a leaf node
The subtree on the left side of a separator contains key values that are lower than the separator; the
subtree on the right side of a separator contains key values which are greater or equal than the
separator
In the case of alphanumeric keys, one can reduce the space requirements by using separators that
have reduced lengths

B+Tree insertion:
Insert at bottom level If leaf page overflows, split page and copy middle element to next index page

If index page overflows, split page and move middle element to next index page
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)
An ISO 9001 : 2008 Certified Institution
DEPARTMENT OF ARTIFICIAL INTELLIGENCE & DATA SCIENCE
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)
An ISO 9001 : 2008 Certified Institution
DEPARTMENT OF ARTIFICIAL INTELLIGENCE & DATA SCIENCE

B+Tree Deletion:
Delete key and data from leaf page
If leaf page underflows, merge with sibling and delete key in between them
If index page underflows, merge with sibling and move down key in between them
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)
An ISO 9001 : 2008 Certified Institution
DEPARTMENT OF ARTIFICIAL INTELLIGENCE & DATA SCIENCE

12.Explain about the Trie trees?


Tries [from retrieval, but pronounced "try"]
Store characters in nodes (not keys).
Each node has R children, one for each possible character.(for now, we do not draw null links)
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)

DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

Search in a
trie:
Follow links corresponding to each character in the key.
Search hit: node where search ends has a non-null value.
Search miss: reach null link or node where search ends has null value.

Follow links corresponding to each character in the key.


Search hit: node where search ends has a non-null value.
Search miss: reach null link or node where search ends has null value.
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)

DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

Follow links corresponding to each character in the key.


Search hit: node where search ends has a non-null value.
Search miss: reach null link or node where search ends has null value.

Follow links corresponding to each character in the key.


Search hit: node where search ends has a non-null value.
Search miss: reach null link or node where search ends has null value.
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)

DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

13. How graph is represented?


QUEUE
GRAPH REPRESENTATION:
The graphs can be represented by the follow three methods,
1. Adjacency matrix.
2. Adjacency list.
3. Adjacency multi-list.

ADJACENCY MATRIX:
The adjacent matrix A of graph G = (V,E) with n vertices is an n * n matrix , such that
Aij =1 , if there is an edge Vi to Vj
Aij =0, if there is no edge.
Adjacent matrix for Directed Graph:

Example:
V1,2 =1, since there is an edge V1 to Vw
Similarly V1,3 =1, there is an edge V1 to V3
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)

DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

V1,1 & V1,4 = 0, there is no edge


Adjacent matrix for Undirected Graph:

Adjacent matrix for Weighted Graph:


Aij = Cij, if there exists an edge from Vi to Vj
Aij =0, if there is no edge & i = j
If there is no arc from i to j , Assume C[i,j]=∞ where i ≠ j

Advantages:
1. Simple to implement
Disadvantages:
1. Takes O(n2) space to represent the graph
2. Takes O(n2) time to solve the most of the problem

ADJACENCY LIST
In this representation, we store a graph as a linked structure.We store all vertices in a list then for each
vertex , we have a linked list of its adjacency vertices.
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)

DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

Disadvantages:
1. It take O(n) time to determine whether there is an arc from vertex I to vertex j. Since there can be O(n)
vertices on the adjacency list for vertex i.
14. Explain transitive closure with examples

A problem related to the all pairs shortest path problem is that of determining for every pair of vertices i,j in G the
existence of a path from i to j. Two cases are of interest, one when all path lengths (i.e., the number of edges on the
path) are required to be positive and the other when path lengths are to be nonnegative. If A is the adjacency matrix
+ +
of G, then the matrix A having the property A (i,j) = 1 if there is a path of length > 0 from i to j and 0 otherwise is
* *
called the transitive closure matrix of G. The matrix A with the property A (i,j) = 1 if

there is a path of length 0 from i to j and 0 otherwise is the reflexive transitive closure matrix of G.
ACHARIYA
COLLEGE OF ENGINEERING TECHNOLOGY
(Approved by AICTE New Delhi & Affiliated to Pondicherry University)

DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

+ * * + +
Figure shows A and A for a digraph. Clearly, the only difference between A and A is in the terms on the diagonal. A
*
(i,i) = 1 iff there a cycle of length > 1 containing vertex i while A (i,i) is always one as there is a path of length 0 from i
to i. If we use algorithm ALL_COSTS with COST(i,j) = 1 if <i,j> is an edge in G and COST(i,j) = +

if <i,j> is not in G, then we can easily obtain A+ from the final matrix A by letting A+ (i,j) = 1 iff A (i,j) < +∞. A*
can be obtained from A+ by setting all diagonal elements equal 1. The total time is O(n3). Some simplification is
achieved by slightly modifying the algorithm. In this modification the computation of line 9 of ALL_COSTS

becomes A(i,j) A (i,j) or (A(i,k) and A(k,)) and COST(i,j) is just the adjacency matrix of G. With this modification,
A need only be a bit matrix and then the final matrix A will be A+.

You might also like