### Data structure and algorithum third semester part A and part B questions

DATA STRUCTURES AND ALGORITHMS

UNIT-I - INTRODUCTION TO DATASTRUCTURES

PART -A

1.Write down the definition of data structures?

A data structure is a mathematical or logical way of organizing data in the memory that
consider not only the items stored but also the relationship to each other and also it is
characterized by accessing functions.

2. Give few examples for data structures?

Stacks, Queue, Linked list, Trees, graphs

3. Define Algorithm?

Algorithm is a solution to a problem independent of programming language. It consist of
set of finite steps which, when carried out for a given set of inputs, produce the corresponding
output and terminate in a finite time.

4. What are the features of an efficient algorithm?

Free of ambiguity
Efficient in execution time
Concise and compact
Completeness
Definiteness
Finiteness

5. List down any four applications of data structures?

Compiler design

Operating System
Database Management system
Network analysis

6. What is meant by an abstract data type(ADT)?

An ADT is a set of operation.A useful tool for specifying the logical properties of a
datatype is the abstract data type.ADT refers to the  basic mathematical concept that defines the
datatype. Eg.Objects such as list, set and graph along their operations can be viewed as ADT's.

7.What are the operations of ADT?

Union, Intersection, size, complement and find are the various operations of ADT.

8.What is meant by list ADT?

List ADT is a sequential storage structure. General list of the form a
1
, a
2
, a
and the
size of the list is 'n'. Any element in the list at the position I is defined to be a
the successor
of a
i
and a
i-1
is the predecessor of a
.

9. What are the various operations done under list ADT?

Print list
Insert
Make empty
Remove
Next
Previous
Find k
th

10.What is a Rational number?

i

A Rational number is a number that can be expressed as the quotient of two integers.
Operations on Rational number:

Creation of rational number from two integers.

Multiplication

Testing for equality.

11.What are the two parts of ADT?

Value definition

Operator definition
12.What is a Sequence?

A sequence is  simply an ordered set of elements.A sequence S is sometimes written as the
enumeration of its elements,such as
S = <s
0
,s
1
,………..s
>
If S contains n elements,then length of S is n.

13.Define len(S),first(S),last(S),nilseq ?

len(S)  is the length of the sequence S.
first(S) returns the value of the first element of S
n-1

last(S) returns the value of the last element of S
i
3
, ai
.…., a
+1
n
nilseq  :Sequence of length 0 is nilseq  .ie., contains no element.

14.What are the four basic data types?

int,float,char and double

15.What are the two things specified in declaration of variables in C?

It specifies the amount of storage  that  must be set aside for objects  declared with
that type.

How data represented by strings of bits are to be interpreted.

16. What is a pointer?

Pointer is a variable, which stores the address of the next element in the list. Pointer is
basically a number.

17.What is an array ?

Array may be defined abstractly as a finite ordered set of homogenous elements.Finite means
there is a specific number of elements in the array.

18.What are the two basic operations that access an array?

Extraction:
Extraction operation  is a function that accepts an array, a ,an index,i,and
returns an element of the array.
Storing:
Storing operation accepts an array , a ,an index i , and an element x.

19.Define Structure?

A Structure is a group of items in which each item is identified by its own identifier ,each of
which is known as a member of the structure.

20.Define Union ?

Union is collection of Structures ,which permits a variable to be interpreted in several different
ways.

21.Define Automatic and External variables?

Automatic variables are variables that are allocated storage when the function is invoked.
External variables are variables that are declared outside any function and are allocated storage
at the point at which they are first encountered for the remeinder of the program's execution.

22.Define Recursion?

Recursion is a function calling itself again and again.

23.What is a Fibonacci sequence?
Fibonacci sequence is the number of integers
0,1,1,2,3,5,8,13,21,34,……….
Each element in this sequence is the sum of the two preceding elements.

PART - B

1.What is an Abstract Data type(ADT)? Explain?

2.Define Structure?Explain in detail?

Definition of Structure

Various forms of declarations of structure

Implementing Structure

3.What is Union?Explain?

Definition of Union

Example

Implementation of Union

4.Define Recursion?Explain Fibonacci sequence?

Definition of Recursion

Fibonacci sequence definition

Example

Explain allocation of storage variables and scope of variables?

Allocation of variables

Two types of variables: Automatic and External variables

Example
UNIT II - STACK,QUEUE AND LINKED LIST

PART - A

1.What is a 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.

