Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
package.json
package-lock.json
build/
DS_Store
plugins/
9 changes: 8 additions & 1 deletion experiment-descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"unit-type": "lu",
"label": "",
"basedir": ".",
"LaTeXinMD": true,
"units": [
{
"unit-type": "aim"
Expand Down Expand Up @@ -47,7 +48,13 @@
"label": "Posttest",
"unit-type": "task",
"content-type": "assesment"
},
{
"target": "references.html",
"source": "references.md",
"label": "References",
"unit-type": "task",
"content-type": "text"
}
]
}

49 changes: 1 addition & 48 deletions experiment/aim.md
Original file line number Diff line number Diff line change
@@ -1,48 +1 @@
Welcome to recursion. One of the most easiest things to code but really hard to debug! Recursion is a very powerful tool to solve problems. All loops(while, for , do while) can be simulated using recursion. Also the main step of the dynamic programming is recursion which is useful in solving many algorithmically difficult problems. Lets solve some problems now.

**Problem 1:**

You are given scales for weighing loads. On the left side lies a single stone of known weight W < 2N. You own a set of N different weights, weighing 1, 2, 4, ..., 2<sup>N</sup>-1 units of mass respectively. Determine how many possible ways there are of placing some weights on the sides of the scales, so as to balance them (put them in a state of equilibrium).


**Input Specification**

The input line contains two integers: N W, where N denotes the number of weights and W represents the weight to be placed on the left side.


**Output Specification**

Output must be a single integer denoting the number ways in which one can balance the weight W by placing weights on any side.


**Sample Input and Output**

Input: 2 4
Output: 3
Input: 5 10
Output: 14


**Problem 2:**

Given a weighing pan, n weights and a destination weight D, print "YES" or "NO" depending whether you can weight D using other weights given.


**Input Specification**

Input begins with numbers of weights n, then n values denoting mass of each weight and then in the end destination weight D.


**Output Specification**

As the output, print "YES" if it is possible to weight D, otherwise "NO".


**Sample Input and Output**

Input: 3 1 3 4 2
Output: YES
Input: 2 1 3 5
Output: NO


