MABS Institution
11th Computer Science Monthly Test -1 ( Iteration and recursion )-Aug 2020
-
-
-
-
-
-
-
-
-
-
-
-
-
-
When will the loop variant be true?
-
-
What is recursive problem solving
-
What is an invariant?
-
-
Consider two variable m and n under the assignment m, n : = m + 3, n - 1. Is the expression m + 3n an invariant?
-
There are 7 tumblers on a table, all standing upside down. You are allowed to turn any 2 tumblers simultaneously in one move. Is it possible to reach a situation when all the tumblers are right side up? (Hint: The parity of the number of upside-down tumblers is invariant.)
-
A knockout tournament is a series of games. Two players compete in each game; the loser is knocked out (i.e. does not play anymore), the winner carries on. The winner of the tournament is the player that is left after all other players have been knocked out. Suppose there are 1234 players in a tournament. How many games are played before the tournament winner is decided?
-
Write a note on Recursion.
-
Show that p - c is an invariant of the assignment. P, C : = P + 1, C + 1
-
Using a loop variant how will you construct a loop?
-
How will you solve a problem using recursion?
-
King Vikramaditya has two magic swords. With one,he can cut off 19 heads of a dragon, but after that the dragon grows 13 heads. With the other sword, he can cut off 7 heads, but 22 new heads grow. If all heads are cut off, the dragon dies.If the dragon has originally 1000 heads, can it ever die?
(Hint :The number of heas mod 3 is invariant .) -
Write a note on Iteration.
-
Write a note on loop variant?
-
There are 6 equally spaced trees and 6 sparrows sitting on these trees,one sparrow on each tree. If a sparrow flies from one tree to another, then at the same time, another sparrow flies from its tree to some other tree the same distance away, but in the opposite direction. Is it possible for all the sparrows to gather on one tree?
-
Power can also be defined recursively as \({ a }^{ n }=\begin{cases} 1\quad \quad \quad \quad \quad \quad ifn=0 \\ a\times { a }^{ n }-1\quad \quad ifn\quad is\quad odd \\ { a }^{ n/2 }\times an/2\quad ifn\quad is\quad even \end{cases}\) Construct a recursive algorithm using this definition. How many multiplications are needed to calculate a10?
-
A single square- covered board is a board of 2n * 2n squares in which one square is covered with a single square tile. Show that it is possible to cover the this board with triominoes without overlap.
-
Explain the outline of recursive problem-solving technique.
-
Design a recursive algorithm to compute an, We constructed an iterative algorithm to compute an in Example 8.5. an can be defined recursively as
-
Customers are waiting in a line at a counter. The man at the counter wants to know how many customers are waiting in the line.
-
Explain how will you solve a problem recursively.
-
Assume an 8 * 8 chessboard with the usual coloring. "Recoloring" operation changes the color of all squares of a row or a column . you can recolor re - peatedly. The goal is to attain just one black squares , it changes by ( |8 - b ) - b| ).
-
Explain Loop invariant with a neat diagram.
-
Explain recursive- problem solving.