Getting Started With Competitive Programming - Unit 3 - Week 0
Getting Started With Competitive Programming - Unit 3 - Week 0
(https://swayam.gov.in)
(https://swayam.gov.in/nc_details/NPTEL)
If already
registered, click
to check your
Week 0 : Assignment 0 (Non
payment status
Graded)
Assignment not submitted
Course
Note : This assignment is only for practice purpose and it will not be counted towards the Final
outline
score
About NPTEL 1) How many ones does the following procedure print when run with input ? 1 point
() n
How does an
NPTEL online
course work?
()
Week 0 ()
Practice: Week
0 : Assignment
0 (Non Graded)
(assessment?
name=322)
Week 1 ()
Week 2 ()
Read the upper bound on the for loop as 2
. Consider
n
the options below:
Week 3 ()
Week 4 () A.
2
n
Θ(2 )
2
(n )
Week 5 () B. 2 Θ
Week 6 () C.
n(n+1)/2
2
Θ( )
Week 7 () D.
n
Θ(n ⋅ 2 )
Week 8 () E.
2 n
Θ(n 2 )
Week 9 ()
Week 10 () Option A
Either B or C (both are valid)
Week 11 ()
Option D
Week 12 () Option E
Transcripts ()
1-2, 3-4, 5-6, 7-8, 7-9, 2-8, 0-5, 1-9
Problem 3
Solving
Session - Jan Yes, the answer is correct.
Score: 1
2024 ()
Accepted Answers:
(Type: Numeric) 3
1 point
3) How many bit strings (i.e, sequences over{0,1}) of length 18 have no consecutive ones? (You
may write a program to answer this question, although a calculator should also suffice.)
6765
1 point
The functions are listed in the increasing order of their asymptotic growth rate.
log n n
{2 , n log n, 2 , n!}
.
2
f (n) = O(f (n ))
5) We have an exponential time algorithm for problem A, and problem A reduces in 1 point
polynomial time to problem B. From this we can conclude that:
6) Which of the following is a stable sorting algorithm that takes the least time when applied 1 point
to an almost sorted array ? (Recall that a sorting algorithm is stable if two objects with equal keys
appear in the same order in sorted output as they appear in the input array to be sorted).
Quick Sort
Insertion Sort
Selection Sort
Merge Sort
Statement 1: For every graph and every maximum flow on , there always exists an edge such that
increasing the capacity on thatGedge will increase the maximum
G
flow that’s possible in the graph.
Statement 2: Suppose the maximum -flow of some graph has value . Now we increase the capacity of
every edge by 1. Then the maximum (s,
-flowt)in this modified graph will f
have value at most .
(s, t) f + 1
Statement 1
Statement 2
Both statements
Neither statement
8) Suppose you have a set of people who all do not know each other, and you have to 1 point
process a sequence of queries of the following kinds:
N
In particular, for every pair of people, we need to maintain a state indicating whether they are friends
or not, and update this state based on queries of type 1, and report the state for queries of type 2.
Since you have learned about the disjoint sets data structures in your algorithms course, you decide to
store the set of people as singleton sets to begin with. For each query of type 1, you perform a union
operation, and for
N
each query
N
of type 2, you perform a find operation.
Lights Out is a one-person game played on a rectangular lattice of lamps which can be turned on and
off. A move consists of flipping a ”switch” inside one of the squares, thereby toggling the on/off state of
this and all four vertically and horizontally adjacent squares. Starting from a randomly chosen light
pattern, the aim is to turn all the lamps off.
9) If the rectangular lattice you are given is a 1×5 grid, as shown below, what is the 0.5 points
smallest number of moves you need to turn off all the squares?
1
2
3
4
Impossible to turn off all squares
10) If the rectangular lattice you are given is a 2×3 grid, as shown below, with the top-left 0.5 points
corner on to begin with, in how many moves can you
turn off all the squares?
1
2
3
4
Impossible to turn off all squares
11) We have a a chessboard and 32 dominoes. Each domino is of such size that it exactly 1 point
covers two adjacent squares on the board. The 32 dominoes therefore can cover all 64 of the
chessboard squares. But now suppose we cut off two squares at diagonally opposite corners of the
board and discard one of the dominoes.
Is it possible to place the 31 dominoes on the board so that all the remaining 62 squares are covered?
Yes
No
12) Suppose we have a simple, undirected, connected graph where all edges have non-negative
weights, and in fact, the weight of each edge is either 1 or 20. G
Consider the following subgraph of — the vertex set of is the same as the vertex set of and the
edge set of consists of all the edges
H G
from whose weightH
is one. G
H G
Suppose has three connected components with 10, 15, and 30 vertices. Then the weight of any
minimum H
spanning tree of is:
G
92
1 point
13) When an array is to be sorted, it may happen that some data values start out being in the1 point
same position where they should end up. For example, in the array which is originally:
45,−4,32,0
−4,0,32,45
But as a particular sorting algorithm operates, it might (depending on the algorithm) move such an
element out of the position where it belongs and move it back eventually. Let’s say that a sorting
algorithm respects fixed points if it never moves an element that is in its proper position, on any input.
Which of the following statements are true? In the options below, the implementation of selection sort
is based on swapping the minimum element into it’s proper place in the current iteration, and does not
involve the use heaps. You may also assume that the input array has no duplicate elements.
Insertion sort does not respect fixedpoints but selection sort does.
Selection sort does not respect fixedpoints but insertion sort does.
Neither insertion sort nor selection sort respects fixed points.
Both insertion sort and selection sort respect fixed points.
14) You are at a party where any two people have an odd number of mutual friends at the 1 point
party. You see an even number of people other than you. What is the parity of the total number of
attendees? Note that we follow the convention that nobody is friends with themselves.
Even
Odd
Can be either odd or even
Such a party cannot exist
15) In a party consisting of 5 couples, people who new each other shook hands (pre-covid 1 point
era) while who did not know each other just greeted each other. One of them, , observed: “If you don’t
count me, then there are no two people present who shook hands the same number
X
of times”. How
many times did the wife of shake hands ?
X
3
4
0
Can’t be determined.
16) Given an undirected graph , we would like to color its vertices red and blue in such a way 1 point
that the total number of edges between
G
the red vertices is as close as possible to the total number of
edges between the blue vertices. In other words, suppose the vertices of graph G are partitioned into
the sets and , and the number of edges with both endpoints in is denoted as , and the the number of
edges with
A
both
B
endpoints in is denoted as . Then, let us defineAthe “quality” ofa the partition as and
denote this by . The goal is then
B
to find a partition
b
that minimizes . This is equivalent to: (A, |a
B)− b|
minimizing the number of edges with exactly one endpoint in and one endpoint in
A B
maximizing the number of edges with exactly one endpoint in and one endpoint in
A B
minimizing the difference between the sums of the degrees of the vertices in and
A B
None of the above