You are on page 1of 17

NOORUL ISLAM COLLEGE OF ENGINEERING, KUMARACOIL

B.E. - ELECTRICAL AND ELECTRONICS ENGINEERING


THIRD SEMESTER
CS1211 — DATA STRUCTURES AND ALGORITHMS

1. What are the different data types in C?


• Integer
• Float
• Character

2. What is the difference between arrays and pointers?


Memory for arrays is statically allocated whereas storage for pointers is
dynamically allocated.

3. How is a structure passed to a function?


A structure is passed to a function by reference (i.e. its address is passed to the
function) and the structure is referred to by means of a pointer in the function.

4. What is meant by automatic variable?


In C variables and parameters declared within a function are known as automatic
variables. Such variables are allocated storage when the function is invoked.
When the function terminates storage assigned to these variables is deallocated.
Thus automatic variables exist only as long as the function is active. They are said
to be local to the function.

5. How is a two-dimensional array represented in memory?


• Row major representation
• Column major representation
• Pointer representation

6. Is *(++ptr) equivalent to ++(*ptr)? If no, why?


No. *(++ptr) represents the content of the next location to the location addressed
by ptr whereas ++(*ptr) represents incrementing the content of the location
addressed by ptr.

7. What will be the output of the following program segment?


void main()
{
int i;
static int x;
for(i=2;i!=x;i--)
printf(“%d\n”,i);
printf(“x = %d”,x);
}
2
1
x=0

8. Distinguish between iteration and recursive definition.


An algorithm that calls for the explicit repetition of some process until a certain
condition is met is called an iterative algorithm.
A definition which defines an objectin terms of a simpler case of itself is called a
recursive definition.

9. What is the difference between structure and union?


A structure may be regarded as a road map to an area of memory. It defines how
the memory is to be interpreted. A union provides several road maps to the same
area of memory and it is the responsibility of the programmer to determine which
road is in current use and this determines how that storage is to be interpreted.
Furthermore, the amount of memory specified by the structure is the sum of the
storage specified by each of its member types whereas the memory actually
allocated for the union is the maximum of the space needed by any single
member.

10. How is an array passed to a function?


An array variable in C is a pointer, array parameters are passed by reference, i.e.,
the base address of the array is passed. The parameter refers to the original array
that was allocated in the calling program.
(e.g.) float avg(float a[ ], int size)
{

}

11. What is meant by external variable?


Variables that are declared outside any function are called external variables.
They are allocated storage at the point at which they are first encountered and
remain in existence for the remainder of the program’s execution. Such variables
may be referred to by all functions in that source file lying beyond their
declaration and are therefore said to be global to those functions.

12. Is *(ptr+1) equivalent to *ptr+1. If no, why?


No. *(ptr+1) refers to the content of the location next to the one addressed by ptr
whereas *ptr+1 refers to 1 added to the content of the location addressed by ptr.

13. What are the two measures of efficiency?


Efficiency is usually measured by two factors: time and space. There is usually a
tradeoff between theswe two efficiencies, so that the implementation that is fast
uses more storage than one that is slow. The choice of implementation in such a
case involves a careful evaluation of the tradeoffs among the various possibilities.

14. Define Data Structures?


Data Structures is a way of organizing data that considers the data to stored and
their relationship with each other. It is representation of the logical relationship
between individual elements of data.

15. Explain the types of Data Structure?


1. PRIMITIVE
These are basic structures and are directly operated upon by the machine
instructions.
a. Integer
b. Float
c. Char
d. Pointer.
2. NON-PRIMITIVE
This type of data structure emphasize on structuring of a group of
homogeneous or heterogeneous data items.
a. Arrays
b. Lists
i. Linear Lists
a. Stack
b. Queue
ii. Non Linear List
a. Graph
b. Tree
c. Files

16. Define ADT (Abstract Data Type)?


An ADT is a mathematical model with a collection of operations defined on that
model. (or) An abstract data type is a data type that is defined in terms of the
information it can contain and the operations that can be performed with it. It is
the basic mathematical concept that defines the data type.

17. Define Linear data structure?


Linear data structures are data structures having a linear relationship between its
adjacent elements. Eg. Linked List.

18. Define Non Linear data structure?


Non Linear data structures are data structures don’t have a linear relationship
between its adjacent elements, but had the hierarchical relationship. Ex. Graph,
Tree.

19. What are different types of Linked List?


Single linked list
Double linked list
Circular linked list

20. What are different types of Circular Linked List?


