0% found this document useful (0 votes)
25 views15 pages

Objective Questions-CP-II

Uploaded by

Diptimayee Rana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views15 pages

Objective Questions-CP-II

Uploaded by

Diptimayee Rana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Competitive Programming-II

UNIT-I
1. What is the GCD of a and b?
a) a + b
b) gcd (a-b, b) if a>b
c) gcd (a+b, a-b)
d) a – b
2. If gcd (a, b) is defined by the expression, d=a*p + b*q where d, p, q are positive integers
and a, b is both not zero, then what is the expression called?
a) Bezout’s Identity
b) Multiplicative Identity
c) Sum of Product
d) Product of Sum
3. What is the total running time of Euclid’s algorithm?
a) O(N)
b) O(N log M)
c) O(N log N)
d) O(log N +1)

4.What is the total running time of the binary GCD algorithm?


a) O(N)
b) O(N2)
c) O(log N)
d) O(N log N)

5. What is the formula for Euclidean algorithm?


a) GCD (m,n) = GCD (n, m mod n)
b) LCM(m,n)=LCM(n, m mod n)
c) GCD(m,n,o,p) = GCD (m, m mod n, o, p mod o)
d) LCM (m,n,o,p) = LCM (m, m mod n, o, p mod o)

6. Which of the following algorithms has better computational complexity than standard
division algorithms?
a) Montgomery algorithm
b) Classical modular exponentiation algorithm
c) ASM algorithm
d) FSM algorithm
7. The time complexity to perform the modular exponentiation of a ≡ cg (mod m).
a) O(m+a)
b) O(a*g)
c) O(gm)
d) O(g)

8. The number of factors of prime numbers are ___________


a) 2
b) 3
c) Depends on the prime number
d) None of the mentioned

9. If a, b, c, d are distinct prime numbers with an as smallest prime then a * b * c * d is a


___________
a) Odd number
b) Even number
c) Prime number
d) None of the mentioned
10. If a, b are two distinct prime number than a highest common factor of a, b is
___________
a) 2
b) 0
c) 1
d) ab

11. What will be the output of the following code in C++?

#include <stdio.h>

int ETF(int n)

int a, result = n;

for (a = 2; a * a <= n; ++a)

if (n % a == 0)

while (n % a == 0)

n = n / a;
result = result - result / a;

if (n > 1)

result = result - result / n;

return result;

int main()

int n;

for (n = 1; n <= 4; n++)

printf("%d\n", ETF(n));

return 0;

a) 0 1 2 3
b) 0 1 2 4
c) 1 1 2 2
d) 1 2 3 4

12. The Euclid’s algorithm runs efficiently if the remainder of two numbers is divided by the
minimum of two numbers until the remainder is zero.
a) True
b) False

13. Which of the following is the correct mathematical application of Euclid’s algorithm?
a) Determination of prime numbers
b) Lagrange’s four square theorem
c) Cauchy-Euler theorem
d) Residue theorem

UNIT- 2

