Вы находитесь на странице: 1из 23

Question Bank –CS2201 DATA STRUCTURES

4202- A.C.T COLLEGE OF ENGINEERING & TECHNOLOGY


NELVOY -603107

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

QUESTION BANK

SUBJECT CODE : CS2201

SUBJECT NAME : DATA STRUCTURES

SEM ESTER : III

YEAR : II

REGULATION : 2008

Prepared By

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 1


Question Bank –CS2201 DATA STRUCTURES

G.P.Marrina M.Tech

Asst.Prof/CSE. A.C.T.C.E.T

UNIT I –LINEAR STRUCTURES

PART A (2 MARKS)

1. Define Data Structures.

Data Structures is defined as the way of organizing all data items that consider not only the
elements stored but also stores the relationship between the elements.

2. Define Linked Lists.

Linked list consists of a series of structures, which are not necessarily adjacent in memory. Each
structure contains the element and a pointer to a structure containing its successor. We call this theNext
Pointer. The last cell’s Next pointer points to NULL.

3. State the different types of linked lists.

The different types of linked list include singly linked list, doubly linked list and circular linked
list.

4. List the basic operations carried out in a linked list.

The basic operations carried out in a linked list include:


• Creation of a list
• Insertion of a node
• Deletion of a node
• Modification of a node
• Traversal of the list

5. List out the advantages of using a linked list.

• It is not necessary to specify the number of elements in a linked list during its declaration
• Linked list can grow and shrink in size depending upon the insertion and deletion that occurs in the list
• Insertions and deletions at any place in a list can be handled easily and efficiently
• A linked list does not waste any memory space

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 2


Question Bank –CS2201 DATA STRUCTURES

6. List out the applications of a linked list.

Some of the important applications of linked lists are manipulation of polynomials, sparse
matrices, stacks and queues.

7. State the difference between arrays and linked lists

Arrays Linked Lists

Size of an array is fixed Size of a list is variable

It is necessary to specify the number of It is not necessary to specify the


elements during declaration. number of elements during declaration

insertions and deletions are Insertions and deletions are carried

somewhat difficult out easily


It occupies less memory than a linked It occupies more memory
list for the same number of elements

8. Define ADT.

An abstract data type (ADT) is a set of operations. Abstract data types are mathematical
abstractions; nowhere in an ADT's definition is there any mention of how the set of operations is
implemented. This can be viewed as an extension of modular design.

9. Define Double linked list.

Each node contains two pointers; one is its predecessor and another to its successor. In fact, in the
context of doubly linked lists, the term predecessor and successor are meaningless, since the list is
entirely symmetric. Doubly linked list may be either linear or circular and may or may not contain a
header node as illustrated in the below figure.

10. Define
Circular linked list.

Suppose that a small change is made to the structure of a linear list, so that the next field in the
last node contains a pointer back to the first node rather than the null pointer. Such a list is called circular
list and is illustrated below. From any point in such a list it is possible to reach any other point in the list.
If we begin at a given node and traverse the entire list, we ultimately end up at the starting point.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 3


Question Bank –CS2201 DATA STRUCTURES

11. Define Stack.

A stack is an ordered collection of items into which new items may be inserted and from which
items may be deleted at one end, called the top of the stack.

12. What are the operations in stack?

There are two operations in stack they are,


 Pop – When the items are removed from the stack at the top.
 Push – When the items are inserted into the stack at top.

13. Define Stack as an ADT.

The representation of a stack as an abstract data type is straight forward.

14. Define Queue ADT.

A queue is an ordered collection of items from which items may be deleted at one end called the
front of the queue and into which items may be inserted at other end called the rear of the queue. For this
reason sometimes the queue is also called FIFO (first-in, first-out).

15. What are the two operations in Queue?

There are two types of operations that takes place in queue, they are
 Enqueue – To insert the item into the queue at the end.
 Dequeue – To delete the item from the queue in the front.

16. What is priority queue?

It is a data structure in which the intrinsic ordering of the elements does determine the results of
its basic operations. There are two types of priority queue,
 Ascending priority queue – It is a collection of items into which items can be inserted arbitrarily
and from which only the smallest item can be removed.
 Descending priority queue – Allows deletion of only the largest item.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 4


Question Bank –CS2201 DATA STRUCTURES