Circular Single linked list
Circular double linked list

21. Define underflow.


The result of an illegal attempt to remove an element from an empty data structure
is called underflow.

22. Define stack or pushdown list.


Stack is an ordered collection of elements in which insertions and deletions are
restricted to one end. The end from which elements are added and /or removed is
referred to as top of the stack. Stacks are also referred as “piles” and “push-down
lists”.

23. What are the primitive operations made to a stack?


• push
• pop
• empty

24. Give some applications of stack.


a. Expression Parsing
b. Evaluation of Postfix
c. Balancing parenthesis
d. Tower of Hanoi
e. Reversing a string

25. Define Queue.


Queue is an ordered collection of elements in which insertions and deletions are
restricted to one end. The end from which elements are added and / or removed is
referred to as the rear end and the end from which deletions are made is referred
to as front end.

26. What are the primitive operations made to a queue?


• insert
• remove
• empty

27. Give some applications of queue.


 Image component Labeling
 Job Scheduling

28. What is lifo and fifo?


Lifo means last-in, first-out and fifo means first-in, first-out. Stack is a lifo list
and queue is a fifo list.

29. Define priority queue.


The priority queue is a data structure in which the intrinsic order of the elements
does determine the results of its basic operations.

30. What are the different types of priority queue?


There are 2 types of priority queue:
• Ascending priority queue
• Descending priority queue

31. Define ascending priority queue.


An ascending priority queue is a collection of items into which items can be
inserted arbitrarily and from which only the smallest element can be removed.

32. Define descending priority queue.


A descending priority queue is a collection of items into which items can be
inserted arbitrarily and from which only the largest element can be removed.

33. Difference between Arrays and Linked List?

Arrays Linked List


Size of any array is fixed Size of list is variable
It is necessary to specify the number of It is not necessary to specify the number of
elements during declaration elements during declaration
Insertion and deletions are difficult and Insertions and deletions are done in less
costly time
It occupies less memory than a linked list It occupies more memory
Coding is easy Careful coding is needed to avoid memory
errors.

34. Give the drawbacks of sequential storage of linked lists.


 A fixed number of storage remains allocated to the list even
when the structure is actually using a smaller amount or possibly
no storage at all.
 No more than that fixed amount of storage may be allocated, thus
introducing the possibility of overflow.
 If there are two stacks implemented as arrays of size 100 each.
Even if the first stack contains only 25 items, the second cannot
contain more than 100.
35. Define linear linked list.
The items in a stack or queue can be explicitly ordered, i.e., each item can contain
within itself the address of the next item. Such an explicit ordering gives rise to a data
structure known as a linear linked list. Each item in the list is called a node and
contains two fields, an information field and a next address field.

36. What is header node?


An extra node kept at he front of a list is called a header node or a list header.
Such a node does not represent an item in the list. The info portion of such a
header node might be unused or could be used to keep global information about
the entire list.

37. What is circular list?


If a small change is made to the structure of a linear list, so that the next field of
the last node contains a pointer to the first node rather than the null pointer, the
list is called a circular list.

38. Give the advantage of circular list.


In a circular list from any point in the list it is possible to reach any other point in
the list.

39. What are the drawbacks of circular linked lists?


One cannot traverse a list backward, nor can a node be deleted from a circularly
linked list, given only a pointer to that node.

40. What is doubly linked list?


Each node in a doubly linked list contains two pointers, one to its predecessor and
another to its successor. Doubly linked lists may be either circular or linear.

41. Define 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.

42. Define depth of a binary tree.


The level of a node in a binary tree is defined as follows: The root of the tree has
level 0, and the level of any other node in the tree is one more than the level of its
father. The depth of a binary tree is the maximum level of any leaf in the tree.

43. Give the algorithm for depth-first order traversal.


i) Visit the root
ii) Traverse the left subtree in preorder
iii) Traverse the right subtree in preorder

44. Give the algorithm for symmetric order traversal.


i) Traverse the left subtree in inorder
ii) Visit the root
iii) Traverse the right subtree in inorder

45. Give the algorithm for postorder traversal.


i) Traverse the left subtree in postorder
ii) Traverse the right subtree in postorder
iii) Visit the root

46. Define strictly binary tree.


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

47. Define complete binary tree.


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

48. Define almost complete binary tree.


A binary tree of depth d is an almost complete binary tree if:
i) Any node nd at level less than d-1 has two sons.
ii) For any node nd in the tree with a right descendent at level d, nd must have a
left son and every left descendent of nd is either a leaf at level d or has two sons.