1) To insert a new node in linked list free node will be available in ........
A. Available list
B. Avail list
C. Free node list
D. Memory space list
2) A singly linked list is also called as ........
A. linked list
B. one way chain
C. two way chain
D. right link
3) A ..... list is a header list where the node points back to the header node.
A. Circular header
B. Grounded header
C. Two way header
D. One way header
4) .......... may take place only when there is some minimum amount(or) no space left in free
storage list.
A. Memory management
B. Garbage collection
C. Recycle bin
D. Memory management
5) A linear list in which the last node points to the first node is ........
Sub: DSU MCQ on Unit-4 Linked List
A. singly linked list
B. circular linked list
C. doubly linked list
D. none of the above
6) What is the time complexity to count the number of elements in the linked list?
A. O(1)
B. O(n)
C. O(logn)
D. O(n2)
7) What is the space complexity for deleting a linked list?
A. O(1)
B. O(n)
C. O(logn)
D. O(n2)
8) Which of these is not an application of a linked list?
A. To implement file systems
B. For separate chaining in hash-tables
C. To implement non-binary trees
D. Random Access of elements
9) What differentiates a circular linked list from a normal linked list?
A. You cannot have the 'next' pointer point to null in a circular linked list
B. It is faster to traverse the circular linked list
C. You may or may not have the 'next' pointer point to null in a circular linked list
D. All of the mentioned
10) In a circular linked list:-
a) Components are all linked together in some sequential manner.
b) There is no beginning and no end.
c) Components are arranged hierarchically.
d) Forward and backward traversal within the list is permitted.
11. 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
12. Which of the following operations is performed more efficiently by doubly linked list
than by singly linked list?
a) Deleting a node whose location in given
b) Searching of an unsorted list for a given item
c) Inverting a node after the node with given location
d) Traversing a list to process each node
13. Consider an implementation of unsorted singly linked list. Suppose it has its
representation with a head and tail pointer. Given the representation, which of
the following operation can be implemented in O(1) time?
i) Insertion at the front of the linked list
ii) Insertion at the end of the linked list
iii) Deletion of the front node of the linked list
iv) Deletion of the last node of the linked list
a) I and II
b) I and III
c) I,II and III
d) I,II and IV
14. In linked list each node contain minimum of two fields. One field is data field to store the
data second field is?
a) Pointer to character
b) Pointer to integer
c) Pointer to node
d) Node
15. The concatenation of two list can performed in O(1) time. Which of the following
variation of linked list can be used?
a) Singly linked list
b) Doubly linked list
c) Circular doubly linked list
d) Array implementation of list
16. Consider the following definition in c programming language
struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;
Which of the following c code is used to create new node?
a) ptr=(NODE*)malloc(sizeof(NODE));
b) ptr=(NODE*)malloc(NODE);
c) ptr=(NODE*)malloc(sizeof(NODE*));
d) ptr=(NODE)malloc(sizeof(NODE));
17. A variant of linked list in which last node of the list points to the first node
of the list is?
a) Singly linked list c) Circular linked list
b) Doubly linked list d) Multiply linked list
UNIT-III
1. What is the worst case complexity of bubble sort?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
2. Which of the following is not an advantage of optimised bubble sort over other
sorting techniques in case of sorted elements?
a) It is faster
b) Consumes less memory
c) Detects whether the input is already sorted
d) Consumes less time

3. What is an in-place sorting algorithm?


a) It needs O(1) or O(logn) memory to create auxiliary locations
b) The input is already sorted and in-place
c) It requires additional storage
d) It requires additional space
4. How many passes does an insertion sort algorithm consist of?
a) N
b) N-1
c) N+1
d) N2
5. Which of the following algorithm implementations is similar to that of an insertion
sort?
a) Binary heap
b) Quick sort
c) Merge sort
d) Radix sort

6. What is the average case running time of an insertion sort algorithm?


a) O(N)
b) O(N log N)
c) O(log N)
d) O(N2)
7. Merge sort uses which of the following technique to implement sorting?
a) backtracking
b) greedy algorithm
c) divide and conquer
d) dynamic programming

8. What will be the best case time complexity of merge sort?


a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)
9. Which of the following is not a variant of merge sort?
a) in-place merge sort
b) bottom up merge sort
c) top down merge sort
d) linear merge sort
10. Find the pivot element from the given input using median-of-three partitioning
method.
8, 1, 4, 9, 6, 3, 5, 2, 7, 0.
a) 8
b) 7
c) 9
d) 6

11. Find the pivot element from the given input using median-of-three partitioning
method.
8, 1, 4, 9, 6, 3, 5, 2, 7, 0.
a) 8
b) 7
c) 9
d) 6
12. Which of the following sorting techniques is most efficient if the range of input data
is not significantly greater than a number of elements to be sorted?
a) selection sort c) counting sort
b) bubble sort d) insertion sort
13. Which of the following sorting techniques is stable?
a) quick sort
b) counting sort
c) heap sort
d) selection sort
14. What is the best case and worst case complexity of ordered linear search?
a) O(nlogn), O(logn)
b) O(logn), O(nlogn)
c) O(n), O(1)
d) O(1), O(n)
15. Binary Search can be categorized into which of the following?
a) Brute Force technique
b) Divide and conquer
c) Greedy algorithm
d) Dynamic programming