UNIT II –TREE STRUCTURES

PART A (2 MARKS)

1. Define a tree.

A tree is a collection of nodes. The collection can be empty; otherwise, a tree consists of a
distinguished node r, called the root, and zero or more nonempty (sub) trees T.

2. Define root.
This is the unique node in the tree to which further sub-trees are attached. Here, A is the root.

3. Define degree of the node.

The total number of sub-trees attached to that node is called the degree of the node. For node A,
the degree is 2 and for B and C, the degree is 0.

4. Define leaves.

These are the terminal nodes of the tree. The nodes with degree 0 are always the leaves. Here, B
and C are leaf nodes.

5. Define internal nodes.

The nodes other than the root and the leaves are called internal nodes. Here, C is the internal
node.

6. Define parent node.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 5


Question Bank –CS2201 DATA STRUCTURES

The node which is having further sub-branches is called the parent node of those sub-branches.
Here, node C is the parent node of D and E.

7. Define depth and height of a node for any node n.

 The depth of n is the length of the unique path from the root to n.
 The height of n is the length of the longest path from n to a leaf.
 Define depth and height of a tree.
 The depth of the tree is the depth of the deepest leaf. The height of the tree is equal to the height
of the root. Always depth of the tree is equal to height of the tree.

8. What do you mean by level of the tree?

The root node is always considered at level zero, and then its adjacent children are supposed to be
at level 1 and so on. Here, node A is at level 0, nodes B and C are at level 1 and nodes D and E are at level
2.

9. Define forest.

A tree may be defined as a forest in which only a single node (root) has no predecessors. Any
forest consists of a collection of trees.

11. Define a binary tree.

A binary tree is a finite set of nodes which is either empty or consists of a root and two disjoint
binary trees called the left sub-tree and right sub-tree.

12. Define a path in a tree.

A path in a tree is a sequence of distinct nodes in which successive nodes are connected by edges
in the tree.

13. Define terminal nodes in a tree.


A node that has no children is called a terminal node. It is also referred to as leaf node.

14. Define non-terminal nodes in a tree.

All intermediate nodes that traverse the given tree from its root node to the terminal nodes are
referred as non-terminal nodes.

15. Define a full binary tree.

A full binary tree is a tree in which all the leaves are on the same level and every non-leaf node
has exactly two children.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 6


Question Bank –CS2201 DATA STRUCTURES

16. Define a complete binary tree.

A complete binary tree is a tree in which every non-leaf node has exactly two children not
necessarily to be on the same level.

17. Define a right-skewed binary tree.

A right-skewed binary tree is a tree, which has only right child nodes.

18. State the properties of a binary tree.

 The maximum number of nodes on level n of a binary tree is 2 n-1, where n≥1.
 The maximum number of nodes in a binary tree of height n is 2 n-1, where n≥1.
 For any non-empty tree, n1=nd+1 where n1is the number of leaf nodes and nd is the number of
nodes of degree 2.

19. What is meant by binary tree traversal?

Traversing a binary tree means moving through all the nodes in the binary tree, visiting each node
in the tree only once.

20. What are the different binary tree traversal techniques?

•Preorder traversal
•Inorder traversal
•Postorder traversal
•Levelorder traversal

21. What are the tasks performed while traversing a binary tree?

•Visiting a node
•Traverse the left sub-tree
•Traverse the right sub-tree

22. What are the tasks performed during preorder traversal?

•Process the root node


•Traverse the left sub-tree
•Traverse the right sub-tree

23. What are the tasks performed during inorder traversal?

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 7


Question Bank –CS2201 DATA STRUCTURES

•Traverse the left sub-tree


•Process the root node
•Traverse the right sub-tree

24. What are the tasks performed during postorder traversal?

•Traverse the left sub-tree


•Traverse the right sub-tree
•Process the root node

25. State the merits of linear representation of binary trees.

•Storage method is easy and can be easily implemented in arrays


•When the location of a parent/child node is known, other one can be determined easily
•It requires static memory allocation so it is easily implemented in all programming language

26. State the demerit of linear representation of binary trees.

Insertions and deletions in a node take an excessive amount of processing time due to data
movement up and down the array.

27. State the merit of linked representation of binary trees.