49. Define binary search tree.


A binary tree that has the property that all elements in the left subtree of a node n
are less than the contents of n, and all elements in the right subtree of n are greater
than or equal to the contents of n.

50. List some representations of binary trees.


i) Node representation of binary trees
ii) Implicit array representation of binary trees

51. Define right in-threaded binary tree.


A left in-threaded binary tree is one in which each NULL left pointer of nodes are
altered to contain a thread to that node’s inorder successor.

52. Define left in-threaded binary tree.


A left in-threaded binary tree is one in which each NULL left pointer of nodes are
altered to contain a thread to that node’s inorder predecessor.

53. Define in-threaded binary tree.


An in-threaded binary tree may be defined as a binary tree that is both left in-
threaded and right in-threaded.

54. Define right and left pre-threaded binary trees.


Right and left pre-threaded binary trees are binary trees in which NULL right and
left pointers of nodes are replaced by their preorder successors and predecessors
respectively.

55. How are lists represented using binary trees?


A list may be represented as a binary tree in such a way that the elements of the
original list are represented by leaves af the tree, whereas nonleaf nodes of the
tree are present as part of the internal tree structure. Associated with each leaf
node are the contents of the corresponding list element. Associated with each
nonleaf node is a count representing the no. of leaves in the node’s left subtree.
The elements of the list in their original sequence are assigned to the leaves of the
tree in the inorder sequence of the leaves.

56. Define tree.


A tree is a finite nonempty set in which one element is called the root and the
remaining elements are partitioned into m>=0 disjoint subsets, each of which is
itself a tree. Each element in a tree is called a node of the tree.

57. Define ordered tree.


An ordered tree is defined as a tree in which the subtrees of each node form an
ordered set.

58. Define forest.


Collection of sub trees that are obtained when root node is eliminated is known
as forest.

59. Give the algorithm for preorder traversal of trees.


i) Visit the root of the first tree in the forest.
ii) Traverse in preorder the forest formed by the subtrees
of the first tree.
iii) Traverse in preorder the forest formed by the remaining
trees in the forest, if any.

60. Give the algorithm for inorder traversal of trees.


i) Traverse in inorder the forest formed by the subtrees of
the first tree in the forest, if any.
ii) Visit the root of the first tree in the forest.
iii) Traverse in inorder the forest formed by the remaining
trees in the forest, if any.

61. Give the algorithm for preorder traversal of trees.


i) Traverse in postorder the forest formed by the subtrees
of the first tree in the forest, if any.
ii) Traverse in postorder the forest formed by the
remaining trees in the forest, if any.
iii) Visit the root of the first tree in the forest.

62. What is Complexity analysis?


It is the analysis of the amount of memory and time an algorithm requires to
completion.
There are two types of Complexity
Space Complexity and Time Complexity

63. Explain Space complexity?


Space complexity of an algorithm is the amount of memory it needs to run to
completion.
64. Explain Time complexity?
Time complexity is the amount of computer time an algorithm requires to run to
completion.

65. Define Efficiency of an algorithm?


It denotes the rate at which an algorithm solves a problem of size n. It is measured
by the amount of resources it uses, the time and the space.

66. Define Worst case of an algorithm?


It is the longest time that an algorithm will use over all instances of size n for a
given problem to produce the result.

67. Define Best case of an algorithm?


It is the shortest time that an algorithm will use over all instances of size n for a
given problem to produce the result.

68. Define average case an algorithm?


It is the average time that an algorithm will use over all instances of size n for a
given problem to produce the result.

What are the two categories of sort?


• Internal sort
• External sort

69. What is internal sort?


If the records that it is sorting are in main memory the sort is called internal sort.

70. What is external sort?


If some of the records that it is sorting are in auxiliary storage the sort is called an
external sort

71. Give examples for external sorts.


• Tag Sorts
• Four Tape Sort
• Polyphase Sort
• External Radix Sort
• External Merge.

72. Define stable sort.


A sort algorithm is said to be “stable” if multiple items which compare as equal
will stay in the same order they were in after a sort.

73. What is in-place sort?


An in-place sort manipulates the elements to be sorted within the array or list
space that contained the original unsorted input. Additional space that is required
is in the form of a constant no. of locations regardless of the size of the set to be
sorted. Additional space requirements are O(1).

74. What is selection sort?


The selection sort algorithms constructs the sorted sequence one element at a time
by adding elements to the sorted sequence in order. At each step, the next element
to be added to the sorted sequence is selected from the remaining elements.

