Dsa Two Mark Questions

6
Data Structures and Algorithms Department of Computer Science and Engineering Muneeswaran V Page 1 Data Structure and Algorithms – Two Mark Questions and Answers UNIT - I 1. Define Algorithm Algorithm is a solution to a problem independent of programming language. It consist of set of unambiguous finite steps which, when carried out for a given set of inputs, produce the corresponding output and terminate in a finite time. 2. Define Program Set of instructions to find the solution to a problem. It is expressed in a programming language in an explicit and unambiguous manner 3. What are the features of an efficient algorithm? Free of ambiguity Efficient in execution time Concise and compact Completeness Definiteness Finiteness 4. Define Data Structures. Data Structure us a way of storing data in a computer, so that it can be used efficiently. 5. Define ADT. An ADT is a specification of a set of data and the set of operations that can be performed on the data. Such a data type is abstract in the sense that it is independent of various concrete implementations. The definition can be mathematical or it can be programmed as a interface. Ex. Complex numbers, list, stack, queue, map, multi list, priority queue, set, string and tree. 6. List the operation performed by the data structure. Create and destroy the data structure Insert element into the data structure Delete elements from the data structure Access elements in the data structure. 7. What are the different types of data structures? Linear data structure and Non Linear data structure. 8. Give some examples for linear data structures? List, Stack and Queue 9. List down the applications of data structures? Compiler design Operating System Database Management system 10. Define List General list of the form a1, a2, a3… an and the size of the list is ‘n’. Any element in the list at the position i is defined to be ai, ai+1 the successor of ai and ai-1 is the predecessor of ai. 11. What are the various operations done under list ADT? Print list Insert Delete Find Previous Find kth Find Make empty IsLast IsEmpty 12. What are the different ways to implement list?

Transcript of Dsa Two Mark Questions

Page 1: Dsa Two Mark Questions

Data Structures and Algorithms  

Department of Computer Science and Engineering                                      Muneeswaran V  Page 1  

Data Structure and Algorithms – Two Mark Questions and Answers UNIT - I 1. Define Algorithm Algorithm is a solution to a problem independent of programming language. It consist of set of

unambiguous finite steps which, when carried out for a given set of inputs, produce the corresponding output and terminate in a finite time.

2. Define Program Set of instructions to find the solution to a problem. It is expressed in a programming language

in an explicit and unambiguous manner 3. What are the features of an efficient algorithm?

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

4. Define Data Structures. Data Structure us a way of storing data in a computer, so that it can be used efficiently.

5. Define ADT. An ADT is a specification of a set of data and the set of operations that can be performed on

the data. Such a data type is abstract in the sense that it is independent of various concrete implementations. The definition can be mathematical or it can be programmed as a interface. Ex. Complex numbers, list, stack, queue, map, multi list, priority queue, set, string and tree.

6. List the operation performed by the data structure. • Create and destroy the data structure

• Insert element into the data structure • Delete elements from the data structure • Access elements in the data structure.

7. What are the different types of data structures? Linear data structure and Non Linear data structure.

8. Give some examples for linear data structures? List, Stack and Queue

9. List down the applications of data structures? • Compiler design

• Operating System • Database Management system

10. Define List General list of the form a1, a2, a3… an and the size of the list is ‘n’. Any element in the list at the

position i is defined to be ai, ai+1 the successor of ai and ai-1 is the predecessor of ai. 11. What are the various operations done under list ADT?

• Print list • Insert • Delete • Find Previous • Find kth

• Find • Make empty • IsLast • IsEmpty

12. What are the different ways to implement list?

Page 2: Dsa Two Mark Questions

Data Structures and Algorithms  

Department of Computer Science and Engineering                                      Muneeswaran V  Page 2  

• Array implementation of list • Linked list implementation of list • cursor implementation of list

13. What are the disadvantages in the array implementation of list? The running time for insertions and deletions is so slow because of unnecessary movement of

elements and the list size must be known in advance i.e., we cannot increase the size of the list. Can’t delete an element permanently.

14. When cursor implementation of list is used? If the linked lists are required and pointers are not available then cursor implementation of list is

used. 15. What is a pointer?

Pointer is a variable, which stores the address of another variable. 16. Define node.

A simple node consists of two fields namely an information field called DATA and a pointer field called LINK. The DATA field is used to store the data and the LINK field is used to store the address of the next node.

17. What is a linked list? Linked list is series of nodes, which are not necessarily adjacent in memory. Each node contains

the element and a pointer to the next node. 18. 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.

19. Define circularly linked list? In a Singly linked list, if the last node points to the first element of the list, then it is a circularly