Insertions and deletions in a node involve no data movement except the rearrangement of
pointers, hence less processing time.

28. State the demerits of linked representation of binary trees.

•Given a node structure, it is difficult to determine its parent node


•Memory spaces are wasted for storing null pointers for the nodes, which have one or no sub-trees
•It requires dynamic memory allocation, which is not possible in some programming language

29. Define a binary search tree.

A binary search tree is a special binary tree, which is either empty or it should satisfy the
following characteristics.
•Every node has a value and no two nodes should have the same value i.e) the values in the binary
search tree are distinct.
•The values in any left sub-tree is less than the value of its parent node
•The values in any right sub-tree is greater than the value of its parent node
•The left and right sub-trees of each node are again binary search trees

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 8


Question Bank –CS2201 DATA STRUCTURES

30. What do you mean by general trees?


General tree is a tree with nodes having any number of children.

31. Define ancestor and descendant.


If there is a path from node n1 to n2, then n1 is the ancestor of n2 and n2 is the descendant of n1.

32. Why it is said that searching a node in a binary search tree is efficient than that of a
simple binary tree?

In binary search tree, the nodes are arranged in such a way that the left node is having
less data value than root node value and the right nodes are having larger value than that of
root. Because of this while searching any node the value of the target node will be compared with
the parent node and accordingly either left sub branch or right sub branch will be searched. So, one has to
compare only particular branches. Thus searching becomes efficient.

33. What is the use of threaded binary tree?

In threaded binary tree, the NULL pointers are replaced by some addresses. The left
pointer of the node points to its predecessor and the right pointer of the node points toits successor.

34. What is an expression tree?

An expression tree is a tree which is build from infix or prefix or postfix expression. Generally, in
such a tree, the leaves are operands and other nodes are operators.

35. Define right-in threaded tree.

Right-in threaded binary tree is defined as one in which threads replace NULL pointers
in nodes with empty right sub-trees.

37. Define left-in threaded tree.


Left-in threaded binary tree is defined as one in which each NULL pointers is altered to
contain a thread to that node’s inorder predecessor.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 9


Question Bank –CS2201 DATA STRUCTURES

UNIT III–BALANCED TREE

PART A (2 MARKS)

1. Define AVL Tree.

An empty tree is height balanced. If T is a non-empty binary tree with T L and TR as its left and right
subtrees, then T is height balanced if

1. TL and TR are height balanced.

2. | hL - hR | ≤ 1.

Where hl and hr are the height of TL and TR respectively.

2. What do you mean by balanced trees?

Balanced trees have the structure of binary trees and obey binary search tree properties.
Apart from these properties, they have some special constraints, which differ from one data
structure to another. However, these constraints are aimed only at reducing the height of the
tree, because this factor determines the time complexity. Eg: AVL trees, Splay trees.

3. What are the categories of AVL rotations?

Let A be the nearest ancestor of the newly inserted nod which has the balancing
factor ±2. Then the rotations can be classified into the following four categories:
Left-Left: The newly inserted node is in the left subtree of the left child of A.

Right-Right: The newly inserted node is in the right subtree of the right child of A.

Left-Right: The newly inserted node is in the right subtree of the left child of A.

Right-Left: The newly inserted node is in the left subtree of the right child of A.

4. What do you mean by balance factor of a node in AVL tree?

The height of left subtree minus height of right subtree is called balance factor of a
node in AVL tree. The balance factor may be either 0 or +1 or -1. The height of an empty tree is
-1.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 10


Question Bank –CS2201 DATA STRUCTURES

5. Define splay tree.

A splay tree is a binary search tree in which restructuring is done using a scheme called splay.
The splay is a heuristic method which moves a given vertex v to the root of the splay tree using a
sequence of rotations.
6. What is the idea behind splaying?

Splaying reduces the total accessing time if the most frequently accessed node is moved
towards the root. It does not require maintaining any information regarding the height or
balance factor and hence saves space and simplifies the code to some extent.

7. List the types of rotations available in Splay tree.

Let us assume that the splay is performed at vertex v, whose parent and grandparent are p
and g respectively. Then, the three rotations are named as:
Zig:

If p is the root and v is the left child of p, then left-left rotation at p would suffice. This case always
terminates the splay as v reaches the root after this rotation.

Zig-Zig:

If p is not the root, p is the left child and v is also a left child, then a left-left rotation at g followed by
a left-left rotation at p, brings v as an ancestor of g as well as p.

Zig-Zag:

If p is not the root, p is the left child and v is a right child, perform a left-right rotation at g and
bring v as an ancestor of p as well as g.

8. Define Heap.

A heap is defined to be a complete binary tree with the property that the value of each
node is at least as small as the value of its child nodes, if they exist. The root node of the heap has the
smallest value in the tree.

9. What is the minimum number of nodes in an AVL tree of height h?

The minimum number of nodes S(h), in an AVL tree of height h is given by S(h)=S(h-
1)+S(h-2)+1. For h=0, S(h)=1.

10. Define B-tree of order M.

A B-tree of order M is a tree that is not binary with the following structural properties:
•The root is either a leaf or has between 2 and M children.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 11


Question Bank –CS2201 DATA STRUCTURES

•All non-leaf nodes (except the root) have between ┌M/2┐ and M children.

•All leaves are at the same depth.

11. What do you mean by 2-3 trees?

A B-tree of order 3 is called 2-3 trees. A B-tree of order 3 is a tree that is not binary with
the following structural properties:
•The root is either a leaf or has between 2 and 3 children.

•All non-leaf nodes (except the root) have between 2 and 3 children.

•All leaves are at the same depth.

12. What do you mean by 2-3-4 tree?

A B-tree of order 4 is called 2-3-4 tree. A B-tree of order 4 is a tree that is not binary with the
following structural properties:
•The root is either a leaf or has between 2 and 4 children.

•All non-leaf nodes (except the root) have between 2 and 4 children.

•All leaves are at the same depth.

13. What are the applications of B-tree?

•Database implementation
•Indexing on non primary key fields.

14. What is the need for Priority queue?

In a multiuser environment, the operating system scheduler must decide which of the several
processes to run only for a fixed period of time. One algorithm uses queue. Jobs are initially placed at the
end of the queue. The scheduler will repeatedly take the first job on the queue, run it until either it finishes
or its time limit is up and place it at the end of the queue if it does not finish. This strategy is not
appropriate, because very short jobs will soon to take a long time because of the wait involved in the run.
Generally, it is important that short jobs finish as fast as possible, so these jobs should have precedence
over jobs that have already been running. Furthermore, some jobs that are not short are still very
important and should have precedence. This particular application seems to require a special kind of
queue, known as priority queue. Priority queue is also called as Heap or Binary Heap.

15. What are the properties of binary heap?

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 12


Question Bank –CS2201 DATA STRUCTURES

i)Structure Property

ii)Heap Order Property

16. What do you mean by structure property in a heap?

A heap is a binary tree that is completely filled with the possible exception at the bottom level,
which is filled from left to right. Such a tree is known as a complete binary tree.

17. What do you mean by heap order property?

In a heap, for every node X, the key in the parent of X is smaller than (or equal to) the
key in X, with the exception of the root (which has no parent).

18. What are the applications of priority queues?

•The selection problem

•Event simulation

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 13


Question Bank –CS2201 DATA STRUCTURES

UNIT IV – HASHING AND SET

PART A (2 MARKS)

1.General idea of hashing and what is the use of hashing function?

A hash table similar to an array of some fixes size-containing keys. The keys specified here might be
either integer or strings, the size of the table is taken as table size or the keys are mapped on to some
number on the hash table from a range of 0 to table size.

2. Explain Hashing .

Hashing is a technique used to identify the location of an identifier ‘x’ in the memory by some
arithmetic functions like f(x), which gives address of ‘x’ in the table.

3.Explain Hash Function.

Hash Function takes an identifier and computes the address of that identifier in the hash table.

4.Mention Different types of popular hash function.

1.Division method

2.Square method

3.Folding method

5.Define Collision.

When two different keys compute in the same location or address in the hash table through any
one of the hashing function then it is termed as collision.

6. Mention Different types of collision resolving techniques.

The collision resolving techniques are:

 Separate chaining.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 14


Question Bank –CS2201 DATA STRUCTURES

 Open Addressing

 Linear Probing

 Quadratic Probing

 Double Hashing.

7. Define Separate Chaining

Separate Chaining is a technique used to avoid collision, where a linked list is used to store the
keys which fall into the same address in the hash table.