To understand and apply the principles of recursion to solve computational problems, analyze recursive processes, and appreciate the power and elegance of recursive thinking in computer programming.
File renamed without changes
6 changes: 5 additions & 1 deletion experiment/objective.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
- To learn to solve problems related to Recursion using Computer Programming.
- To understand the concept of recursion and identify problems that can be solved recursively.
- To develop and implement recursive algorithms for classic computational problems.
- To analyze the flow and efficiency of recursive solutions, including base cases and recursive cases.
- To compare recursion with iteration and recognize when recursion is advantageous.
- To strengthen problem-solving skills by applying recursion to real-world scenarios and algorithmic challenges.
221 changes: 175 additions & 46 deletions experiment/posttest.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,175 @@
[
{"question":"1. A continue statement causes execution to skip to:",
"answers":{
"a":"the end of the program",
"b":"the first statement after the loop",
"c":"the statement following the continue statement",
"d":"the next iteration of the loop"
},
"correctAnswer":"d"},

{"question":"2. The statement i++; is equivalent to:",
"answers":{
"a":"i = i + i;",
"b":"i = i + 1;",
"c":"i = i - 1;",
"d":"i - - ;"
},
"correctAnswer":"b"},

{"question":"3. Another word for 'looping' is:",
"answers":{
"a":"recapitulation ",
"b":"tintinabulation ",
"c":"iteration",
"d":"reiteration"
},
"correctAnswer":"c"},

{"question":"4. Which looping process is best used when the number of iterations is known?",
"answers":{
"a":"for",
"b":"while",
"c":"do-while",
"d":"all of the above"
},
"correctAnswer":"a"},

{"question":"5. Which of the following is not an infinite loop.",
"answers":{
"a":"int i = 1 ; while ( 1 ) { i++ ; }",
"b":"for( int i =1; i < 10 ; i--) printf('Hello World');",
"c":"for(int i =1; i<100; i++) printf('Hello World');",
"d":"int i = 0; do{ i-- printf('%d ',i); }while(i>0);"
},
"correctAnswer":"c"}
]
{
"version": 2.0,
"questions": [
{
"question": "1. Which of the following best describes a base case in recursion?",
"answers": {
"a": "A function that calls itself",
"b": "A variable declaration",
"c": "A condition where recursion stops",
"d": "A loop inside a function"
},
"correctAnswer": "c",
"explanations": {
"a": "Incorrect. That describes recursion, not the base case.",
"b": "Incorrect. Variables are unrelated.",
"c": "Correct. The base case is where recursion terminates.",
"d": "Incorrect. Loops are not required for recursion."
},
"difficulty": "beginner"
},
{
"question": "2. What is the output of the following recursive function call: factorial(3)?\nfunction factorial(n) { if (n == 0) return 1; else return n * factorial(n-1); }",
"answers": {
"a": "0",
"b": "1",
"c": "3",
"d": "6"
},
"correctAnswer": "d",
"explanations": {
"a": "Incorrect. 0 is not the result.",
"b": "Incorrect. 1 is the base case result.",
"c": "Incorrect. 3 is not the result of factorial(3).",
"d": "Correct. 3 * 2 * 1 = 6."
},
"difficulty": "beginner"
},
{
"question": "3. Which of the following is NOT a property of recursion?",
"answers": {
"a": "Always faster than iteration",
"b": "Requires a base case",
"c": "Can be used to solve combinatorial problems",
"d": "Can lead to stack overflow"
},
"correctAnswer": "a",
"explanations": {
"a": "Incorrect. Recursion is not always faster than iteration.",
"b": "Correct. Recursion requires a base case.",
"c": "Correct. Recursion is used in combinatorial problems.",
"d": "Correct. Stack overflow is a risk in recursion."
},
"difficulty": "intermediate"
},
{
"question": "4. In the context of recursion, what is a call stack overflow?",
"answers": {
"a": "When a function returns a value",
"b": "When a loop runs infinitely",
"c": "When too many recursive calls exhaust the stack memory",
"d": "When a variable is not initialized"
},
"correctAnswer": "c",
"explanations": {
"a": "Incorrect. Returning a value does not cause overflow.",
"b": "Incorrect. Infinite loops are not stack overflows.",
"c": "Correct. Too many recursive calls can exhaust stack memory.",
"d": "Incorrect. Variable initialization is unrelated."
},
"difficulty": "intermediate"
},
{
"question": "5. Which of the following problems is best solved using recursion?",
"answers": {
"a": "Variable assignment",
"b": "Simple addition",
"c": "Finding the maximum in an array",
"d": "Tower of Hanoi"
},
"correctAnswer": "d",
"explanations": {
"a": "Incorrect. Assignment does not require recursion.",
"b": "Incorrect. Addition is a simple operation.",
"c": "Incorrect. Maximum can be found iteratively.",
"d": "Correct. Tower of Hanoi is a classic recursive problem."
},
"difficulty": "intermediate"
},
{
"question": "6. What is the main advantage of tail recursion?",
"answers": {
"a": "It always runs faster",
"b": "It can be optimized to use less stack space",
"c": "It requires no base case",
"d": "It never terminates"
},
"correctAnswer": "b",
"explanations": {
"a": "Incorrect. Not always faster.",
"b": "Correct. Tail recursion can be optimized by compilers.",
"c": "Incorrect. Base case is still required.",
"d": "Incorrect. Tail recursion can terminate."
},
"difficulty": "advanced"
},
{
"question": "7. Which of the following recursive algorithms is used to solve the balancing weights problem?",
"answers": {
"a": "Sorting the weights",
"b": "Ignoring the weights",
"c": "Exploring all combinations of placing weights",
"d": "Adding all weights to one side"
},
"correctAnswer": "c",
"explanations": {
"a": "Incorrect. Sorting is not required.",
"b": "Incorrect. Ignoring weights does not solve the problem.",
"c": "Correct. The recursive solution explores all combinations.",
"d": "Incorrect. All weights on one side is not the only solution."
},
"difficulty": "advanced"
},
{
"question": "8. Which of the following is true about the subset sum problem in recursion?",
"answers": {
"a": "It only works for two weights",
"b": "It is not related to recursion",
"c": "It cannot be solved recursively",
"d": "It can be solved by considering all combinations recursively"
},
"correctAnswer": "d",
"explanations": {
"a": "Incorrect. It works for any number of weights.",
"b": "Incorrect. It is related to recursion.",
"c": "Incorrect. It can be solved recursively.",
"d": "Correct. Subset sum is a classic recursive problem."
},
"difficulty": "advanced"
},
{
"question": "9. What is the main risk of using recursion without careful design?",
"answers": {
"a": "All of the above",
"b": "Stack overflow",
"c": "Incorrect results",
"d": "Infinite loops"
},
"correctAnswer": "a",
"explanations": {
"a": "Correct. All are risks of poor recursion design.",
"b": "Correct. Stack overflow is a risk.",
"c": "Correct. Incorrect results are possible.",
"d": "Correct. Infinite loops can occur."
},
"difficulty": "advanced"
},
{
"question": "10. Which of the following is NOT a typical use case for recursion?",
"answers": {
"a": "Simple variable assignment",
"b": "Sorting algorithms like Merge Sort",
"c": "Solving combinatorial problems",
"d": "Tree traversal"
},
"correctAnswer": "a",
"explanations": {
"a": "Incorrect. Assignment does not require recursion.",
"b": "Correct. Merge Sort uses recursion.",
"c": "Correct. Combinatorial problems often use recursion.",
"d": "Correct. Tree traversal is a classic use of recursion."
},
"difficulty": "advanced"
}
]
}
Loading
Loading