linked list. 20. Define double circularly linked list?

In a doubly linked list, if the last node forward link points to the first element of the list, and the first node back link points to the last node of the list, then it is double circularly linked list.

21. List three examples that uses linked list? • Polynomial ADT

• Radix sort • Multi lists

22. Define Stack. A Stack is an ordered list in which all insertions and deletion are made at one end, called the

top. In a stack S = (a1, a2, ,…an), a1 is the bottom most element and element ai is on top of element ai-1. Stack is also referred as Last In First Out (LIFO) list or First In Last Out (FILO) list. The operations of the stack are Push and Pop. Push adds an element to one end of the stack. Pop deletes an element from the same end of the stack

23. What are the various Operations performed on the Stack? The various operations that are performed on the stack are

• CREATE(S) – Creates S as an empty stack. • PUSH(S, X) – Adds the element X to the top of the stack. • POP(S) – Deletes the top most element from the stack. • TOP(S) – returns the value of top most element from the stack. • ISEMTPTY(S) – returns true if Stack is empty else false. • ISFULL(S) – returns true if Stack is full else false

24. List the Applications of Stack

Page 3: Dsa Two Mark Questions

Data Structures and Algorithms  

Department of Computer Science and Engineering                                      Muneeswaran V  Page 3  

• Reversing data • Parsing (Checking for balanced parenthesis) • Postponement (Convert infix to postfix and prefix, evaluate a postfix and prefix

expression) • Backtracking (Function calls)

25. 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.

26. Define Queues. A Queue is an ordered list in which all insertions take place at one end called the rear, and all

deletions take place at the other end called the front. Queue is also referred as First In First Out (FIFO) list or Last In Last Out (LILO) list. The operations of queue are enqueue and dequeue. Enqueue adds an element in rear end. Dequeue deletes an element from the front end.

27. What are the various operations performed on the Queue? The various operations that are performed on the queue are

• CREATE(Q) – Creates S as an empty Queue. • Enqueue(Q,X) – Adds the element X to the Queue. • Dequeue(Q) – Deletes a element from the Queue. • ISEMTPTY(Q) – returns true if Queue is empty else false. • ISFULL(Q) – returns true if Queue is full else false.

28. Define Dqueue. Double ended Queue. It is a linear list in which insertions and deletion are made from either

end of the Queue. 29. List down any four applications of data structures?

• Compiler design • Operating System • Database Management system • Network analysis

30. Define Circular Queue. Another representation of a queue, which prevents an excessive use of memory is to arrange

elements Q[1], Q[2],…..Q[n] in a circular fashion. That is, it is the queue, which wraps around upon reaching the end of the array

UNIT - II 31. 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.

32. Define tree? A tree is a collection of nodes. The collection can be empty; otherwise, a tree consists of a

distinguished node r, called root, and zero or more non-empty (sub) tress T1, T2,….,Tk. Each of whose roots are connected by a directed edge from r.

33. Define leaf node? In a directed tree any node, which has out-degree 0, is called a terminal node or a leaf.

34. Define Sibling. Nodes with the same parent are called siblings.

35. Define directed tree and forest? A directed tree is an acyclic digraph which has one node called its root with in-degree 0 while

all other nodes have in-degree 1. In a directed tree any node which has out-degree 0 is called

Page 4: Dsa Two Mark Questions

Data Structures and Algorithms  

Department of Computer Science and Engineering                                      Muneeswaran V  Page 4  

a terminal node or a leaf all others nodes are called branch nodes. A set of disjoint tree is a forest

36. 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. 37. Define Binary Tree.

If every non-leaf node must have at most two children. A binary tree T is defined as a finite set of nodes that is either empty or consists of a root and two disjoint binary trees TL and TR called, respectively, the left and right subtree of the root.

38. Define Strictly binary tree? If every non-leaf node in a binary tree has nonempty left and right sub trees, the tree is termed

as a strictly binary tree. 39. What are the two methods of binary tree implementation?

Two methods to implement a binary tree are, a. Array representation. b. Linked representation

40. Define Depth of a node in the tree. The depth of node is the length of the unique path from the root to node. Thus for a root the

depth is always zero. 41. Define Height of a node in the tree.

The height of a node is the length of the longest path from root to particular node. Thus all leaves have height zero. The height of a tree is equal to a height of a root.

42. Define Preorder, inorder and postorder traversal. Preorder

• In the preorder traversal, Root is visited before the left and right subtrees are visited (n that order)

Inorder • In the inorder traversal, the root is visited after visiting its left subtree but before visiting

the right subtree Postorder