8.Define Open Addressing.

Open addressing is an alternative to resolving collisions with linked lists. In an open addressing
hashing system, if a collision occurs, alternative cells are tried until an empty cell is found.

9.Define Linear probing.

In Linear Probing, F is a linear function of i, typically F(i)=i. This amount to trying cells sequentially in
search of an empty cell.

10.Define Quadratic Probing

Quadratic Probing is a collsion resolution method that eliminates the primary clustering problem of linear
probingThe popular choice is F(i)=i2.

11.Define Double Hashing.

For Double Hashing ,One popular choice is F(i)=i . hash2(X).This formula says that we apply a second
hash function to X and probe at a distance hash2(X), hash2(X)…and so on.

12.What are the use of hash table?

1. Compilers can use hash table to keep track of declared variable in source code.

2. A hash table is useful for any graph theory problem where nodes have real names instead of numbers

3. A third use of hash table is in program that play games.

4. On line spell checkers

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 15


Question Bank –CS2201 DATA STRUCTURES

13.Define Equivalence relation.

A relation R is defined on a set S if for every pair of element (a, b), a, bS, aRb is either true or
false if aRb is true, then we say that a is related to b.

An Equivalence relation is a relation R that satisfies these properties,

(1) Reflexive aRa, for all a  S

(2) Symmetric aRa if and only if bRa

(3) Transitive aRb and bRc implies that aRc.

Eg:- Electrical connectivity

14. List the operation of set ADT?

Union and Find are the two operations on set ADT

15. What is electrical connectivity?

Where all connection are metal wires, in an equivalence relation. The relation is clearly
reflexive ,as any component is connected to itself. If a is electrically connected to b, then b must be
electrically connected to a, so this relation is symmetric. Finally if a is connected to b and b is connected
to c then a is connected to c. Thus electrical connectivity is an equivalence relation.

16. What is equivalence class?

The equivalence class of an element a € S is the subset of S that contain all the element that are
related to a.

17. When the Disjoint set Union / Find algorithm is dynamic?

During the course of the algorithm, the set can change via the Union operation. The algorithm
must also operate on-line: when a find is preformed ,it must give an answer before continuing.

18. Define smart union algorithms.

Always to make the smaller tree a sub tree of the larger, breaking ties by any method Union by
size Union by height.

19. What is path compression?

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 16


Question Bank –CS2201 DATA STRUCTURES

This is the only way to speed the algorithm up , without reworking the data structure entirely.
Path compression is performed during a Find operation.

20. Write the code disjoint set Find with path compression method.

Set Type

Find(Element Type X,DisjSet S)

if(S[X]<=0)

return X;

else

return S[X]=Find(S[X],S);

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 17


Question Bank –CS2201 DATA STRUCTURES

UNIT V – GRAPHS

PART A (2 MARKS)

1. Define Graph.

A Graph G, consists of a set of vertices V, and a set of edges E.V is a finite non-empty set consisting of
vertices of vertices of the graph. The set of edges E consists of a pair of vertices from the vertex set.

2. What is undirected graph.


If an edge between any two nodes in a graph is not directionally oriented, a graph is
called as undirected graph. It is also called as unqualified graph.

a b

3. What is directed graph.


If an edge between any two nodes in a graph is directionally oriented, a graph is called as directed
graph. It is also called as digraph.

a b

4. Define a cycle in a graph.


A cycle is a path containing atleast thee vertices such that the starting and the ending vertices are
the same.

5. Define a weakly connected graph.


A directed graph is said to be a weakly connected graph if any vertex doesn’t have a directed path
to any other vertices.

6. Define a weighted graph.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 18


Question Bank –CS2201 DATA STRUCTURES

A graph is said to be 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 edges along the path.
2
a b

5 11

7. Define parallel edges


In some directed as well as undirected graph certain pair of nodes are joined by more than one
edge, such edges are called parallel edges.

a b
a

c d
a a
8. List some representation of Graphs?

Physically a graph can be represented as,

-adjacency matrix

-Incident matrix

-Adjacency list

-Adjacency multilist

-Circular adjacency list

9. Define Adjacency Matrix.


Adjacency Matrix is a representation used to represent a graph with zeros and ones.A graph
containing n vertices can be represented using n rows and n columns.