75. Define search algorithm.


A search algorithm is an algorithm that accepts an argument a and tries to find a
record whose key is a. The algorithm may return the entire record or it may return
a pointer to the record.

76. Compare selection sort and insertion sort.


The selection sort algorithms constructs the sorted sequence one element at a time
by adding elements to the sorted sequence in order. At each step, the next element
to be added to the sorted sequence is selected from the remaining elements.
Because the elements are added to the sorted sequence in order, they are always
added at one end. This is what makes selection sorting different from insertion
sorting. In insertion sorting elements are added to the sorted sequence in an
arbitrary order. Therefore, the position in the sorted sequence at which each
subsequent element is inserted is arbitrary.
Both selection and insertion sorts sort the arrays in place.

77. List the pros and cons of selection sort.


Pros: Simple and easy to implement.
Cons: Inefficient for large lists, so similar to the more efficient insertion sort that
the insertion sort should be used in its place.

78. List the advantages and disadvantages of insertion sort.


Advantage: Relatively simple and easy to implement.
Disadvantage: Inefficient for large lists.

79. Give the merits and demerits of bubble sort.


Merit: Simple and easy to implement.
Demerit: Horribly inefficient.

80. Give the merits and demerits of quick sort.


Merit: Extremely fast.
Demerit: Very complex algorithm, massively recursive.

81. Give the merits and demerits of heap sort.


Merit: In-place and non-recursive, making it a good choice for extremely large
data sets.
Demerit: Slower than the merge and quick sorts.

82. Define graph.


A graph consists of a set of nodes (or vertices) and a set of arcs (or edges). Each
arc in a graph is specified by a set of nodes.

83. Define digraph.


If the pairs of nodes that make up the arcs are ordered pairs, the graph is said to be
a directed graph (or digraph)

84. Define degree.


The degree of a node is the number of arcs incident to it.

85. Define adjacent node.


A node n is adjacent to a node m if there is an arc from m to n. If n is adjacent to
m, n is called a successor of m, and m a predecessor of n.

86. Define indegree.


The indegree of a node n is the no. of arcs that have n as the head.

87. Define outdegree.


The outdegree of a node n is the no. of nodes that have n as the tail.

88. Define relation.


A set R on a set A is a set of ordered pairs of elements of A.

89. Define weighted graph.


A graph in which a number is associated with each arc is called a weighted graph
or network.

90. Define path.


A path of length k from node a to b is defined as a sequence of k+1 nodes n1,n2, . .
. . nk+1 such that n1=a, nk+1=b and adjacent(ni,ni+1) is true for all I between 1 and k.

91. Define dag.


A pathfrom a node to itself is called a cycle. If a graph contains a cycle it is
cyclic; otherwise it is acyclic. A directed acyclic graph is called a dag.

92. Define adjacency matrix.


Adjacency matrix, represented by adj is used to totally describe a graph which has
no information associated with the nodes and arcs. Adj[i][j] is TRUE or FALSE
depending on whether or not node j is adjacent to node i.

93. Define transitive closure.


The path matrix is also called transitive closure of the adjacency matrix. Path[i][j]
is TRUE or FALSE depending on whether or not a path exists from node i to node
j.

94. What are the conditions for pathk+1[i][j] to be true according to Warshall’s law?
pathk+1[i][j] is true if and only if one of the following two conditions holds:
 pathk[i][j] == TRUE
 pathk[i][k+1] == TRUE && pathk+1[k+1][j] == TRUE

95. What are the types of nodes in adjacency list representation of graphs?
 Header nodes
 List nodes or arc nodes

96. Define adjacency list.


In adjacency list representation of graphs a header node is used to represent each
graph node. Each header node is at the head of a list of nodes of a second type
called list nodes. This list is called the adjacency list. Each node on an adjacency
list represents an arc of a graph.

97. Define traversal.


Traversing a data structure means to visit each of its elements in a systematic
manner.

98. Why is graph traversal complex?


 No natural starting node to start traversal.
 All the nodes may not be reachable from the selected stating node.
 There is no natural order among the successors of a node.
 A node may have more than one predecessor.

99. Define tree edges.


Tree edges are arcs of the graph that are included in the spanning forest.

100. Define forward edges.


Forward edges are arcs of the graph from a node to a spanning forest nonson
descendent.

101. Define cross edges.


A cross edge is an arc from one node to another node that is not the first son’s
descendent or ancestor in the spanning forest.