• In the postrder traversal, the root is visited after visiting the left and right sbutrees (in that order)

43. What is Binary Search Tree (BST)? The property that makes a binary tree into a binary search tree is that for every node, X, in the

tree, the values of all the keys in its left subtree are smaller that the key value in X, and the values of all the keys in its right subtree are larger that the key value in X. All the elements in the tree can be ordered.

44. Define expression trees? The leaves of an expression tree are operands, such as constants or variable names and the

other nodes contain operators. 45. What are the applications of binary tree?

Binary tree is used in data processing. a. File index schemes b. Hierarchical database management system

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

UNIT – III 47. Define AVL Tree

Page 5: Dsa Two Mark Questions

Data Structures and Algorithms  

Department of Computer Science and Engineering                                      Muneeswaran V  Page 5  

An AVL tree is a binary search tree except that for every node in the tree, the height of the left and right subtrees can differ by at most 1.

48. What is a balance factor in AVL trees? Balance factor of a node is defined to be the difference between the heights of the node’s

left subtree and the height of the node’s right subtree. 49. What is the need for hashing?

Hashing is used to perform insertions, deletions and find in constant average time. 50. Define hash function? 

Hash function takes an identifier and computes the address of that identifier in the hash table using some function

51. What are the problems in hashing? a. Collision

b. Overflow 52. What is collision?

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

53. Define collision resolution The process of finding another position for the collide record. Various techniques are

• Separate chaining • Open addressing

54. Define Binary heap? A heap is a binary tree that is completely filled, with the possible exception of the bottom level,

which is filled from left to right. Such a tree is known as complete binary tree. A heap in which the parent has a smaller key than the child’s is called a min heap and the parent has a larger key than the child’s is called a max heap.

55. List the application of Priority Queues. • The Selection Problem 

• Event Simulation UNIT – IV 56. Define Graph?

A graph G =<V, E>, consists of a set of vertices, V and a set of edges, E. Each edge is a pair (v, w), where v, w belongs to V.

57. Name the different ways of representing a graph? a. Adjacency matrix

b. Adjacency list 58. Define Topological Sorting.

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

59. What is the use of BFS? BFS can be used to find the shortest distance between some starting node and the remaining

nodes of the graph. The shortest distance is the minimum number of edges traversed in order to travel from the start node the specific node being examined.

60. Define biconnected graph? A graph is called biconnected if there is no single node whose removal causes the graph to

break into two or more pieces. A node whose removal causes the graph to become disconnected is called a cut vertex.

61. What is a minimum spanning tree? A minimum spanning tree of an undirected graph G is a tree formed from graph edges that

Page 6: Dsa Two Mark Questions

Data Structures and Algorithms  

Department of Computer Science and Engineering                                      Muneeswaran V  Page 6  

connects all the vertices of G at the lowest total cost 62. What are the two traversal strategies used in traversing a graph?

a. Breadth first search b. Depth first search 

63. State the differences between BFS and DFS. BFS DFS

Data Structure Queue Stack No. of Vertex Ordering 1 Ordering 2 Ordering Edge types (undirected Graphs)

Tree and Cross Edges Tree and Back Edges

Applications Connectivity, Acyclicity, Minimum – edge paths

Connectivity, Acyclicity, articulation points

Efficiency for Adjacent Matrix O(|V2|) O(|V2|) Efficiency for Adjacent List O(|V|+|E|) O(|V|+|E|)

UNIT – V 64. What is divide and conquer?

Given a function to compute on ‘n’ inputs the divide and conquer strategy suggests splitting the n inputs into k subsets yielding k sub problems. These sub problems are solved independently and then a solution must be found to combine the sub solutions into a solution of the whole.

65. State the importance of dynamic programming. Instead, a mathematical way of thinking about it is to look at what you should do at the end, if

you get to that stage. So you think about the best decision with the last potential partner (which you must choose) and then the last but one and so on. This way of tackling the problem backwards is Dynamic programming.

66. Where is dynamic programming used? Dynamic programming is used when the problem is to be solved in a sequence of

intermediate steps. It is particularly relevant for many optimization problems, i.e. frequently encountered in Operations research.

67. Define Space Complexity The Space complexity of an algorithm is the amount of memory it needs to run to completion

68. Define Time Complexity Time complexity of an algorithm is the amount of computer time it needs to run to completion

69. What are asymptotic notations? The notations that enables us to make meaningful statements about the time and space

complexity of a program is called asymptotic notations 70. What is NP?

NP is the class of decision problems for which a given proposed solution for a given input can be checked quickly to see if it is really a solution.