The other name of stack is
Last-in -First-out list.

2.What are the two operations of Stack?

PUSH

POP

3. Write postfix from of the expression –A+B-C+D?

A-B+C-D+

4.What is a Queue ?

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 tems may be inserted at the other end called rear of the
queue.Queue is called as First –in-First-Out(FIFO).

5.What is a Priority Queue?

Priority queue is a data structure in which the intrinsic ordering of the elements does determine
the results of its basic operations.Ascending and Descending priority queue are the two types of
Priority queue.

6.What are the different ways to implement list?

Simple array implementation of list

7. What are the advantages in the array implementation of list?

a) Print list operation can be carried out at the linear time
b) Find K
th
operation takes a constant time

8. What is a linked list?

Linked list is a kind of series of data structures, which are not necessarily adjacent in memory.
Each structure contain the element and a pointer to a record containing its successor.

9.Name the two fields of Linked list?

Info field

Next field
10. What is a doubly linked list?

In a simple linked list, there will be one pointer named as 'NEXT POINTER' to point the next
element, where as in a doubly linked list, there will be two pointers one to point the next
element and the other to point the previous element location.

11.Name the three fields of Doubly Linked list?

Info field

Left field

Right field

12. Define double circularly linked list?

In a doubly linked list, if the last node or pointer of the list, point to the first element of the list,
then it is a circularly linked list.

13. What is the need for the header?

Header of the linked list is the first element in the list and it stores the number of elements in the
list. It points to the first data element of the list.

14. List three examples that uses linked list
?

Multi lists

15. Give some examples for linear data structures?

Stack
Queue

16. Write postfix from of the expression –A+B-C+D?

A-B+C-D

17. How do you test for an empty queue?

To test for an empty queue, we have to check whether READ=HEAD where REAR is a pointer
pointing to the last node in a queue and HEAD is a pointer that pointer to the dummy header. In
the case of array implementation of queue, the condition to be checked for an empty queue is

18.What are the postfix and prefix forms of the expression?

