Sree Saraswathi Thyagaraja College (Autonomous), Pollachi

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Sree Saraswathi Thyagaraja College (Autonomous), Pollachi

MCA Department
Question Bank – Advanced Data Structures and Algorithms

Unit – I
Section – A (1 Mark)
A linear collection of data elements where the linear node is given by means of pointer is called?
a) Linked list
b) Node list
c) Primitive list
d) None
Answer:A

A variant of the linked list in which none of the node contains NULL pointer is?
a) Singly linked list
b) Doubly linked list
c) Circular linked list
d) None
Answer: C

Linked lists are best suited .....


A.for relatively permanent collections of data.
B.for the size of the structure and the data in the structure are constantly changing.
C.data structure
D.for none of above situation
Answer: A

Each node in singly linked list has ........ fields.


A.2
B.3
C.1
D.4
Answer: A

Each node in a linked list must contain at least .....


A.Three fields
B.Two fields
C.Four fields
D.Five fields
Answer: B

In a linked list the .......... field contains the address of next element in the list.
A.Link field
B.Next element field
C.Start field
D.Info field
Answer: B
LLINK is the pointer pointing to the ...
A.successor node
B.predecessor node
C.head node
D.last node
Answer:B

.......... refers to a linear collection of data items.


A. List
B. Tree
C. Graph
D. Edge
Answer:A

A linear list in which the pointer points only to the successive node is ......
A.singly linked list
B.circular linked list
C.doubly linked list
D.none of the above
Answer:A

A doubly linked list is also called as ..........


A.linked list
B.one way chain
C.two way chain
D.right link

The postfix form of the expression (A+ B)*(C*D- E)*F / G is?