Unit –IV
1. In a stack, if a user tries to remove an element from an empty stack it is called
_________
a) Underflow
b) Empty collection
c) Overflow
d) Garbage Collection
2. Pushing an element into stack already having five elements and stack size of 5, then
stack becomes ___________
a) Overflow
b) Crash
c) Underflow
d) User flow
3. Entries in a stack are “ordered”. What is the meaning of this statement?
a) A collection of stacks is sortable
b) Stack entries may be compared with the ‘<‘ operation
c) The entries are stored in a linked list
d) There is a Sequential entry that is one by one
4. Which of the following is not the application of stack?
a) A parentheses balancing program
b) Tracking of local variables at run time
c) Compiler Syntax Analyzer
d) Data Transfer between two asynchronous process

5. Consider the usual algorithm for determining whether a sequence of parentheses is


balanced. Suppose that you run the algorithm on a sequence that contains 2 left
parentheses and 3 right parentheses (in some order). The maximum number of
parentheses that appear on the stack AT ANY ONE TIME during the computation?
a) 1
b) 2
c) 3
d) 4 or more
6. What is the value of the postfix expression 6 3 2 4 + – *?
a) 1
b) 40
c) 74
d) -18
7. What does the following function check for? (all necessary headers to be included and
function is called from main)

#define MAX 10

typedef struct stack

int top;

int item[MAX];

} stack;

int function(stack *s)

if(s->top == -1)

return 1;

else return 0;

a) full stack
b) invalid index
c) empty stack
d) infinite stack

8. What does ‘stack underflow’ refer to?


a) accessing item from an undefined stack
b) adding items to a full stack
c) removing items from an empty stack
d) index out of bounds exception

9. Array implementation of Stack is not dynamic, which of the following statements


supports this argument?
a) space allocation for array is fixed and cannot be changed during run-time
b) user unable to give the input for stack operations
c) a runtime exception halts execution
d) improper program compilation

10. What does the following function do?

public Object some_func()throws emptyStackException

if(isEmpty())

throw new emptyStackException("underflow");

return first.getEle();

a) pop
b) delete the top-of-the-stack element
c) retrieve the top-of-the-stack element
d) push operation

11. What does ‘stack overflow’ refer to?


a) accessing item from an undefined stack
b) adding items to a full stack
c) removing items from an empty stack
d) index out of bounds exception

12. Which of the following data structures can be used for parentheses matching?
a) n-ary tree
b) queue
c) priority queue
d) stack

13. Minimum number of queues to implement stack is ___________


a) 3
b) 4
c) 1
d) 2

UNIT – V

1. Which of the following is false?


a) The spanning trees do not have any cycles
b) MST have n – 1 edges if the graph has n edges
c) Edge e belonging to a cut of the graph if has the weight smaller than any other
edge in the same cut, then the edge e is present in all the MSTs of the graph
d) Removing one edge from the spanning tree will not make the graph
disconnected

2. Which of the following is not the algorithm to find the minimum spanning tree of
the given graph?
a) Boruvka’s algorithm
b) Prim’s algorithm
c) Kruskal’s algorithm
d) Bellman–Ford algorithm

3. Consider the graph shown below. Which of the following are the edges in the
MST of the given graph?

a) (a-c)(c-d)(d-b)(d-b)
b) (c-a)(a-d)(d-b)(d-e)
c) (a-d)(d-c)(d-b)(d-e)
d) (c-a)(a-d)(d-c)(d-b)(d-e)

4. Consider a undirected graph G with vertices { A, B, C, D, E}. In graph G, every


edge has distinct weight. Edge CD is edge with minimum weight and edge AB is
edge with maximum weight. Then, which of the following is false?
a) Every minimum spanning tree of G must contain CD
b) If AB is in a minimum spanning tree, then its removal must disconnect G
c) No minimum spanning tree contains AB
d) G has a unique minimum spanning tree
5. The travelling salesman problem can be solved using _________
a) A spanning tree
b) A minimum spanning tree
c) Bellman – Ford algorithm
d) DFS traversal
6. Which of the following is false in the case of a spanning tree of a graph G?
a) It is tree that spans G
b) It is a subgraph of the G
c) It includes every vertex of the G
d) It can be either cyclic or acyclic

