Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

UIT1301 DATA STRUCTURES AND ALGORITHM ANALYSIS

UNIT I INTRODUCTION TO DATA STRUCTURES


PART A
1. Formally define the notion of algorithm with diagram
Definition of Algorithm: The algorithm is defined as a collection of unambiguous occurring
in some specific sequence and such an algorithm should produce output for given set of input
in finite amount of time.
2. Write a concept of time and space complexity
The complexity is the amount of time required by an algorithm to execute. For computing the
time complexity, the frequency count of the basic operation in the algorithm is computed.
This frequency count is then denoted in terms of asymptotic notations to express the time
complexity of an algorithm. The space complexity is an amount of space required by an
algorithm. The space complexity is denoted in terms of asymptotic nations.
3. Establish the relation between O and Ω
The notion O represents the upper bound of algorithm is running time. The omega nation
Ω represents the lower bound of algorithm’s running time.
The theta notion represents the running time between upper and lower bound. If f(n) and
g(n) are two functions then, f(n) = Ɵ(n) if and only if f(n) = f(n) = O(g(n)) and f(n) =
Ω(g(n)).
4. Define algorithm validation.
The process of measuring the effectiveness of the algorithm before actually making program
or code form it, in order to know whether the algorithm is correct for valid input is known as
algorithm validation. Algorithm validation can be done with the help of mathematical and
empirical methods.
5. What is average case analysis
In average case analysis, all the possible inputs are considered and total number of inputs
then divides the calculated values. The value, which we obtain by this computation, yields the
average case analysis.
6. What is meant by substitution methods?
Substitution method is used for solving the recurrence relation. It is a kind of methods in
which a guess for the solution is made. There are two types of substitutions made.
7 Find the number of comparisons made by the sequential search for the worst and
best case.

1
Input size – number of elements = n
Basic operation – key comparison A[i] = = k
Number of comparison:
Worst case Cwosrt (n) = n
Best case C best (n) =1
Average Case
In the case of a successful search the probability of the first match occurring in the
with position of the list is p/n
For every I and the number of comparisons made by the algorithm in such a situation
is obviously i.

In the case of an unsuccessful search of comparison is in with the probability of such


a search being (I – p)

p(n+1)
Cavg(n) = ---------- + ( I-p)

8.What is the average case complexity of linear search algorithm(APR/MAY 2012)


We can find the average number of key comparisons Cavg((n) as follows.
In the case of a successful search, the probability of the first match occurring in the ith
position of the list is p/n
For every I, and the number of comparisons made by the algorithm in such a situations is
obviously i.
In the case of an unsuccessful search, the number of comparisons is n with the
probability of such a search being (1- p). Therefore,
Cavg(n) = [ 1.p/n+2.p/n+…+i.p/n+…+n.p/n] +n.(1-p)
= p/n[1+2+…+i+….+n]+n(1-p)
=p/nn(n+1)/2+n(1-p)
Cavg(n) = p(n+1)/2+n(1-p)
9.What are the properties of asymptotic notations?(APR/MAY 2014)
Asymptotic notations and their properties
 Big-oh notation: Big-oh is used for upper bound values.
 Big-Omega notation: Big-Omega is used for lower bound values.
 Theta notation: Theta is used for average bound values.

2
10.What are the two types of algorithms?
 Brute Force Algorithm
 Recursive Algorithm
 Randomized Algorithm
 Sorting Algorithm
 Searching Algorithm
 Hashing Algorithm

UNIT II –LINEAR DATA STRUCTURES –ARRAYS,STACKS,LISTS AND QUEUES)


PART A
1. List the applications of Data Structure.
 Operating Systems
 Complier design
 Statistical and Numerical analysis
 Database Management Systems.
 Network analysis
 Expert Systems.

2. What are the properties of effective algorithm?


 It should be clear//complete and definite
 It should be efficient.
 It should be concise and compact
 It should be less time consuming
 Effective memory utilization

3. What are the classification of data structures?