a)AB+ CD*E - FG /**


b)AB + CD* E - F **G /
c)AB + CD* E - *F *G /
d)AB + CDE * - * F *G /
ANSWER: a) AB+ CD*E - FG /**

The data structure required to check whether an expression contains balanced parenthesis is?
a) Stack
b) Queue
c) Array
d) Tree
ANSWER: a) Stack

What data structure would you mostly likely see in a non recursive implementation of a recursive
algorithm?
a) LinkList
b) Stack
c) Queue
d) Tree
ANSWER: b) Stack

The process of accessing data stored in a serial access memory is similar to manipulating data on a
------?
a) Heap
b) Binary Tree
c) Array
d) Stack
ANSWER: d) Stack

The postfix form of A*B+C/D is?


a) *AB/CD+
b) AB*CD/+
c) A*BC+/D
d) ABCD+/*
ANSWER: b) AB*CD/+

Which data structure is needed to convert infix notation to postfix notation?


a) Branch
b) Tree
c) Queue
d) Stack

A linear list of elements in which deletion can be done from one end (front) and insertion can take
place only at the other end (rear) is known as a ?
a) Queue
b) Stack
c) Tree
d) Linked list
ANSWER: a) Queue

A queue is a ?
a) FIFO (First In First Out) list
b) LIFO (Last In First Out) list.
c) Ordered array
d) Linear tree
ANSWER: a) FIFO (First In First Out) list

If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what
order will they be removed?
a) ABCD
b) DCBA
c) DCAB
d) ABCD
ANSWER: a) ABCD
Section – B (5 Mark)
Write a program to print out the elements of a singly linked list.
Given two sorted lists, L1 and L2,write a procedure to compute L1 L2 using only the
basic list operation.
Write a program to evaluate a postfix expression.
Write a program to convert postfix expression in to infix.
Write a routine to implement queues using linked list
Write a routine to implement queues using Array.
Explain the procedure to insert a new node in the
(a) Beginning
(b) End of the list
Write an algorithm for the following in doubly linked list.
(i) inserting a node to the left.
(ii) Deleting a node.
Explain the cursor implementation of linked list.
Explain the following algorithm of a circular linked list.
(a) inset the node at the beginning
(b) delete a node from beginning
Write a routine to implement stack using
(a) array
(b) linked list
Write a routine to implement polynomial ADT.

Section – C (8 Mark)
Explain in detail about Arrays?
Discuss in detail about structures in c.
What is a Stack? Explain its operations with example.
Write the algorithm for converting infix expression to postfix expression.
What is a Queue? Explain its operations with example.
Explain any two applications of stack.
Write an algorithm to perform the following operation on a singly linked list.
(i) Insert new node at the beginning of list.
(ii) Insert new node at Middle.
(iii) Delete a node in the middle and last.
(iv) Count the number of nodes.
Write an algorithm to perform the following operation on a doubly linked list.
(v) Insert new node at the beginning of list.
(vi) Insert new node at Middle.
(vii) Delete a node in the middle and last.
(viii) Count the number of nodes.
Explain the Linear linked Implementation of Stack and Queue.
Explain the Insertion and Deletion algorithm for Circular linked List.
Explain the operations of Priority Queue.
Write the algorithm to merge any two Linked list.
Write an algorithm that takes the first node in a linked list, Reverse it and return the first
node in the resulting linked list without recursion and with recursion.
Implement a circular Queue in C using arrange to perform insertion and deletion
operations.
Convert the following Infix Expression to postfix using stack.
A*B-(C+D)+E
Explain Polynomial addition operation using array.
Unit – II
Section – A (1 Mark)
The height of a BST is given as h. Consider the height of the tree as the no. of edges in the longest
path from root to the leaf. The maximum no. of nodes possible in the tree is?
a) 2h-1 -1
b) 2h+1 -1
c) 2h +1
d) 2h-1 +1
ANSWER: B

The no of external nodes in a full binary tree with n internal nodes is?
a) n
b) n+1
c) 2n
d) 2n + 1
ANSWER: B

The difference between the external path length and the internal path length of a binary tree with
n internal nodes is?
a) 1
b) n
c) n + 1
d) 2n
ANSWER: D

Suppose a binary tree is constructed with n nodes, such that each node has exactly either zero or
two children. The maximum height of the tree will be?
a) (n+1)/2
b) (n-1)/2
c) n/2 -1
d) (n+1)/2 -1
ANSWER: B

Which of the following statement about binary tree is CORRECT?


a) Every binary tree is either complete or full
b) Every complete binary tree is also a full binary tree
c) Every full binary tree is also a complete binary tree
d) A binary tree cannot be both complete and full
ANSWER: C

Suppose we have numbers between 1 and 1000 in a binary search tree and want to search for the
number 363. Which of the following sequence could not be the sequence of the node examined?
a) 2, 252, 401, 398, 330, 344, 397, 363
b) 924, 220, 911, 244, 898, 258, 362, 363
c) 925, 202, 911, 240, 912, 245, 258, 363
d) 2, 399, 387, 219, 266, 382, 381, 278, 363
ANSWER: C

In full binary search tree every internal node has exactly two children. If there are 100 leaf nodes
in the tree, how many internal nodes are there in the tree?
a) 25
b) 49
c) 99
d) 101
ANSWER: C

Which type of traversal of binary search tree outputs the value in sorted order?
a) Pre-order
b) In-order
c) Post-order
d) None
ANSWER: B

Suppose a complete binary tree has height h>0. The minimum no of leaf nodes possible in term of
h is?
a) 2h -1
b) 2h -1 + 1
c) 2h -1
d) 2h +1
ANSWER: C

A 2-3 is a tree such that


a) All internal nodes have either 2 or 3 children
b) All path from root to leaves have the same length
The number of internal nodes of a 2-3 tree having 9 leaves could be
a) 4
b) 5
c) 6
d) 7
ANSWER: A, D

If a node having two children is to be deleted from binary search tree, it is replaced by its
a) In-order predecessor
b) In-order successor
c) Pre-order predecessor
d) None
ANSWER: B

A binary search tree is formed from the sequence 6, 9, 1, 2, 7, 14, 12, 3, 8, 18. The minimum number
of nodes required to be added in to this tree to form an extended binary tree is?
a) 3
b) 6
c) 8
d) 11
ANSWER: D

In a full binary tree, every internal node has exactly two children. A full binary tree with 2n+1
nodes contains
a) n leaf node
b) n internal nodes
c) n-1 leaf nodes
d) n-1 internal nodes
ANSWER: B

The run time for traversing all the nodes of a binary search tree with n nodes and printing them in
an order is
a) O(nlg(n))
b) O(n)
c) O(√n)
d) O(log(n))
ANSWER: B

When a binary tree is converted in to an extended binary tree, all the nodes of a binary tree in the
external node becomes
a) Internal nodes
b) External nodes
c) Root nodes
d) None
ANSWER: A

If n numbers are to be sorted in ascending order in O(nlogn) time, which of the following tree can
be used
a) Binary tree
b) Binary search tree
c) Max-heap
d) Min-heap
ANSWER: D

If n elements are sorted in a binary search tree. What would be the asymptotic complexity to
search a key in the tree?
a) O(1)
b) O(logn)
c) O(n)
d) O(nlogn)
View Answer / Hide Answer
ANSWER: C

If n elements are sorted in a balanced binary search tree. What would be the asymptotic
complexity to search a key in the tree?
a) O(1)
b) O(logn)
c) O(n)
d) O(nlogn)
ANSWER: B

The minimum number of elements in a heap of height h is


a) 2h+1
b) 2h
c) 2h -1
d) 2h-1
ANSWER: B

The maximum number of elements in a heap of height h is


a) 2h+1 -1
b) 2h
c) 2h -1
d) 2h -1
ANSWER: A
Section – B (5 Mark)
what are the types of representation of binary tree?
what is traversal? Give an algorithm for traversal in the binary tree.
Draw a Binary search tree for the following input list 60,25,75,15,50,66,33,44.Trace the algorithm to
delete the nodes 25,75,44 from the tree.
Explain and write routine to the various tree traversal methods.
Show the result of inserting 3,1,4,6,9,2,5,7 in to an initially empty binary search tree.
Show that for the perfect binary tree of height h containing 2h+1-1nodes.
Write a routine to implement the basic binary search tree operations.
Show the result of inserting 2,1,4,5,9,3,6,7 in to an initially empty binary tree.
Explain in detail about Threaded binary trees.
Write a procedure to Delete an element from a binary search tree and show the result
of deleting the root.
Construct an expression tree for the input ab+cde+**

Section – C (8 Mark)
Explain the various representations of binary tree in detail with suitable examples?
Explain in details about binary tree operations
Explain in detail about binary tree traversals
Explain Expression tree. How to convert expression trees into binary trees. Give example
What is binary search tree? Explain the insertion and deletion operations of binary search tree
with example
Define binary tree. Explain the insertion, deletion and searching operations of Binary tree with
algorithms
What is AVL tree? How to balanced the AVL tree?
Unit – III
Section – A (1 Mark)
A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After

inserting 6 values into an empty hash table, the table is as shown below. Which one of
the following choices gives a possible order in which the key values could have been inserted in the table?
A 46, 42, 34, 52, 23, 33
B 34, 42, 23, 52, 33, 46
C 46, 34, 42, 23, 52, 33
D 42, 46, 33, 23, 34, 52
Answer: C

How many different insertion sequences of the key values using the same hash function and linear probing
will result in the hash table shown above?
A 10
B 20
C 30
D 40
Answer C

The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open
addressing with hash function h(k) = k mod 10 and linear probing. What is the resultant hash table?

AA
BB
CC
DD
Answer C
Consider a hash table of size seven, with starting index zero, and a hash function (3x + 4)mod7. Assuming
the hash table is initially empty, which of the following is the contents of the table when the sequence 1, 3,
8, 10 is inserted into the table using closed hashing? Note that ‘_’ denotes an empty location in the table.
A 8, _, _, _, _, _, 10
B 1, 8, 10, _, _, _, 3
C 1, _, _, _, _, _,3
D 1, 10, 8, _, _, _, 3
Answer B

Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function x mod
10, which of the following statements are true? i. 9679, 1989, 4199 hash to the same value ii. 1471, 6171 has
to the same value iii. All elements hash to the same value iv. Each element hashes to a different value
(GATE CS 2004)
A i only
B ii only
C i and ii only
D iii or iv
Answer:C

Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform
hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions?
A (97 × 97 × 97)/1003
B (99 × 98 × 97)/1003
C (97 × 96 × 95)/1003
D (97 × 96 × 95)/(3! × 1003)
Answer: A

Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets
numbered 0 to 9 for i ranging from 0 to 2020?
A h(i) =i2 mod 10
B h(i) =i3 mod 10
C h(i) = (11 ∗ i2) mod 10
D h(i) = (12 ∗ i) mod 10
Answer B

Given a hash table T with 25 slots that stores 2000 elements, the load factor α for T is __________
A 80
B 0.0125
C 8000
D 1.25
Answer A
Which of the following statement(s) is TRUE?

1. A hash function takes a message of arbitrary length and generates a fixed length code.
2. A hash function takes a message of fixed length and generates a code of variable length.
3. A hash function may give the same hash value for distinct messages.

A I only
B II and III only
C I and III only
D II only
Answer: C

Consider a hash function that distributes keys uniformly. The hash table size is 20. After hashing of how
many keys will the probability that any new key hashed collides with an existing one exceed 0.5.
A5
B6
C7
D 10
Answer D

Section – B (5 Mark)
1. Draw the complete undirected graphs on one, two, three, four and five vertices. Prove that
the number of edges in an n vertex complete graph is n(n-1)/2.
2. Draw the complete undirected graphs on one, two, three, four and five vertices. Prove that
the number of edges in an n vertex complete graph is n(n-1)/2.
3. What are the different ways of representing a graph? Represent the following
graph using those ways.
4. What are the different ways of representing a graph? Represent the following
graph using those ways.
5. Write an algorithm which does depth first search through an un-weighted
connected graph. In an un-weighted graph, would breadth first search or depth
first search or neither find a shortest path tree from some node? Why?
6. Which are the two standard ways of traversing a graph? Explain them with an
example of each.
7. Explain Dijkstra’s algorithm for finding the shortest path in a given graph.
8. What do you understand by tree traversal? Write a procedure for traversing a
binary tree in preorder .
9. How memory is freed using Boundary tag method in the context of Dynamic
memory management?
Section – C (8 Mark)
1.Write short notes on the following:
(i) Threaded binary trees.
(ii) Graph traversal.
(iii) Conversion of forest into tree.
2.What do you understand by structured programming? Explain.
3.Write an algorithm to sort a given list using Quick sort method. Describe the behaviour of Quick
sort when input is already sorted.
4.Sort the following list using Heap Sort
5, 33, 40, 20, 50, 88, 60, 11, 77, 30, 45, 65.
5.Define graph, adjacency matrix, adjacency list, hash function, sparse matrix, reachability matrix.
6.Explain various graph traversal schemes and write their merits and demerits.
7.Which sorting algorithm is easily adaptable to singly linked lists? Explain your answer.
8.What do you mean by complexity of an algorithm? Explain the meaning of worst case analysis
and best case analysis with an example..
9.Write an algorithm to insert a node in the beginning of the linked list.
Unit – IV
Section – A (5 Mark)
1) The operation of processing each element in the list is known as ......
A. sorting
B. merging
C. inserting
D. traversal

2) Other name for directed graph is ..........


A. Direct graph
B. Digraph
C. Dir-graph
D. Digraph

3) Binary trees with threads are called as .......


A. Threaded trees
B. Pointer trees
C. Special trees
D. Special pointer trees

4) Graph G is .............. if for any pair u, v of nodes in G there is a path from u to v or path from v to
u.
A. Leterally connected
B. Widely Connected
C. Unliterally connected
D. Literally connected

5) In Binary trees nodes with no successor are called ......


A. End nodes
B. Terminal nodes
C. Final nodes
D. Last nodes

6) A connected graph T without any cycles is called ........


A. free graph
B. no cycle graph
C. non cycle graph
D. circular graph

7) Trees are said .......... if they are similar and have same contents at corresponding nodes.
A. Duplicate
B. Carbon copy
C. Replica
D. Copies

8) A connected graph T without any cycles is called a ........


A. A tree graph
B. Free tree
C. A tree d
D. All of the above

9) Every node N in a binary tree T except the root has a unique parent called the ......... of N.
A. Antecedents
B. Predecessor
C. Forerunner
D. Precursor

10) In a graph if E=(u,v) means ......


A. u is adjacent to v but v is not adjacent to u
B. e begins at u and ends at v
C. u is processor and v is successor
D. both b and c

11) Sequential representation of binary tree uses........


A. Array with pointers
B. Single linear array
C. Two dimentional arrays
D. Three dimentional arrays

12) In a graph if e=[u,v], Then u and v are called ........


A. End points of e
B. Adjacent nodes
C. Neighbours
D. All of the above

13) TREE[1]=NULL indicates tree is ........


A. Overflow
B. Underflow
C. Empty
D. Full

14) A binary tree whose every node has either zero or two children is called .......
A. complete binary tree
B. binary search tree
C. extended binary tree
D. data structure

15) Linked representation of binary tree needs ......... parallel arrays.


A. 4
B. 2
C. 3
D. 5

16) The depth of complete binary tree is given by ......


A. Dn = n log2n
B. Dn= n log2n+1
C. Dn = log2n
D. Dn = log2n+1

17) In a 2-tree, nodes with 0 children are called ............


A. Exterior node
B. Outside node
C. Outer node
D. External node

18) Which indicates pre-order traversal?


A. Left sub-tree, Right sub-tree and root
B. Right sub-tree, Left sub-tree and root
C. Root, Left sub-tree, Right sub-tree
D. Right sub-tree, root, Left sub-tree

19) In a extended-binary tree nodes with 2 children are called ........


A. Interior node
B. Domestic node
C. Internal node
D. Inner node

20) A terminal node in a binary tree is called ............


A. Root
B. Leaf
C. Child
D. Branch

Answers:
1) D. traversal
2) D. Digraph
3) A. Threaded trees
4) C. Unliterally connected
5) B. Terminal nodes
6) A. free graph
7) D. Copies
8) D. All of the above
9) B. Predecessor
10) D. both b and c
11) A. Array with pointers
12) D. All of the above
13) C. Empty
14) C. extended binary tree
15) C. 3
16) D. Dn = log2n+1
17) D. External node
18) C. Root, Left sub-tree, Right sub-tree
19) C. Internal node
20) B. Leaf

Section – B (5 Marks)

1. Bubble sort algorithm is inefficient because it continues execution even after an array is sorted
by performing unnecessary comparisons. Therefore, the number of comparisons in the best and
worst cases are the same. Modify the algorithm in such a fashion that it will not make the next
pass when the array is already sorted.
2. What are B-trees? Construct a B-Tree of order 3 for the following set of Input data: 69, 19, 43, 16,
25, 40, 132, 100, 145, 7, 15, 18.
3. Draw the 11 item hash table resulting from hashing the keys: 12, 44, 13, 88, 23, 94, 11, 39, 20, 16
and 5 using the hash function h(i) = (2i+5) mod 11.
4. What is the average number of comparisons in a sequential search?
5. 1 Sort the following list using Heap Sort technique, displaying each step. 20, 12, 25 6, 10, 15, 13
6. When will you sort an array of pointers to list elements, rather than sorting the elements
themselves?
7. The element being searched for is not found in an array of 100 elements. What is the average
number of comparisons needed in a sequential search to determine that the element is not there, if
the elements are completely unordered?
8. Show the result of inserting the keys.
F, S, Q, K, C, L, H, T, V, W, M, R, N , P, A, B, X, Y, D, Z, E in the order to an empty B-tree of
degree-3.
9. What do you mean by hash clash? Explain in detail any one method to resolve hash collisions.
10. Define Hashing. How do collisions happen during hashing? Explain the different techniques
resolving of collision.
Section – C (8 Marks)

1. Write short notes on any FOUR:-


(i) B Tree.
(ii) Time Complexity, Big O notation.
(iii) Merge Sort.
(iv) Threaded Binary Tree.
(v) Depth First Traversal
2. Which sorting algorithm is best if the list is already sorted? Why?
3. Sort the following sequence of keys using merge sort.66, 77, 11, 88, 99, 22, 33, 44, 55
4. Draw a B-tree of order 3 for the following sequence of keys: 2, 4, 9, 8, 7, 6, 3, 1, 5, 10
5. What is quick sort? Sort the following array using quick sort method. 24 56 47 35 10 90 82 31
6. How many key comparisons and assignments an insertion sort makes in its worst case?
7. Create a heap with following list of keys:8, 20, 9, 4, 15, 10, 7, 22, 3, 12
8. The following values are to be stored in a hash table 25, 42, 96, 101, 102, 162, 197. Describe how
the values are hashed by using division method of hashing with a table size of 7. Use chaining as
the method of collision resolution.
9. Describe insertion sort with a proper algorithm. What is the complexity of insertion sort in the
worst case?
10. Write short notes on the following:
(i) B-tree.
(ii) Abstract data type.
(iii) Simulation of queues.
Unit – V
Section – A (1 Mark)
1) Which of the following properties are necessary for an Algorithm?
(A) Definite ness (B) correct ness (C) Effectiveness (D) A and C

2) which of the following technique is not using for solve a 0-1knapsack problem
(A) Greedy (B) Dynamic programming (C) branch and bound (D) all of the above

3)For the following program gives Big O analysis of the running time (in terms of n)
For (i=0; i<n; i++)
A[i] = +;
(A) O(n-1) (B) O(n) (C) O(n2) (D) O(log n)

4) For the following program gives Big O analysis of the running time (in terms of n)
For (i=0; i< n; i++)
For (j=i; j< n; j++)
For (k=j; k< n; k++)
S++;
(A) O(n-1) (B) O(n2) (C) O(n3) (D) O(log n)

5) For the following program gives Big O analysis of the running time (in terms of n)
For (i=0; i < n*n; i++)
A[i] = i;
(A) O(n-1) (B) O(n2) (C) O(n3) (D) O(log n)

6) Given f(n) = log2n, g(n) = √n which function is asymptotically faster


(A) f(n) is faster than g(n) (B) g(n) is faster than f(n)
(C) Either f(n) or g(n) (D) Neither f(n) nor g(n)

7) Which of the following are true


(a) 33n3 + 4n2 = p (n2) (b) n! = O(nn) (c) 10n2+ 9 = O(n2) (d) 6n3 /(log n +1) = O(n3)
(A) a,b and c (B)a and c (C) a and b (D) all are true

8) n! =
(A) O( 2n) (B) ω(2n) (C) A and B (D) O(n100)

9) T (n) = 8T (n/2) + n2, T (1) = 1 then T (n) =


(A) ϴ (n2) (B) ϴ (n3) (C) ϴ (n4) (D) ϴ (n)

10) T (n) = 3T (n/4) + n then T (n) =


A) O (n2) (B) O (n3) (C) O (n) (D) O (n4)

11) T (n) = 4T (n/2) + n then T (n) =


(A) ϴ (n2) (B) ϴ (n3) (C) ϴ (n4) (D) ϴ (n)

12) T (n) = 2T (n/2) + cn then T (n) =


(A) O (log n) (B) O (n log n) (C) O (n2log n) (D) O (n2)

13) T (n) = 2T (n/2) + n2 then T (n) =


(A) ϴ (n2) (B) ϴ (n3) (C) ϴ (n4) (D) ϴ (n)

14) T (n) = 2T (n/2) + n2 then T (n) =


(A) O (n3) (B) O (n2) (C) O (n) (D) O (n4)

15) T (n) = 9T (n/3) + n then T (n) =


(A) ϴ (n4) (B) ϴ (n3) (C) ϴ (n2) (D) ϴ (n)

Answers
1D
2A
3B
4C
5B
6A
7D
8C
9B
10 C
11 A
12 B
13 A
14 B
15 C

You might also like