A+B*(C-D)/(P-R)
Postfix form: ABCD-*PR-/+
Prefix form: +A/*B-CD-PR

19. Explain the usage of stack in recursive algorithm implementation?

In recursive algorithms, stack data structures is used to store the return address when a recursive
call is encountered and also to store the values of all the parameters essential to the current state
of the procedure.

20. Write down the operations that can be done with queue data structure?

Queue is a first - in -first out list. The operations that can be done with queue are insert and
remove.

22. What is a circular queue?

The queue, which wraps around upon reaching the end of the array is called as circular queue.

PART – B

1.What is a Stack?Explain with example?

Definition of Stack

Operations of Stack:PUSH and POP

Example

2.Write the algorithm for converting infix expression to postfix expression?

Definition of Expression

Types  of expression

Algorithm for infix to postfix expression

Example

3.What is a Queue?Explain its operation with example?

Definition of Queue

Operations of Queue:insert and remove

Example

4.What is a Priority Queue?What are its types?Explain?

Definition of Priority queue

Types:Ascending and Descending priority queue

Array Implementation of  priority queue

5.Write an algorithm for inserting and deleting  an element  from Doubly linked list?Explain
llinear linked implementation of Stack and Queue?

Operations:insertion and deletion with algorithm

UNIT-III - TREES

PART- A

1. Define non-linear data structure?

Data structure which is capable of expressing more complex relationship than that of physical
adjacency is called non-linear data structure.

2. Define tree?

A tree is a data structure, which represents hierarchical relationship between individual data
items.

3. Define leaf?

In a directed tree any node which has out degree o is called a terminal node or a leaf.

4. What is meant by directed tree?

Directed tree is an acyclic diagraph which has one node called its root with indegree o whille all
other nodes have indegree I.

5. What is a ordered tree?

In a directed tree if the ordering of the nodes at each level is prescribed then such a tree is called
ordered tree.

6.What is a Binary tree?

A Binary tree is a finite set of elements that is either empty or is partitioned into three disjoint
subsets.The first subset contains a single element called the root of the tree.The other two
subsets are themselves binary trees called the left and right subtrees.

7. What are the applications of binary tree?

Binary tree is used in data processing.

a. File index schemes
b. Hierarchical database management system

8. What is meant by traversing?

Traversing a tree means processing it in such a way, that each node is visited only once.

9. What are the different types of traversing?

The different types of traversing are
a. Pre-order traversal-yields prefix from of expression.
b. In-order traversal-yields infix form of expression.
c. Post-order traversal-yields postfix from of expression.

10. What are the two methods of binary tree implementation?

Two methods to implement a binary tree are,
a. Linear representation.

11. Define pre-order traversal?

Pre-order traversal entails the following steps;
a. Visit the root node
b. Traverse the left subtree
c. Traverse the right subtree

12.Define post-order traversal?

Post order traversal entails the following steps;
a. Traverse the left subtree
b. Traverse the right subtree
c. Visit the root node

13. Define in -order traversal?

In-order traversal entails the following steps;
a. Traverse the left subtree
b. Visit the root node
c. Traverse the right subtree

14. What is the length of the path in a tree?

The length of the path is the number of edges on the path. In a tree there is exactly one path
form the root to each node.

15. Define expression trees?

The leaves of an expression tree are operands such as constants or variable names and the
other nodes contain operators.

16.Define Strictly binary tree?

If every nonleaf node in a binary tree has nonempty left and right subtrees ,the tree is termed
as a strictly binary tree.

17.Define complete binary tree?

A complete binary tree of depth d is the strictly  binary tree all of whose are at level d.

18.What is an almost complete binary tree?

A binary tree of depth d is an almost complete binary tree if :

Each leaf in the tree is either at level d or at level d-1

For any node nd in the tree with a right descendant at level d,all the left descendants of
nd that are leaves are at level d.

Right –in –threaded binary tree is defined as one in which threads replace NULL pointers in
nodes with empty right subtrees.

20.Define left – in –threaded tree?
A left-in-threaded  binary tree may be defined as one in which each NULL pointers is altered to
contain a thread to that node's inorder predecessor.

PART- B

1.What is a Binary tree?Explain Binary tree traversals in C?

Definition of Binary tree

Traversals

Inorder traversal

Preorder traversal

Postorder traversal

2.Explain Representing lists as Binary tree?Write algorithm for finding K
th
element and deleting
an element?

Representing list as Binary tree

Finding K
th
element

Deleting an element

3.Write a program to find duplicate numbers in an input list which includes the routines
maketree and setleft?

Program to find duplicate numbers in an input list

Routines maketree

Routines setleft

4.Explain Threaded binary tree with its type?

5.Explain Binary tree representation?

Node representation of Binary tree

Internal and external nodes

Implicit array representation of Binary tree
UNIT-IV - SORTINGAND SEARCHING

PART - A

1.What is meant by sorting?

Ordering the data in an increasing or decreasing fashion according to some relationship among
the data item is called sorting.

2. What are the two main classifications of sorting based on the source of data?

a. Internal sorting
b. External sorting

3. What is meant by external sorting?

External sorting is a process of sorting in which large blocks of data stored in storage devices
are moved to the main memory and then sorted.

4. What is meant by internal sorting?

Internal sorting is a process of sorting the data in the main memory.

5. What are the various factors to be considered in deciding a sorting algorithm?

a. Programming time
b. Execution time of the program
c. Memory needed for program environment

6.What is the main idea in Bubble sort?

The basic idea underlying the bubble sort is to pass through the file sequentially several
times.Each pass consists of comparing each element in the file with its successor (x[i] and
x[i+1] and interchanging the two elements if they are not in proper order.

7.
What is the main idea behind insertion sort?

The main idea of insertion sort is to insert in the ith pass the ith element in A (1)
A (2)...A (i) in its rightful place.

8.
What is the main idea behind selection sort?

The main idea behind the selection sort is to find the smallest element among in A (I) A
(J+1)...A (n) and then interchange it with a (J). This process is then repeated for each value of J.

9. What is the basic idea of shell sort?

Instead of sorting the entire array at once, it is first divide the array into smaller segments,
which are then separately sorted using the insertion sort.

10. What is the other name for shell sort?

Diminishing increment sort.

11. What is the purpose of quick sort?

The purpose of the quick sort is to move a data item in the correct direction, just enough for to
reach its final place in the array.

12. What i the advantage of quick sort?

Quick sort reduces unnecessary swaps and moves an item to a greater distance, in one move.

13. What is the average efficiency of heap sort?

The average efficiency of heap sort is 0 (n(log2 n)) where, n is the number of elements sorted.

14. Define segment?

When large blocks of data are to be sorted, only a portion of the block or file is loaded in the
main memory of the computer since, it cannot hold the entire block.
This small portion of file is called a segment.

15. Name some of the external sorting methods?

a. Polyphase merging
b. Oscillation sorting
c. Merge sorting
16. When is a sorting method said to be stable?

A sorting method is said to be stable, it two data items of matching values are guaranteed to be
not rearranged with respect to each other as the algorithm progresses.

17. Name some simple algorithms used in external sorting?

a.
Multiway merge

b. Polyphase merge
c. Replacement selection

18. When can we use insertion sort?

Insertion sort is useful only for small files or very nearly sorted files.

19. How many passes are required fork-way merging?

The number of passes required using k-way merging is [log k (n/m)] because the N H S get k
times as large in each pass.

20. Define max heap?

A heap in which the parent has a larger key than the child's is called a max heap.

21. Define min heap?

A heap in which the parent has a smaller key than the child is called a min heap.

22.What is the idea behind Address calculation sort ?

This sorting is also called Hashing.In this method  a function f is applied to each key.The result
of the function determines into which of several subfiles  the record is to be placed.The function
should have the property that if x<=y ,f(x)<=f(y).Such a function is called order preserving.

PART - B

1.Explain Exchange sorts with example?

Bubble sort with example

Efficiency of Bubble sort

Quick sort with example

Efficiency of Quick sort

2.Explain Selection and tree sorting with example?

Selection sort

Straight selection sort

Binart tree sort

3.Explain Heap sort?

Heap sort

Heap as a priority queue

Sorting using a heap

Heap sort procedure

4.Explain Insertion sort with example?

Simple insertion

Shell sort

5.Explain merge and radix sort with example?

Merge sort with example

UNIT-V - GRAPHS

PART - A

1
.Define Graph?

A graph G consist of a nonempty set V which is a set of nodes of the graph, a set E which is the
set of edges of the graph, and a mapping from the set for edge E to a set of pairs of elements of
V. It can also be represented as G=(V, E).

Any two nodes which are connected by an edge in a graph are called adjacent nodes. For
example, if and edge x

E is associated with a pair of nodes (u,v) where u, v

V, then we say
that the edge x connects the nodes u and v.

3. What is a directed graph?

A graph in which every edge is directed is called a directed graph.

4. What is a undirected graph?

A graph in which every edge is undirected is called a directed graph.

5. What is a loop?

An edge of a graph which connects to itself is called a loop or sling.

6.What is a simple graph?

A simple graph is a graph, which has not more than one edge between a pair of nodes than such
a graph is called a simple graph.

7. What is a weighted graph?

A graph in which weights are assigned to every edge is called a weighted graph.

8. Define out degree of a graph?

In a directed graph, for any node v, the number of edges which have v as their initial node is
called the out degree of the node v.

9. Define indegree of a graph?

In a directed graph, for any node v, the number of edges which have v as their terminal node is
called the indegree of the node v.

10. Define path in a graph?

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

11.What is a simple path?

A path in a diagram in which the edges are distinct is called a simple path. It is also called as
edge simple.

12. What is a cycle or a circuit?

A path which originates and ends in the same node is called a cycle or circuit.

13. What is an acyclic graph?

A simple diagram which does not have any cycles is called an acyclic graph.

14. What is meant by strongly connected in a graph?

An undirected graph is connected, if there is a path from every vertex to every other vertex. A
directed graph with this property is called strongly connected.

15. When is a graph said to be weakly connected?

When a directed graph is not strongly connected but the underlying graph is connected, then the
graph is said to be weakly connected.

16. Name the different ways of representing a graph?

17. What is an undirected acyclic graph?

When every edge in an acyclic graph is undirected, it is called an undirected acyclic graph. It is
also called as undirected forest.

18. What are the two traversal strategies used in traversing a graph?

b. Depth first search

19. What is a minimum spanning tree?

A minimum spanning tree of an undirected graph G is a tree formed from graph edges that
connects all the vertices of G at the lowest total cost.

20.What is a forest ?

A forest  may be defined as an acyclic graph  in which every  node has one or no predecessors.A
tree may be defined as a forest in which only a single node called root  has no predecessors.

PART - B

1.Explain Shortest path algorithm with example?

Shortest path algorithm
Example

2.Explain Depth first and breadth first traversal?

Depth first traversal
Effieciency of Depth first traversal

3.Explain spanning and minimum spanning tree?

Spanning tree
Minimum spanning tree

4.Explain Kruskal's and Round robin algorithm?

Kruskal's algorithm
Round robin algorithm

5.Explain C Representation of graph?