3
Primitive Data Structures:
Primitive data structure is a fundamental type of data structure that stores the data of only one
type whereas the non-primitive data structure is a type of data structure which is a user-
defined that stores the data of different types in a single entity.
Linear Data Structures: A data structure is called linear if all of its elements are arranged in
the linear order. In linear data structures, the elements are stored in non-hierarchical way
where each element has the successors and predecessors except the first and last element.
Non Linear Data Structures: This data structure does not form a sequence i.e. each item or
element is connected with two or more other items in a non-linear arrangement. The data
elements are not arranged in sequential structure.
4. Define ADT.
Abstract Data type (ADT) is a type (or class) for objects whose behaviour is defined by a
set of values and a set of operations such as Union, Intersection, Complement , Find etc..   It
does not specify how data will be organized in memory and what algorithms will be used
for implementing the operations. It is called “abstract” because it gives an implementation-
independent view. The basic idea implementing ADT is that the operations are written once
in program and can be called part of the program.
5. What are the advantages of Circular Linked List ?
 It is possible to traverse from the last node back to the first i.e. the head node.
 The starting node does not matter as we can traverse each and every node despite
whatever node we keep as the starting node.
 The previous node can be easily identified.
 There is no need for a NULL function to code. The circular list never identifies a NULL
identifier unless it is fully assigned.
 Circular linked lists are beneficial for end operations as start and finish coincide.  
 Algorithms such as Round Robin setup can effectively complete online queues without
having to meet NULL suspension or reference references.
6. Write the exception condition for stack and queue.
Exceptional Condition for Stack
Overflow
Attempt to insert an element when the stack is full is said to be overflow.
Underflow
Attempt to delete an element when the stack is empty is said to be underflow
Exceptional Condition for Queue

4
Overflow
Attempt to insert an element when the queue is full is said to be overflow.
Underflow
Attempt to delete an element when the queue is empty is said to be underflow

7. Write the applications of stack?


o Evaluation of Arithmetic Expressions
o Backtracking
o Delimiter Checking
o Reverse a Data
o Processing Function Calls
8. Difference between Doubly Linked List and Singly Linked List.
Singly Linked List Doubly Linked List
A Doubly Linked List has a previous link
A Singly Linked has nodes with a data field
field along with a data field and a next link
and a next link field.
field.
In a Doubly Linked List, the traversal can
In a Singly Linked List, the traversal can
be done using the next node link as well as
only be done using the link of the next node.
the previous node link.
A Singly Linked List occupies less memory A Doubly Linked List occupies more
than the Doubly Linked List, as it has only 2 memory than the Singly Linked List, as it
fields. has 3 fields.
Accessing elements in a Singly Linked List Accessing elements in a Doubly Linked List
is less efficient when compared to a Doubly is more efficient when compared to a Singly
Linked List, as only forward traversal is Linked List as both forward and backward
possible. traversal is possible.
The time complexity of inserting or deleting The time complexity of inserting or deleting
a node at a given position (if the pointer to a node at a given position (if the pointer to
that position is given) in a singly linked list that position is given) in a doubly linked list
is O(n). is O(1).
Singly linked list is preferred when we have Doubly linked list is preferred when we
memory limitation(we can’t use much don’t have memory limitation and searching
memory) and searching is not required. is required(we need to perform search

5
operation on the linked list).

9. Define Priority Queue and its applications of Priority Queue


A priority queue is an abstract data type that behaves similarly to the normal queue except
that each element has some priority, i.e., the element with the highest priority would come
first in a priority queue. The priority of the elements in a priority queue will determine the
order in which elements are removed from the priority queue.
The priority queue supports only comparable elements, which means that the elements are
either arranged in an ascending or descending order.
Applications priority queue:
o It is used in the Dijkstra's shortest path algorithm.
o It is used in prim's algorithm
o It is used in data compression techniques like Huffman code.
o It is used in heap sort.
o It is also used in operating system like priority scheduling, load balancing and
interrupt handling.
10. Write the recursive routine for Towers of Hanoi.
void Hanoi(int n, char s, char d,chari)
{
/*n=no of disks,s->source,d->destination ,i->intermediate*/
if(n==1)
{
print(s,d);
return;
}
else
{
Hanoi(n-1,s,i,d);
print(s,d);
Hanoi(n-1,i,d,s);
return;
}
}