7. 2. Every graph has only one minimum spanning tree.


a) True
b) False
8. What is a full binary tree?
a) Each node has exactly zero or two children
b) Each node has exactly two children
c) All the leaves are at the same level
d) Each node has exactly one or two children
9. What is a complete binary tree?
a) Each node has exactly zero or two children
b) A binary tree, which is completely filled, with the possible exception of the
bottom level, which is filled from right to left
c) A binary tree, which is completely filled, with the possible exception of the
bottom level, which is filled from left to right
d) A tree In which all nodes have degree 2

10. What is the average case time complexity for finding the height of the binary tree?
a) h = O(loglogn)
b) h = O(nlogn)
c) h = O(n)
d) h = O(log n)
11. In a full binary tree if number of internal nodes is I, then number of nodes N are?
a) N = 2*I
b) N = I + 1
c) N = I – 1
d) N = 2*I + 1
12. Which of the following is incorrect with respect to binary trees?
a) Let T be a binary tree. For every k ≥ 0, there are no more than 2k nodes in level
k
b) Let T be a binary tree with λ levels. Then T has no more than 2λ – 1 nodes
c) Let T be a binary tree with N nodes. Then the number of levels is at least
ceil(log (N + 1))
d) Let T be a binary tree with N nodes. Then the number of levels is at least
floor(log (N + 1))

13. Figure below is a balanced binary tree. If a node inserted as child of the node R,
how many nodes will become unbalanced?
a) 2
b) 1
c) 3
d) 0
UNIT – VI
1. Which of the following is/are property/properties of a dynamic programming
problem?
a) Optimal substructure
b) Overlapping subproblems
c) Greedy approach
d) Both optimal substructure and overlapping subproblems

2. 2. If an optimal solution can be created for a problem by constructing optimal


solutions for its subproblems, the problem possesses ____________ property.
a) Overlapping subproblems
b) Optimal substructure
c) Memoization
d) Greedy
3. When a top-down approach of dynamic programming is applied to a problem, it
usually _____________
a) Decreases both, the time complexity and the space complexity
b) Decreases the time complexity and increases the space complexity
c) Increases the time complexity and decreases the space complexity
d) Increases both, the time complexity and the space complexity

4. 9. Which of the following problems is NOT solved using dynamic programming?


a) 0/1 knapsack problem
b) Matrix chain multiplication problem
c) Edit distance problem
d) Fractional knapsack problem
5. Which of the following problems is NOT solved using dynamic programming?
a) 0/1 knapsack problem
b) Matrix chain multiplication problem
c) Edit distance problem
d) Fractional knapsack problem

6. Which of the following problems should be solved using dynamic programming?


a) Mergesort c) Longest common subsequence
b) Binary search d) Quick sort

7. Suppose you have coins of denominations 1, 3 and 4. You use a greedy algorithm,
in which you choose the largest denomination coin which is not greater than the
remaining sum. For which of the following sums, will the algorithm NOT produce
an optimal answer?
a) 20
b) 12
c) 6
d) 5

8. Suppose you have coins of denominations 1,3 and 4. You use a greedy algorithm,
in which you choose the largest denomination coin which is not greater than the
remaining sum. For which of the following sums, will the algorithm produce an
optimal answer?
a) 14
b) 10
c) 6
d) 100

9. The Knapsack problem is an example of ____________


a) Greedy algorithm
b) 2D dynamic programming
c) 1D dynamic programming
d) Divide and conquer
10. You are given a knapsack that can carry a maximum weight of 60. There are 4
items with weights {20, 30, 40, 70} and values {70, 80, 90, 200}. What is the
maximum value of the items you can carry using the knapsack?
a) 160
b) 200
c) 170
d) 90
11. What is the time complexity of the brute force algorithm used to solve the
Knapsack problem?
a) O(n)
b) O(n!)
c) O(2n)
d) O(n3)

12. The 0-1 Knapsack problem can be solved using Greedy algorithm.
a) True
b) False

You might also like