10. What is meant by Traversing a Graph?

It means visiting all the nodes in the graph

11. Define undirected graph / directed graph.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 19


Question Bank –CS2201 DATA STRUCTURES

If G=(V, E) is a graph. The edge between v1 and v2 is represented as (v1, v2). If the edges of the form
(v1, v2) and (v2, v1) are treated as the same edge, then G is said to be an undirected graph.

In case of a directed graph, the edge <v1, v2> and <v2, v1> are different.

12. Define out degree of a graph.

In a directed graph, for any node ‘v’, the number of outgoing edges from ‘v’ are called out degree
of a node ‘v’. Ex : out degree of c =2

a b

c
13. Define In degree of a graph.

In a directed graph, for any node ‘v’, the number of incoming edges to ‘v’ are called In degree of
a node ‘v’. Ex : In degree of c =1

a b

14. Define total degree of a graph.

The sum of the In degree and out degree of a node is called the total degree of the node. Ex :
total degree of a node c = 1 +2 =3

a b

15. Define a path in a graph.


A path in a graph is defined as a sequence of distinct vertices each adjacent to the next,except
possibly the first vertex and last vertex is different.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 20


Question Bank –CS2201 DATA STRUCTURES

The path in a graph is the route taken to reach the terminal node from a starting node.

a b
a
e
a
c d
a a

The path from ‘a’ to ‘e’ are

P1 = ((a,b),(b,e))

P2 = ((a,c),(c,d),(d,e))

16. What is a complete Graph.

A complete graph is a graph in which there is an edge between every pair of vertices.

a b
a

c d
a a

17. Give the adjacency list representation for the following

A B
a

A B C D
C D
a

0 1 1 1

0 0 0 1

0 0 0 1

1 1 1 0
Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 21
Question Bank –CS2201 DATA STRUCTURES

18. List out the graph traversals of graph search?

The two methods of traversal is,

-Depth First Search (DFS)

-Breadth First Search (BFS)

19. Define minimum cost spanning tree.

A spanning tree of a connected graph G, is a tree consisting of edges and all the vertices of G.

In minimum spanning tree T, for a given graph G, the total weights of the edges of the spanning tree
must be minimum compared to all other spanning trees generated from G.

-Prim’s and Kruskal is the algorithm for finding Minimum Cost Spanning Tree.

20. Define shortest path problem.

For a given graph G=(V, E), with weights assigned to the edges of G, we have to find the shortest path
(path length is defined as sum of the weights of the edges) from any given source vertex to all the
remaining vertices of G.

21. Define topological sort.

A topological sort is an ordering of vertices in a directed acyclic graph, such that if there is a path
from vi to vj appears after vi in the ordering.

22. What is the use of Kruskal’s algorithm and who discovered it?

Kruskal’s algorithm is one of the greedy techniques to solve the minimum spanning tree
problem. It was discovered by Joseph Kruskal when he was a second-year graduate student.

23. What is the use of Dijksra’s algorithm?

Dijkstra’s algorithm is used to solve the single-source shortest-paths problem: for a given vertex
called the source in a weighted connected graph, find the shortest path to all its other vertices. The single-
source shortest-paths problem asks for a family of paths, each leading from the source to a different
vertex in the graph, though some paths may have edges in common.

24. Prove that the maximum number of edges that a graph with n Vertices is

n*(n-1)/2.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 22


Question Bank –CS2201 DATA STRUCTURES

Choose a vertex and draw edges from this vertex to the remaining n-1 vertices. Then, from these n-
1 vertices, choose a vertex and draw edges to the rest of the n-2 Vertices. Continue this process till it
ends with a single Vertex.

Hence, the total number of edges added in graph is

(n-1)+(n-2)+(n-3)+…+1 =n*(n-1)/2.

25. Define connected and strongly connected graph.

Two Vertices u and v are said to be connected if there exists a path from u to v in the graph. A directed
graph is said to be connected if every pair of vertices in the graph is connected.

A directed graph is said to be strongly connected if for every pair of distinct vertices v i and vj, there
exists two disjoint paths, one from vi to vj and the other from vj to vi.

Dept. of CSE -A.C.T College of Engineering & Technology, Nelvoy Page 23

Вам также может понравиться