6
UNIT III –NON LINEAR DATA STRUCTURES -TREES

PART A
1. How tree is used to implement data structures?
Binary Tree is a special data structure used for data storage purposes. A binary
tree has a special condition that each node can have a maximum of two children. A
binary tree has the benefits of both an ordered array and a linked list as search is as
quick as in a sorted array and insertion or deletion operation are as fast as in linked
list.

2. Sketch full and complete binary tree and explain its height representation?
A full binary tree (sometimes proper binary tree or 2-tree) is a tree in which every node
other than the leaves has two children. A complete binary tree is a binary tree in which every
level, except possibly the last, is completely filled, and all nodes are as far left as possible.

7
3. List out the properties of red black tree?
 Every node has a color.
 The root is black.
 Every leaf is a special node called NIL (with no key)
 NIL is black.
 If a node is red, then it's children are black [ie no 2 red trees in a row]
 Every path from root to leaf has the same number of black nodes.

4. Explain threaded binary tree?


In the linked representation of binary trees, more than one half of the link fields
contain NULL values which results in wastage of storage space. If a binary tree
consists of n nodes then n+1 link fields contain NULL values. The NULL links are
replaced with special links known as threads. Such binary trees with threads are
known as threaded binary trees. Each node in a threaded binary tree either contains
a link to its child node or thread to other nodes in the tree.

5. Define Splay tree.


A splay tree is a self-balancing tree, but AVL and Red-Black trees are also self-balancing
trees then. What makes the splay tree unique two trees. It has one extra property that makes it
unique is splaying.A splay tree contains the same operations as a Binary search tree, i.e.,
Insertion, deletion and searching, but it also contains one more operation, i.e., splaying. So.all
the operations in the splay tree are followed by splaying.Splay trees are not strictly balanced
trees, but they are roughly balanced trees.
6.List some of the tree terminologies
Root
 The first node from where the tree originates is called as a root node.

8
 In any tree, there must be only one root node.
 We can never have multiple root nodes in a tree data structure.
Edge
 The connecting link between any two nodes is called as an edge.
 In a tree with n number of nodes, there are exactly (n-1) number of edges.
Parent
 The node which has a branch from it to any other node is called as a parent node.
 In other words, the node which has one or more children is called as a parent node.
 In a tree, a parent node can have any number of child nodes.
Child
 The node which is a descendant of some node is called as a child node.
 All the nodes except root node are child nodes.
 Nodes which belong to the same parent are called as siblings.
 In other words, nodes with the same parent are sibling nodes.
Degree
 Degree of a node is the total number of children of that node.
 Degree of a tree is the highest degree of a node among all the nodes in the tree.
Level
 In a tree, each step from top to bottom is called as level of a tree.
 The level count starts with 0 and increments by 1 at each level or step.
Height
 Total number of edges that lies on the longest path from any leaf node to a particular node
is called as height of that node.
 Height of a tree is the height of root node.
 Height of all leaf nodes = 0

7. Construction rule for expression tree.


1.Read one symbol at a time from the postfix expression.
2.Check whether the symbol is an operand or operator.
(a) if the symbol is an operand a one node tree and push a pointer on a stack.
(b) if the symbol is an operator pop two pointers from the stack T 1 and T2 and form a new tree
roots as the operator and T2 as a left child and T1as a right child. A pointer to this new tree is
then pushed onto the stack.
8.What are the properties of B tree?

9
 All leaves are at the same level.
 B-Tree is defined by the term minimum degree ‘t‘. The value of ‘t‘ depends upon disk
block size.
 Every node except the root must contain at least t-1 keys. The root may contain a
minimum of 1 key.
 All nodes (including root) may contain at most (2*t – 1) keys.
 Number of children of a node is equal to the number of keys in it plus 1.
 All keys of a node are sorted in increasing order. The child between two
keys k1 and k2 contains all keys in the range from k1 and k2.

9. What is meant 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).This property allows the deletemin
operations to be performed quickly has the minimum element can always be found at the
root.Thus,we get the FindMin operation in constant time.

10.What is the balance factor of AVL tree?