102. Define back edges.


Back edges are arcs from a node to a spanning forest ancestor.

103. What are the two types of traversal applied to directed graphs?
• Depth first traversal
• Breadth first traversal
104. List some algorithms used to find the shortest path.
• Dijikstra’s Algorithm
• Warshall’s algorithm

105. Define minimum spanning tree.


A spanning tree for which the sum of weights of the arcs is minimum is called
minimum spanning tree.

106. List some algorithms to construct minimum spanning tree.


• Prim’s algorithm
• Kruskal’s algorithm
• Round robin algorithm
NOORUL ISLAM COLLEGE OF ENGINEERING, KUMARACOIL
B.E. - ELECTRICAL AND ELECTRONICS ENGINEERING
THIRD SEMESTER
CS1211 — DATA STRUCTURES AND ALGORITHMS

107. Compare the implementations of structure and union with example.


• Comparison
• Structure example
• Union example

108. Write a C program to find the factorial of a number using recursion and
explain its execution in detail.
• Program
• Recursion definition
 Explanation with stack

109. Explain the concept of pointers in C.


• Pointer definition with example
• Importance of base type
• and & operators
• Call by value and call by reference

110. Compare iterative algorithm and recursive definition with the following
examples: (i) Factorial (ii) Fibonacci sequence
(i) Factorial
• iterative algorithm with explanation
• recursive definition with explanation
(ii) Fibonacci sequence
• iterative algorithm with explanation
• recursive definition with explanation

111. Write a C program to implement matrix addition and multiplication.


• main program
• matrix addition fn.
• multiplication

112. Illustrate the differences between call-by-value and call-by-reference with


the help of a typical example.
• call-by-value
• example
• call-by-reference
• example

113. Explain the operations performed on singly linked lists.


• Insertion
• Deletion
• Traversal
• Search

114. i) Explain the array implementation of priority queues


ii) Explain the list implementation of priority queues
i)Array implementation
• pqinsert
• pqmindelete
• problem and solutions
ii)List implementation
• as ordered list
• as unordered list

115. What are circular lists? Explain how stacks and queues are represented
using circular list.
• Definition
• Advantage
• Linked implementation of stacks

• Linked implementation of queues

116. Explain the C implementation of queues.


• Definition
• Linear queue, its disadvantage
• Circular queue

117. What are doubly linked lists? Explain the addition of long integers using
doubly linked lists.
• Definition
• Advantage
• Description of addition
• Algorithm
• Example

118. Explain binary tree traversals.


• Traversal definition
• Preorder traversal
• Inorder traversal
• Postorder traversal

119. Explain threaded binary trees in detail.


• Drawback of binary trees
• Thread definition
• Left in-threaded binary tree
• Right in-threaded binary tree
• In-threaded binary tree
• Right and left pre-threaded binary tree
• Inorder traversal

120. Explain tree traversals.


• Traversal definition
• Preorder traversal
• Inorder traversal
• Postorder traversal

121. Explain binary tree representations.


• Node representation
• Implicit array representation

122. Explain radix sort with example.


• Radix sort definition
• Radix exchange sort description
• Radix sort description
• Radix sort algorithm
• Example

123. Explain Quicksort with an example


• Description
• Algorithm
• Description with example
• Efficiency

124. Explain Binary search with example.


• Description
• Algorithm
• Description with example
• Efficiency

125. Explain heapsort with example.


• Description
• Algorithm
• Description with example
• Efficiency

126. Explain Bubble sort with example.


• Description
• Algorithm
• Description with example
• Efficiency

127. Explain Interpolation search with example.


• Description
• Algorithm
• Description with example
• Efficiency

128. Explain Warshall’s algorithm


• General description
• Conditions for pathk+1[i][j] to be true
• Algorithm
• Description
• Efficiency

129. Explain Depth first traversal of graphs.


• Definition
• Algorithm
• Description
• Example
• Efficiency
• Applications

130. Explain shortest path algorithm


• Description
• Algorithm
• Description with example
• Efficiency

131. Explain Breadth first traversal of graphs.


• Definition
• Algorithm
• Description
• Example
• Efficiency
• Applications

132. Explain Prim’s algorithm.


• Description
• Algorithm
• Description with example
• Efficiency

133. Explain Kruskal’s algorithm.


• Description
• Algorithm
• Description with example
• Efficiency

134. Explain round robin algorithm.


• Description
• Algorithm
• Description with example
• Efficiency

You might also like