Balance factor of a node in an AVL tree is the difference between the height of the left
subtree and that of the right subtree of that node. The self balancing property of an avl tree is
maintained by the balance factor. The value of balance factor should always be -1, 0 or +1.

UNIT IV - NON LINEAR DATA STRUCTURES -GRAPHS


PART A
1.What is degree of vertex in graph data structure?
It is the number of edges incident on a vertex determines its degree.The degree of the vertex
V is written as deg(V).
Degree of vertex can be considered under two cases of graphs −
 Undirected Graph
 Directed Graph

10
2. Write the routine for Kruskal’s Algorithm
voidkruskal( graph G ) {
 intEdgesAccepted; DisjSet S; PriorityQueue H; vertex u, v; SetTypeuset, vset; Edge e;
 Initialize( S );                            // form a single node tree
 ReadGraphIntoHeapArray( G, H );
 BuildHeap( H );
 EdgesAccepted = 0;
 while(EdgesAccepted < NumVertex-1 )
 {
 e = DeleteMin( H );      // Selection of minimum edge
 uset = Find( u, S );
 vset = Find( v, S );
 if(uset != vset )
 {
 /* accept the edge */ EdgesAccepted++; SetUnion( S, uset, vset );
} }}
3. Define the term Biconnectivity and Articulation points :
Biconnectivity:
A connected undirected graph is biconnected if there are no vertices removal disconnects the
rest of the graph.
Articulation points:
The vertices whose removal would disconnect the graph as articulation point.
4.Explain graph structure.

11
A graph G=(V,E) consists of a set of vertices ,V and set of edges E. Vertices are referred
as nodes ,between the nodes are referred as egdes.Each edge is a pair (v,w) where v,w € V.
(ie.) v=V1,w=V2….

5.Explain and draw strongly connected graph.


A directed graph is strongly connected if there is a path between all pairs of vertices.
A strongly connected component (SCC) of a directed graph is a maximal strongly
connected subgraph. 

6. Outline the acyclic graph


A directed graph which has no cycles is referred to as acyclic graph.It is abbreviated
as DAG –Directed Acyclic Graph)

12
7. Write the applications of DFS.
 To check whether the undirected graph is connected or not.
 To check whether the connected undirected graph is Bio connected or not.
 To check the acyclicity of the directed graph.

8. Sketch the representation of graph


Graph can be represented by Adjacency matrix and Adjacency List .
The adjacency matrix graph A , G=(V,E) with ‘n ‘ vertices is an nXn matrix , such
that Aij=1,if there is an edge Vi to Vj
Aij= 0, if there no edge

9. Steps to implement to perform topological sort .


1. Find the indegree for every vertex
2. Place the vertices whose indegree is ‘0’ on the empty queue.
3. Dequeue the vertex V and decrement the indegree’s of all its adjacent vertices.
4. Enqueue the vertex on the queue, if its indegree falls to zero

13
5. Repeat the steps 3 until the queue becomes empty
6. The topological ordering is the order in which the vertices dequeued.

10.Define complete graph .


A graph is said to be a complete graph if, for all the vertices of the graph, there exists an edge
between every pair of the vertices. In other words, we can say that all the vertices are
connected to the rest of all the vertices of the graph. A complete graph of 'n' vertices contains
exactly nC2 edges, and a complete graph of 'n' vertices is represented as Kn.

UNIT V- SEARCHING, SORTING AND HASHING TECHNIQUES


PART A
1. Difference between linear and binary search

 Basis of Linear search Binary search


comparison

Definition The linear search starts It finds the position of the searched element by
searching from the first finding the middle element of the array.
element and compares each
element with a searched
element till the element is not
found.

Sorted data In a linear search, the elements The pre-condition for the binary search is that
don't need to be arranged in the elements must be arranged in a sorted
sorted order. order.

Implementation The linear search can be The implementation of binary search is limited

14
implemented on any linear data as it can be implemented only on those data
structure such as an array, structures that have two-way traversal.
linked list, etc.

Approach It is based on the sequential It is based on the divide and conquer approach.
approach.

Size It is preferable for the small- It is preferable for the large-size data sets.
sized data sets.

Efficiency It is less efficient in the case of It is more efficient in the case of large-size
large-size data sets. data sets.

Worst-case In a linear search, the worst- In a binary search, the worst-case scenario for
scenario case scenario for finding the finding the element is O(log2n).
element is O(n).

Best-case In a linear search, the best-case In a binary search, the best-case scenario for
scenario scenario for finding the first finding the first element in the list is O(1).
element in the list is O(1).

2 .Comparative analysis of different sorting techniques.

3. Difference between external and internal sorting.


15
SN Internal Sorting External Sorting
O
1 The sorting process that takes place If the data being sorted do not fit into the
entirely within main memory of the main memory and they reside in slower
computer. external memory external sorting is done.
2 Data to be sorted is small enough to be Used to handle massive amounts of the
held in main memory data in external memory(Secondary
storage)
3 Does not make use of any external Make use of external resource
resource
4 Example : Insertion sort, Bubble sort, Example : Merge sort
Selection sort

4.List the factors while sorting of an elements.


 Computational complexity (bestcase,worstcase,average case)
 Memory utilization
 Stability
 No of comparisons
 Method applied like insertion, exchange, selection and merging etc.

5. Write the routine for insertion sort .


void insertion _sort(int a[],int n )
{
inti,j,temp;
for(i=0;i<n;i++)
{
temp=a[i];
for(i=0;j>0 && a[j-1]>temp;j--)
{
a[j]=a[j-1];
}
a[j]=temp;
}

16
}
6.Define Hashing.
Hashing is a technique of storing the elements directly at the specific location in the hash
table.The hashing makes use of hash function to place the record at its position. Using the
same hash function the data can be retrieved directly from the hash table.
7. What is meant by extendible hashing?
Extendible hashing is a technique which handle a large amount of data. The data to be
placed in hash table is by extracting certain number of bits. Extendible hashing grow and
shrink similar to B – trees.
8. What is rehashing?
Rehashing is a technique in which the table is resized.That means the ize of the table is
doubled by creating a new table .The total size of the table is usually a prime
number.Following are the situations in which the rehashing is required.
(i) When table is completely full
(ii) With quadratic probing, the table is filled half.
(iii) When insertions fail due to overflow.

9. List out the applications of hashing.


Hashing is used to obtaining the position of the desire record efficiently.
 In compilers to keep track of declared variables.
 For online spelling the hashing function is used
 Hashing help in game playing programs to store the move made by the player.
 In web browsing programs for caching the web pages hashing is used.
10. What is meant by collision resolution strategies?
If collision occurs then it should be handled by applying some techniques. Such a
technique is called collision handling technique.
1. Chaining
2. Open addressing
Two more difficult collision handling techniques are:
1. Quadratic probing
2. Double probing

17
PART B QUESTIONS
UNIT 1
1. Algorithm Analysis (16)
2. Mathematical notations and functions-Asymptotic notations(16)
3. Linear and Binary search - Bubble sort(8+8)
UNIT II
1. Single dimensional array-Insertion, deletion, find, find next, find previous(16)
2. Matrix addition & multiplication(16)
3. Doubly linked list insertion and deletion(8) & Circular linked list insertion and
deletion(8)
4. Stack insertion & Deletion(8) & Queue insertion & Deletion(8)
5. Towers of Honnai(8) & Circular queue insertion & Deletion(8)
6. Conversion Infix, Postfix, Prefix(16)
UNIT III

1. Tree traversal(8) & Expression tree conversion(8)


2. Binary Search tree Insertion and deletion(16)
3. AVL rotation and tree insertion(16)
4. Splay tree insertion and B-tree insertion and deletion(16)
5. Red black tree insertion(8) & heap insertion(8)

UNIT IV
1. Graph traversal(16)
2. Topological sort(16)
3. Prims algorithm(16)
4. Kruskals algorithm(16)
5. Dijkstra‟s algorithm(16)
UNIT V
1. Bubble sort(8) &Selection sort(8)
2. Insertion sort ( 8) &Quick sort(8)
3. Merge sort (8) &Shell sort (8)
4. Separate Chaining(8) & Open Addressing (8)
5. Rehashing(8) &Extendible Hashing.(8)

18

You might also like