From 1160dd48c841456a04e91b594d07efcdfa02357d Mon Sep 17 00:00:00 2001 From: Manasa_krishna <36001156+chandumanu111@users.noreply.github.com> Date: Mon, 22 Jun 2020 19:52:49 +0530 Subject: [PATCH 1/4] new files project files are added to existing repo --- src/lab/exp1/Objective.html | 255 +++++----------------- src/lab/exp1/Theory.html | 330 ++++++++--------------------- src/lab/exp10/Objective.html | 258 +++++------------------ src/lab/exp10/Theory.html | 298 ++++++-------------------- src/lab/exp2/Objective.html | 258 +++++------------------ src/lab/exp2/Theory.html | 314 +++++++-------------------- src/lab/exp3/Objective.html | 258 +++++------------------ src/lab/exp3/Theory.html | 398 ++++++++++------------------------- src/lab/exp4/Objective.html | 258 +++++------------------ src/lab/exp4/Theory.html | 393 +++++++++++----------------------- src/lab/exp5/Objective.html | 257 +++++----------------- src/lab/exp5/Theory.html | 331 +++++++---------------------- src/lab/exp6/Objective.html | 257 +++++----------------- src/lab/exp6/Theory.html | 323 +++++++--------------------- src/lab/exp7/Objective.html | 257 +++++----------------- src/lab/exp7/Theory.html | 286 ++++++------------------- src/lab/exp8/Objective.html | 257 +++++----------------- src/lab/exp8/Theory.html | 278 ++++++------------------ src/lab/exp9/Objective.html | 257 +++++----------------- src/lab/exp9/Theory.html | 300 ++++++-------------------- 20 files changed, 1295 insertions(+), 4528 deletions(-) diff --git a/src/lab/exp1/Objective.html b/src/lab/exp1/Objective.html index 21e498e7..5cca27b8 100644 --- a/src/lab/exp1/Objective.html +++ b/src/lab/exp1/Objective.html @@ -1,216 +1,59 @@ - - + + OJ + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Numerical Representation

-

- To learn to solve problems related to Numerical Representation using Computer Programming. -

-
-
+
+
+ +
+ +
+

Objective

+

    +
  1. To learn about the meaning of operators +
  2. +
  3. To learn about the precedence and assosciativity of the operators +
  4. +
  5. To learn how to evaluate an expression by evaluating its sub expressions +
  6. + +

    +
+
+ - - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp1/Theory.html b/src/lab/exp1/Theory.html index d26e606c..760afe7b 100644 --- a/src/lab/exp1/Theory.html +++ b/src/lab/exp1/Theory.html @@ -1,250 +1,98 @@ - - - - - - - - - - Welcome to Virtual Labs - A MHRD Govt of india Initiative - - - - - - - - - - - - - - - - - - -
-
- - + + OJ + + + + + + + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Numerical Representation

-

Problem 1

-
-

-Let us try to find how many binary numbers can be generated when you are given a fixed number of bits,say n.
-n=1, gives
-0,1
-n=2, gives
-00,01,10,11 -n=3, gives
-000,001,010,011,100,101,110,111
-etc. -

- -

-

-It can be seen easily by the multiplication principle that for n bits this number is 2n. One of these number corresponds to the 0 in decimal, so the biggest number possible is 2n - 1. Therefore, given a number, say N, it can fit in n bits if N is less than 2^n. Hence, the number of bits required to fit a number N is equal to ceil(log2(N)). Now finding ceil(log2(N)) can be done easily by repeatedly dividing the given number, N, by two until you get 0 as the quotient. For example, let N=96 -

-

-Then,
-Step 1 :96/2 gives quotient as 48
-Step 2 :48/2 gives quotient as 24
-Step 3 :24/2 gives quotient as 12
-Step 4 :12/2 gives quotient as 6
-Step 5 :6/2 gives quotient as 3
-Step 6 :3/2 gives quotient as 1
-
-

- -

Problem 2

-
-

-Lets start with an example. Consider the sample input, the given characters are A,B,C and the input string is AC. Assume we are traversing the input string from left to right, say initially we are at 0th position. If instead of 'A' suppose B was present, then all the strings which would start with A would come first than B, right? -Thus, the number of strings which come before BC would No_strings which start with A + No_strings which start with B before BC. But luckily we have initial letter as A. Now the 1st character is 'C' , thus we need to count all the strings which start with AB. If instead of 'C' there was a D, then we would have to count the number of strings starting with AB, AC. In this manner we proceed adding the requisite number of strings to our result. -

-
-
+
+
+ +
+ +
+

Theory

+

Problem 1

+

+ Let us try to find how many binary numbers can be generated when you are given a fixed number of bits,say n. + n=1 + 0,1 + n=2 + 00,01,10,11 + n=3 + 000,001,010,011,100,101,110,111 + etc. + + It can be seen easily by the multiplication principle that for n bits this number is 2^n. One of these number corresponds to the 0 in decimal, so the biggest number possible is 2^n - 1. Therefore, given a number, say N, it can fit in n bits if N is less than 2^n. Hence, the number of bits required to fit a number N is equal to ceil(log2(N)). Now finding ceil(log2(N)) can be done easily by repeatedly dividing the given number, N, by two until you get 0 as the quotient. For example, let N=96 + + Then, + Step 1 :96/2 gives quotient as 48 + Step 2 :48/2 gives quotient as 24 + Step 3 :24/2 gives quotient as 12 + Step 4 :12/2 gives quotient as 6 + Step 5 :6/2 gives quotient as 3 + Step 6 :3/2 gives quotient as 1 + Step 7 :1/2 gives quotient as 0 + + So, ceil(log2(96)) is 6 because doing division on the 7th time gave a zero as the quotient. Therefore, the minimum number of bits required to fit 96 is 6. + + + +

+

+ +
+

+

Problem 2

+
	Lets start with an example. Consider the sample input , the given characters are A,B,C and the input string is AC.
+	Assume we are traversing the input string from left to right, say initially we are at 0th position. 
+	If instead of 'A' suppose B was present, then all the strings which would start with A would come first than B right.
+	Thus the number of strings which come before BC would No_strings which start with A + No_strings which start with B before BC.
+	But luckily we have initial letter as A. 
+	Now the 1st character is 'C' , thus we need to count all the strings which start with AB.
+	If instead of 'C' there was a D, then we would have to count the number of strings starting with AB , AC.In this manner 
+	we proceed adding the requisite number of strings to our result.   
+
+ + +
+
+ - - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp10/Objective.html b/src/lab/exp10/Objective.html index 5c75a4a6..5cca27b8 100644 --- a/src/lab/exp10/Objective.html +++ b/src/lab/exp10/Objective.html @@ -1,219 +1,59 @@ - - + + OJ + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Sequences

-

- To learn to solve problems related to Sequences using Computer Programming. -

-
-
+
+
+ +
+ +
+

Objective

+

    +
  1. To learn about the meaning of operators +
  2. +
  3. To learn about the precedence and assosciativity of the operators +
  4. +
  5. To learn how to evaluate an expression by evaluating its sub expressions +
  6. + +

    +
+
+ - - - - - -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp10/Theory.html b/src/lab/exp10/Theory.html index 6fb94c04..c33b13f7 100644 --- a/src/lab/exp10/Theory.html +++ b/src/lab/exp10/Theory.html @@ -1,239 +1,77 @@ - - - - - - - - - - Welcome to Virtual Labs - A MHRD Govt of india Initiative - - - - - - - - - - - - - - - - - - -
-
- - -
- -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Sequences

-

Problem 1

-
-

-This is a fairly straight-forward problem. We have to determine the length of the longest subsequence in which all the elements are smaller than the previous ones. It is easy to see that each of these decresing subsequences will end either when the current number is bigger than the previous number, or when the current number is the final number in the sequence. Also, the end of one sequence marks the beginning of another sequence. So, this problem is easy to solve if we can note down the lengths of these sequences and find the largest number in them. All this can be done while the input is being read. You just need to keep track of the length of the current sequence and the length of the largest sequence which has been seen till now. As discussed earlier, if the currrent number is lesser than the previous number then the length of the current sequence is incremented by 1, and if the current number is greater than the previous number, then the current sequnce ends and we check whether its length is the greatest that has been seen till now, and we also start a new sequence with length equal to 1. When, then input sequence ends then also the current sequence is deemed as terminated, and we again check its length against the length of the largest sequence seen till now. -

-

-
-

Problem 2

-
-

-This is a very famous problem. It's known as longest increasing subsequence problem.Let us consider a naive approach of solving this problem. For every subsequence if it is a increasing subsequence we try to update the maximum length of the longest increasing subsequence.If we analyse the time complexity of this appraoch it is clear that it is goin to take 2N*N operations. So, if N = 30, this approach would take 32212254720 (~3*1011) operations. Looking at the constraints it is obvious that this algorithm is not feasible. Now we look at the standard solution. You may refer wikipedia for the same. -

-

-Every subsequence has to end with some element of the sequence. So we calculate the length of the longest incresing subsequence subject to the constraint that the subsequence ends with seq[i].Lets say that it is best[i]. The answer will be max(best[0],best[1],...,best[N-1]). -

-

Recursive formulation

-

-Now the task is to find a recursive formula for best[i]. Assume we know the values of best[0],best[1],..., best[i-1] and now out task is to find best[i]. Seq[i] can form a increasing subsequence with some Seq[j] if Seq[i] > Seq[j] and j < i. Thus the recusive formula is : -

-

- best[i] = max(1,best[j]+1|j< i && Seq[i]>Seq[j]) -

-

-
-
+ + OJ + + + + +
- - - - - - - - - - - - - - - +
+ +
+
+ +
+
+
+ +
+ +
+

Theory

+

Problem 1

+
This is a fairly straight-forward problem. We have to determine the length of the longest subsequence in which all the elements are smaller than the previous ones. It is easy to see that each of these decresing subsequences will end either when the current number is bigger than the previous number, or when the current number is the final number in the sequence. Also, the end of one sequence marks the beginning of another sequence. So, this problem is easy to
+solve if we can note down the lengths of these sequences and find the largest number in them. All this can be done while the input is being read. You just ne
+ed to keep track of the length of the current sequence and the length of the largest sequence which has been seen till now. As discussed earlier, if the curr
+rent number is lesser than the previous number then the length of the current sequence is incremented by 1, and if the current number is greater than the pre
+vious number, then the current sequnce ends and we check whether its length is the greatest that has been seen till now, and we also start a new sequence with length equal to 1. When, then input sequence ends then also the current sequence is deemed as terminated, and we again check its length against the length of the largest sequence seen till now.
+
+
+

+

Problem 2

+
	This is a very famous problem.Its known as longest increasing subsequence problem.Let us consider a
+	naive approach of solving this problem. For every subsequence if it is a increasing subsequence we 
+	try to update the maximum length of the longest increasing subsequence.If we analyse the time complexity
+	of this appraoch it is clear that it is goin to take 2^N * N operations.So if N = 30 , this approach would
+	take 32212254720 (~3*10^11) operations.Looking at the constraints it is obvious that this algorithm is not feasible.
+	Now we look at the standard solution.You may refer wikipedia for the same.
 	
-	
-	
-
-
 
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/lab/exp2/Objective.html b/src/lab/exp2/Objective.html
index fdf7bf68..5cca27b8 100644
--- a/src/lab/exp2/Objective.html
+++ b/src/lab/exp2/Objective.html
@@ -1,219 +1,59 @@
-
-
+		
+		OJ
+		
+		
+	
+	
+		
-
-	
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Beauty of Numbers

-

- To learn to solve problems related to Number Theory using Computer Programming. -

-
-
+
+
+ +
+ +
+

Objective

+

    +
  1. To learn about the meaning of operators +
  2. +
  3. To learn about the precedence and assosciativity of the operators +
  4. +
  5. To learn how to evaluate an expression by evaluating its sub expressions +
  6. + +

    +
+
+ - - - - - -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp2/Theory.html b/src/lab/exp2/Theory.html index 32e09134..73a82d12 100644 --- a/src/lab/exp2/Theory.html +++ b/src/lab/exp2/Theory.html @@ -1,257 +1,85 @@ - - - - - - - - - - Welcome to Virtual Labs - A MHRD Govt of india Initiative - - - - - - - - - - - - - - - - - - -
-
- - + + OJ + + + + + +
+
+ +
+ +
+

Theory

+

Problem 1

+
  P is divisor of Q, if dividing Q by P does not leave any remainder. A number, N, is called a perfect number, if the sum of all such divisors of N(not including N) is equal to N. 6 is the smallest perfect number. It's factors are 1,2,3 and their sum is 1+2+3=6. So, to check whether a number, say N, is perfect or not, it is required to find all the divisors of that number. The easiest way to do this is to check every number form 2 to N-1 if it is dividing N completely or not, and take the sum of all the divisor. While this may work well for small numbers, it would be very time consuming for large numbers.
+
+        A better solutin can be built by observing that many numbers can easily be ruled out as not divisors. For instance, all the numbers between N/2 and N cannot be divisors. Similarly, all numbers between N/2 and N/3 cannot be divisors of N, and so on. So, at each step we can check two numbers to be divisors of N and at the same time we can eliminate a fraction of the numbers less than N as not divisors and putting an upper bound on the next biggest possible divisor. Lets apply this tactic to find the divisors of 60.
+
+60 divided by 2 gives 30 as the quotient and 0 as the remainder. So, 2 and 30 are divisors and there are no other divisors greater than 30. SUM=32+1=33
+60 divided by 3 gives 20 as the quotient and 0 as the remainder. So, 3 and 20 are divisors and there are no other divisors greater than 20. SUM=33+23=46
+60 divided by 4 gives 15 as the quotient and 0 as the remainder. So, 4 and 15 are divisors and there are no other divisors greater than 15. SUM=46+19=65
+60 divided by 5 gives 12 as the quotient and 0 as the remainder. So, 5 and 12 are divisors and there are no other divisors greater than 12. SUM=65+17=82
+60 divided by 6 gives 10 as the quotient and 0 as the remainder. So, 6 and 10 are divisors and there are no other divisors greater than 10. SUM=82+16=98
+60 divided by 7 gives 8 as the quotient and 4 as the remainder. So, 7 is not a divisor and there are no other divisors greater than or equal to 8.
 
-	
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Beauty of Numbers

-
-

Problem 1

-

-P is divisor of Q, if dividing Q by P does not leave any remainder. A number, N, is called a perfect number, if the sum of all such divisors of N(not including N) is equal to N. 6 is the smallest perfect number. It's factors are 1,2,3 and their sum is 1+2+3=6. So, to check whether a number, say N, is perfect or not, it is required to find all the divisors of that number. The easiest way to do this is to check every number form 2 to N-1 if it is dividing N completely or not, and take the sum of all the divisor. While this may work well for small numbers, it would be very time consuming for large numbers. -

-

-A better solutin can be built by observing that many numbers can easily be ruled out as not divisors. For instance, all the numbers between N/2 and N cannot be divisors. Similarly, all numbers between N/2 and N/3 cannot be divisors of N, and so on. So, at each step we can check two numbers to be divisors of N and at the same time we can eliminate a fraction of the numbers less than N as not divisors and putting an upper bound on the next biggest possible divisor. Lets apply this tactic to find the divisors of 60. -

-

-60 divided by 2 gives 30 as the quotient and 0 as the remainder. So, 2 and 30 are divisors and there are no other divisors greater than 30. SUM=32+1=33
-60 divided by 3 gives 20 as the quotient and 0 as the remainder. So, 3 and 20 are divisors and there are no other divisors greater than 20. SUM=33+23=46
-60 divided by 4 gives 15 as the quotient and 0 as the remainder. So, 4 and 15 are divisors and there are no other divisors greater than 15. SUM=46+19=65
-60 divided by 5 gives 12 as the quotient and 0 as the remainder. So, 5 and 12 are divisors and there are no other divisors greater than 12. SUM=65+17=82
-60 divided by 6 gives 10 as the quotient and 0 as the remainder. So, 6 and 10 are divisors and there are no other divisors greater than 10. SUM=82+16=98
-60 divided by 7 gives 8 as the quotient and 4 as the remainder. So, 7 is not a divisor and there are no other divisors greater than or equal to 8.
-

-

-

Now, we see that there is no need to see any more divisors. The divisors of 60 are 2,30,3,20,4,15,5,12,6 and 10. And their sum is 97. So, 60 is not a perfect number. Lets try this procedure on 28 which is the next prefect number after 6. -

-

-28 divided by 2 gives 14 as the quotient and 0 as the remainder. So, 2 and 14 are divisors and there are no other divisors greater than 14. SUM=1+16=17
-28 divided by 3 gives 9 as the quotient and 2 as the remainder. So, 3 is not a divisor and there are no other divisors greater than or equal to 9. SUM=17
-28 divided by 4 gives 7 as the quotient and 0 as the remainder. So, 4 and 7 are divisors and there are no other divisors greater than 7. SUM=17+11=28
-28 divided by 5 gives 5 as the quotient and 3 as the remainder. So, 5 is not a divisor and there are no other divisors greater than 5. SUM=28
-

-

-We need not check any more numbers. The SUM is 28, and hence, 28 is a perfect number. -

-
-

Problem 2

-
-

-Consider the fraction A/B. We use two variables A,B to represent a fraction. Lets see how can we solve the -problem. A/B = q + 1/E. How can we find q,E given A,B such that E&gt1.; From math basics any fraction can be -expressed A/B = step(A/B) + frac(A/B). frac(A/B)< 1 so 1/frac(A/B) > 1. Thus we shall choose q as step(A/B) -and E as 1/frac(A/B). Now we shall see programatically how can we represent and E as we need to do the same -operation on E. Obviosuly from the above equation E = B/(A-B*q) which means E is also a fraction. Thus -we express E in terms of some (x,y) where x = B and y = A-B*q and do the same operation as we have done on (A,B). -It is recommended to use while loop and handle the termination case properly while coding. -

-
-
-
- - - - - -
- - +28 divided by 2 gives 14 as the quotient and 0 as the remainder. So, 2 and 14 are divisors and there are no other divisors greater than 14. SUM=1+16=17 +28 divided by 3 gives 9 as the quotient and 2 as the remainder. So, 3 is not a divisor and there are no other divisors greater than or equal to 9. SUM=17 +28 divided by 4 gives 7 as the quotient and 0 as the remainder. So, 4 and 7 are divisors and there are no other divisors greater than 7. SUM=17+11=28 +28 divided by 5 gives 5 as the quotient and 3 as the remainder. So, 5 is not a divisor and there are no other divisors greater than 5. SUM=28 +We need not check any more numbers. The SUM is 28, and hence, 28 is a perfect number. -
- - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp3/Objective.html b/src/lab/exp3/Objective.html index 040e9a11..5cca27b8 100644 --- a/src/lab/exp3/Objective.html +++ b/src/lab/exp3/Objective.html @@ -1,219 +1,59 @@ - - + + OJ + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

More on Numbers

-

- To learn to solve problems related to Number Theory using Computer Programming. -

-
-
+
+
+ +
+ +
+

Objective

+

    +
  1. To learn about the meaning of operators +
  2. +
  3. To learn about the precedence and assosciativity of the operators +
  4. +
  5. To learn how to evaluate an expression by evaluating its sub expressions +
  6. + +

    +
+
+ - - - - - -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp3/Theory.html b/src/lab/exp3/Theory.html index 70ad7f5a..401c6123 100644 --- a/src/lab/exp3/Theory.html +++ b/src/lab/exp3/Theory.html @@ -1,296 +1,122 @@ - - - - - - - - - - Welcome to Virtual Labs - A MHRD Govt of india Initiative - - - - - - - - - - - - - - - - - - -
-
- - -
- -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

More on Numbers

-

Problem 1

-

-Lets look at the remainder after with 9 for 10,100,1000,10000 etc. It is equal to 1 in all the cases. It is not difficult of see that for multiples of these numbers, the remainder after division with 9 will only depend on the multiple. So, for 20,40,800,500,7000,2000 etc., the remainder after division with 9 are 2,4,8,5,7 and 2. Now, any number, say N, written as sequence, WXYZ can be expressed as: -

-

-N=W*1000*X+100+Y*10+Z
-eg: For N=3548
-N=3*1000+5*100+4*10+8
-


-

-So, clearly the remainder after divison with 9 depends upon remainder after division with 3000, 500, 40 and 8, which are 3, 5, 4, and 8 respectively. Hence, the divisibility test for 9 states that a number is divisible by 9 if the sum digits of the number is divisible by 9. How to check whether sum of the digits is divisible by nine? Keep on doing the same test on the sum until the problem becomes trivial. -

-

-So, how do we find the sum of the digits of a number. For this one can repeatedly take mod of the number by 10 and then divide the number by 10, until the number becomes less than 10. For example:
-346 gives 6 as the remainder SUM=6
-34 gives 4 as the remainder SUM=10
-3 gives 3 as remainder SUM=13
-



-

-Now repeat the same procedure with SUM=13
-13 gives 3 as the remainder SUM=3
-1 gives 1 as the remainder SUM=4
-Now, SUM=4 is not divisible by 9. Hence, 346 is not divisible by 9.
-



- -

-
-

Problem 2

-

-Suppose the number we require is say (X[0],X[1],...,X[N]). We dont know what X[0] ,X[1],...X[N-1] are -and also the value of N. But fortunately we know some properties about this number with which we can find -out what number it is. We know the value of X[N]. Let take the sample input. X[N] = 4 in that case. -Say we represent the product as (P[0],P[1],...,P[M]). Now X[N] = 4 and when we multiply it with -X[N] we get 16(which is 4*4), which implies P[M]=6.Since the number has to be circular it is obvious -that X[N-1] must be 6.Now again multiplying X[N-1] = 6 with X[N]=4 and yea dont forget to add the carry which -we obtained in previous step.So P[M-1] = (6*4 + 1)%10 = 5 and carry is 2 this time. So we carry on like this. -

-Step1: xxxxxx4
-*4
-------
-6 and carry = 1
-------
-Step2:
-xxxxx64
-*4
-------
-56 and carry = 2
-------
-Step3:
-xxxx564
-*4
-------
-256 and carry = 2
-------
-Step4:
-xxx2564
-*4
-------
-0256 and carry = 1
-------
-Step5:
-xx02564
-*4
-------
-10256 and carry = 0
-------
-Step6:
-x102564
-*4
-------
-410256 and carry = 0
-------
- -At step 6, you can observe that the number is exactly the circular number. So we stop doing it. -The stopping criteria is simple. The carry must be 0 and the units digit with which we multiply -must be same as the last digit generated in the product. Here multiplication digit is 4. Thus the output is 102564. - - -




































-

-
-
+ + OJ + + + + +
- - - - +
+ +
+
+ +
+
+
+ +
+ +
+

Theory

+

Problem 1

+
     Lets look at the remainder after with 9 for 10,100,1000,10000 etc. It is equal to 1 in all the cases. It is not difficult of see that for multiples of these numbers, the remainder after division with 9 will only depend on the multiple. So, for 20,40,800,500,7000,2000 etc., the remainder after division with 9 are 2,4,8,5,7 and 2. Now, any number, say N, written as sequence, WXYZ can be expressed as
+        N=W*1000*X+100+Y*10+Z
+        eg: For N=3548
+        N=3*1000+5*100+4*10+8
+        So, clearly the remainder after divison with 9 depends upon remainder after division with 3000, 500, 40 and 8, which are 3, 5, 4, and 8 respectively. Hence, the divisibility test for 9 states that a number is divisible by 9 if the sum digits of the number is divisible by 9. How to check whether sum of the digits is divisible by nine? Keep on doing the same test on the sum until the problem becomes trivial.
+
+        So, how do we find the sum of the digits of a number. For this one can repeatedly take mod of the number by 10 and then divide the number by 10, until the number becomes less than 10. For example:
+	346 gives 6 as the remainder  SUM=6
+	34 gives 4 as the remainder   SUM=10
+	3 gives 3 as remainder        SUM=13
 	
-    
-
-    
-    
-
-	
-    
-    
-    
-	
+	Now repeat the same procedure with SUM=13 
+	13 gives 3 as the remainder   SUM=3
+	1 gives 1 as the remainder    SUM=4
 	
-	
+
+

+

Problem 2

+
	Suppose the number we require is say (X[0],X[1],...,X[N]) . We dont know what X[0] ,X[1],...X[N-1] are 
+	and also the value of N. But fortunately we know some properties  about this number with which we can find
+	out what number it is :) . We know the value of X[N]. Let take the sample input. X[N] = 4 in that case. 
+	Say we represent the product as (P[0],P[1],...,P[M]). Now X[N] = 4 and when we multiply it with 
+	X[N] we get 16(which is 4*4), which implies  P[M]=6.Since the number has to be circular it is obvious
+	that X[N-1] must be 6.Now again multiplying X[N-1] = 6 with X[N]=4 and yea dont forget to add the carry which 
+	we obtained in previous step.So P[M-1] = (6*4 + 1)%10 = 5 and carry is 2 this time.So we carry on like this.
+	

+ Step1: xxxxxx4 + *4 + ------ + 6 and carry = 1 + ------ + Step2: + xxxxx64 + *4 + ------ + 56 and carry = 2 + ------ + Step3: + xxxx564 + *4 + ------ + 256 and carry = 2 + ------ + Step4: + xxx2564 + *4 + ------ + 0256 and carry = 1 + ------ + Step5: + xx02564 + *4 + ------ + 10256 and carry = 0 + ------ + Step6: + x102564 + *4 + ------ + 410256 and carry = 0 + ------ + + At step 6 you can observe that the number is exactly the circular number. So we stop doing it. + The stopping criteria is simple. The carry must be 0 and the units digit with which we multiply + must be same as the last digit generated in the product(Here multiplication digit is 4) + Thus the output is 102564 + +
+ + +
+
+ + - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp4/Objective.html b/src/lab/exp4/Objective.html index 9644003b..5cca27b8 100644 --- a/src/lab/exp4/Objective.html +++ b/src/lab/exp4/Objective.html @@ -1,219 +1,59 @@ - - + + OJ + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Factorials

-

- To learn to solve problems related to Factorials using Computer Programming. -

-
-
+
+
+ +
+ +
+

Objective

+

    +
  1. To learn about the meaning of operators +
  2. +
  3. To learn about the precedence and assosciativity of the operators +
  4. +
  5. To learn how to evaluate an expression by evaluating its sub expressions +
  6. + +

    +
+
+ - - - - - -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp4/Theory.html b/src/lab/exp4/Theory.html index 21dbaa2d..0a5d0f78 100644 --- a/src/lab/exp4/Theory.html +++ b/src/lab/exp4/Theory.html @@ -1,288 +1,131 @@ - - - - - - - - - - Welcome to Virtual Labs - A MHRD Govt of india Initiative - - - - - - - - - - - - - - - - - - -
-
- - -
- -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Factorials

-

Problem 1

-

-We shall try to calculate the factorial of a number and then find out the number of digits in it.
-1! = 1
-2! = 1*2 = 2
-3! = 1*2*3 = 6
-4! = 1*2*3*4 = 24
-.
-.
-.
-10! = 3628800
-So n! means multiplying all the numbers from 1 to n. For the sample input, 52, we can see from the sample output that the factorial of 52 is 68 digits and this cannot fit in long long data type in C. You may now attempt to store the answer in a string and do multiplication operation on strings(by multiplying each digit of the string individually). Now, let us see how many operations do we need for multiplying 2 strings. Consider 11!, 11! = 11*10!, assume we already have 10! stored in a string and 11 stored in a string. Now, to calculate 11! from 10! we need to multiply each digit of 11 with each digit of 10!, i.e it would take No_digits(11) * No_digits(3628800) = 2*7 = 14 operations. We consider only multiplication operations(we also have to consider addition operations for each of the biproducts and carries).
-

-

-Similarly 53! would take 2*68=136 operations from 52!.
-52! would take 2*67 = 134 operations from 51!
-51! would take 2*65 = 130 operations from 50!.
- -We can see that there would be a operations required for calculating 53! (No_operations = 136+134+130+...+1). Also in 1000000! the number of digits is 5565709, so we would require large amount of storage and both these difficulties make calculation of N! hard.
-

-

-Is there any way to find the number of digits without actually calculating N!? Let us consider a simple problem of finding the number of digits in a number N.Consider N = 12 , we can also write this as 0.12*102 which is a 2 digit number . Consider N=125 , which can be written as 0.125 *103 which is a 3 digit number. Evidently calculating the exponent of 10 in the scientific notaion and gives the number of digits.
- -For any N,
-N=x*10exp
-=> log10(N) = log10(x) + exp.
-For n=95,
-log10(95) = log10(0.95)+exp, since 95 = 0.95 *102
-N = x*10exp , x < 1
-Taking step on both sides.
-=> step(log10(N)) = step(log10(x)+exp)
-=> step(log10(N)) = exp-1
-=> exp = step(log10(N))+1
-=> No_digits(N) = step(log10(N))+1
-

-

-Applying the above formula to calculate the number of digits of N! gives
-No_digits(N!) = step(log10(N!) ) +1
-=> No_digits(N!) = step(log10(N*(N-1)*(N-2)*(N-3)...*2*1)) + 1
-=> No_digits(N!) = step(log10(N) + log10(N-1) + log10(N-2) + ...+log10(2) + log10(1) ) +1

-

-log10(N) can be easily calculated by the log10 function in math.h.
-

-

-
-

Problem 2

-

-Let us observe the zeroes in the factorial of a few numbers.
- -4!=24 (0 zeroes)
-5!=120 (1 zeroes)
-6!=720 (1 zeroes)
-7!=5040 (1 zeroes)
-8!=40320 (1 zeroes)
-9!=362880 (1 zeroes)
-10!=3628800 (2 zeroes)
-11!-14! (2 zeroes)
-15! (3 zeroes)
-

-

-We can observe that for every multiple of 5, we have a zero being added to the product. This is due to the multiplication of 5 with an even number in the product. So, our problem simplifies to counting the number of 5's in the factors of the number to be calculated. Let us formalize the proof.
-

-

-Let p be a prime number.
- -n!=1×2×…×(n−1)×n
-We see that any integer m such that 0 < m ≤ n which is divisible by pj and not p(j+1) must be counted exactly j times. That is: once in ⌊n/p⌋, once in ⌊n/(p2)⌋, …, once in ⌊n(pj)⌋. And that is all the occurrences of p as a factor of n!.
-Thus:
-μ(No. of occurences of p)=⌊n/p⌋+⌊n/(p2)⌋+⋯+⌊n/(pj)⌋
-Ex:Number of zeroes in 25! = Number of occurences of 5 in 25! = (⌊25/5⌋+⌊25/(5^2)⌋)=5+1=6
-

-

-
-
+ + OJ + + + + +
- - - - +
+ +
+
+ + +
+
+ +
+ +
+

Theory

+

Problem 1

+
	We shall try to calculate the factorial of a number  and then find out the number of digits in it.
+        1! = 1
+       	2! = 1*2 = 2
+	3! = 1*2*3 = 6
+        4! = 1*2*3*4 = 24
+	.
+	.
+	.
+	10! = 3628800
+ 	So n! means multiplying all the numbers from 1 to n.
+	For the sample Input 52 we can see from the sample output that the factorial of 52 is
+	68 digits and this cannot fit in long long data type in C.You may now attempt to
+	store the answer in a string and do multiplication operation on strings(by multiplying each digit
+	of the string individually). Now let us see how many operations do we need for multiplying 2 
+	strings.Consider 11!, 11! = 11*10!, assume we already have 10! stored in a string and 11 stored in a string.
+	Now to calculate 11! from 10! we need to multiply each digit of 11 with each digit of 10! i.e it would 
+	take No_digits(11) * No_digits(3628800) = 2*7 = 14 operations.We consider only multiplication operations 
+	(we also have to consider addition operations for each of the biproducts and carries).
+
+	Similarly 53! would take 2*68=136 operations from 52!.
+	52! would take 2*67 = 134 operations from 51! 
+	51! would take 2*65 = 130 operations from 50!.
+	 
+        We can see that there would be a operations required for calculating  53! (No_operations = 136+134+130+...+1)
+	Also in 1000000! the number of digits is 5565709, so we would require large amount of storage and both these 
+	difficulties make calculation of  N! hard.
+
+
+	Is there any way to find the number of digits without actually calculating N!? Let us consider a simple problem
+	of finding the number of digits in a number N.Consider N = 12 , we can also write this as 0.12*10^2 which is a 2 
+	digit number . Consider N=125 , which can be written as 0.125 *10^3 which is a 3 digit number. Evidently calcula-
+	-ting the exponent of 10 in the scientific notaion and gives the number of digits.For any N ,N=x*10^exp 
+        => log10(N) = log10(x) + exp. for n=95 log10(95) = log10(0.95)+exp since 95 = 0.95 *10^2. 
+	N = x*10^exp , x<1 
+	Taking step on both sides . 
+	=> step(log10(N)) = step(log10(x)+exp) 
+	=> step(log10(N)) = exp-1 
+	=> exp = step(log10(N))+1
+	=> No_digits(N) = step(log10(N))+1
 	
-    
+	Applying the above formula to calculate the number of digits of N! gives
+	No_digits(N!) = step(log10(N!) ) +1
+	=> No_digits(N!) = step(log10(N*(N-1)*(N-2)*(N-3)...*2*1)) + 1
+	=> No_digits(N!) = step(log10(N) + log10(N-1) + log10(N-2) + ...+log10(2) + log10(1) ) +1
 
-    
-    
-
-	
-    
-    
-    
-	
-	
-	
+	4!=24		(0 zeroes)
+	5!=120		(1 zeroes)
+	6!=720		(1 zeroes)
+	7!=5040		(1 zeroes)
+	8!=40320	(1 zeroes)
+	9!=362880	(1 zeroes)
+	10!=3628800	(2 zeroes)
+	11!-14!		(2 zeroes)
+	15!		(3 zeroes)
+	We can observe that for every multiple of 5, we have a zero being added to the product. This is due to the
+	multiplication of 5 with an even number in the product. So, our problem simplifies to counting the number of 5's
+	in the factors of the number to be calculated.
+	
+	Let us formalize the proof.
+	Let p be a prime number.
+
+	n!=1×2×…×(n−1)×n
+	We see that any integer m such that 0 < m ≤ n which is divisible by p^j and not p^(j+1) must be counted exactly j
+	times.
+	That is: once in ⌊n/p⌋, once in ⌊n/(p^2)⌋, …, once in ⌊n(p^j)⌋.
+	And that is all the occurrences of p as a factor of n!.
+	Thus:
+	μ(No. of occurences of p)=⌊n/p⌋+⌊n/(p^2)⌋+⋯+⌊n/(p^j)⌋
 	
+Ex:No. of zeroes in 25!(No of occurences of 5 in 25!)=(⌊25/5⌋+⌊25/(5^2)⌋)=5+1=6
 
+
- \ No newline at end of file +
+
+ + + + + \ No newline at end of file diff --git a/src/lab/exp5/Objective.html b/src/lab/exp5/Objective.html index 9546fdfc..5cca27b8 100644 --- a/src/lab/exp5/Objective.html +++ b/src/lab/exp5/Objective.html @@ -1,218 +1,59 @@ - - + + OJ + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

String Operations

-

- To learn to solve problems related to Strings using Computer Programming. -

-
-
+
+
+ +
+ +
+

Objective

+

    +
  1. To learn about the meaning of operators +
  2. +
  3. To learn about the precedence and assosciativity of the operators +
  4. +
  5. To learn how to evaluate an expression by evaluating its sub expressions +
  6. + +

    +
+
+ - - - - - -
- - - -
- - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp5/Theory.html b/src/lab/exp5/Theory.html index e559a3cd..85d396b1 100644 --- a/src/lab/exp5/Theory.html +++ b/src/lab/exp5/Theory.html @@ -1,264 +1,93 @@ - - - - - - - - - - Welcome to Virtual Labs - A MHRD Govt of india Initiative - - - - - - - - - - - - - - - - - - -
-
- - -
- -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

String Operations

-

Problem 1

-
-

-A palindrome is a string which reads same wheter it is read from start to end of from end to the start. In literature, however, even the capitalization of words and punctuations are ignored. So, "Rats live on no evil stars." is also a palindrome. Detection of such palindromes can be done by creating a new string in which all the punctuations have been removed and all the upper case characters have been converted to lower case characters, and then doing a test for plaindome on the new string. -

-

-Alternatively, one can create two indices and put them at the end and beginning of the string. The index at the beginning moves towards the end and vice versa. If a character at any of the indices is not an alphabet the corresponding indice is moved until an alphabet is encountered. If the alphabet is in Upper case, then it is converted into lower case. Now, the values at the indices are compared and if they are not same then the string is not a palindome. Otherwise, the check is repeated for new values of indices obtained by moving them by suffiecient amount so that an alphabet is encountered. If at any time the indices are coincident or the indices cross each other, then the string is a palindrome. -

-

-
-

Problem 2

-

-Inorder to obtain string2 from string1 by deleting 0 or more characters it is fairly obvious that the characters in string2 must appear in the same order as in string1. -
-

-

-

Mathematical formulation

-

Suppose the length of string A is M and string B is N we need to find a N tuple (X[0],X[1],...,X[N-1]) -such that X[i] < X[i+1] for 0<=i<=N-2 and A[X[i]] = B[i] for 0<=i<=N-1. Why this formulation is correct? -B[0] occurs at X[0]
-B[1] occurs at X[1]
-..
-..
-..
-B[N-1] occurs at X[N-1]
-

-

-Now, we remove all other characters from A except those which appear at positions indicated by array X. Then we get string B.Thus the problem formulation is correct. The order constraint between X[i]'s is element because we want the characters in B to appear in order in A. -
-

-
-

Solution

-

So now once we have stated the problem mathematically we would like to know how can we find -array X subjected to the constraints mentioned.Lets see how can we find X[0]. You must be apply -the same logic on how to find other values of array X once you are familier with X[0]. -X[0] has only one constraint to be satisfied which is A[X[0]] = B[0] . There can be many values -of X[0] which can satisfy the above constraint. So which value should X[0] take? -
-
-

-

Proofs

-

-Suppose S is a set of values which X[0] can take. We prove that X[0] should take the minimum value, amongst all the members of set S. If |S|=1 , then it is obviously valid. So, assume |S|>=2. We will deal with |S|=0 case later. Lets say X[0] = b and the minimum value of the set S is a i.e a < X[0]. Since we have choosen X[0] as b we need to search for B[1] [b+1 m] beacuse B[1]> B[0]. It can happen that B[1] is not present in [b+1 m] at all which would imply that string B cannot be a subsequence of string A. But suppose the character is present in [a+1 b] and X[0]=a then it is possible that string B might be a subsequence of string A. Thus, X[0] must take the minimum value of set S i.e the position where first B[0] is same as chracter of A should be chosen as X[0]. -

-

-Now, if X[0] = a, we shall search for X[1] in [a+1,M] and similarly X[2] in [X[1]+1,M] -and for X[i] in [X[i-1]+1,M].Thus if we can find the array X then we say YES else NO. -

-

-


-
+ + OJ + + + + +
- - - - - - - - - +
+ +
+
+ + +
+
+ +
+ +
+

Theory

+

Problem 1

+
   A palindrome is a string which reads same wheter it is read from start to end of from end to the start. In literature, however, even the capitalization of words and punctuations are ignored. So, "Rats live on no evil stars." is also a palindrome. Detection of such palindromes can be done by creating a new string in which all the punctuations have been removed and all the upper case characters have been converted to lower case characters, and then doing a test for plaindome on the new string. Alternatively, one can create two indices and put them at the end and beginning of the string. The index at the beginning moves towards the end and vice versa. If a character at any of the indices is not an alphabet the corresponding indice is moved until an alphabet is encountered. If the alphabet is in Upper case, then it is converted into lower case. Now, the values at the indices are compared and if they are not same then the string is not a palindome. Otherwise, the check is repeated for new values of indices obtained by moving them by suffiecient amount so that an alphabet is encountered. If at any time the indices are coincident or the indices cross each other, then the string is a palindrome.
 
-	
-    
-    
-    
-	
 	
-	
 	
+
+
+
+ + + - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp6/Objective.html b/src/lab/exp6/Objective.html index d0c37ebc..5cca27b8 100644 --- a/src/lab/exp6/Objective.html +++ b/src/lab/exp6/Objective.html @@ -1,218 +1,59 @@ - - + + OJ + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Recursion

-

- To learn to solve problems related to Recursion using Computer Programming. -

-
-
+
+
+ +
+ +
+

Objective

+

    +
  1. To learn about the meaning of operators +
  2. +
  3. To learn about the precedence and assosciativity of the operators +
  4. +
  5. To learn how to evaluate an expression by evaluating its sub expressions +
  6. + +

    +
+
+ - - - - - -
- - - -
- - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp6/Theory.html b/src/lab/exp6/Theory.html index 7e2949ba..b8d0bd33 100644 --- a/src/lab/exp6/Theory.html +++ b/src/lab/exp6/Theory.html @@ -1,255 +1,86 @@ - - - - - - - - - - Welcome to Virtual Labs - A MHRD Govt of india Initiative - - - - - - - - - - - - - - - - - - -
-
- - -
- -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Recursion

-

Problem 1

-

-Recursion can be applied to a problem if the problem for the given input can be expressed as dependent upon the solution of the same problem for simpler inputs. One has to hardcode the solution for some simple cases, so that this recursion does not go on endlessly. Now, the given problem of expressing a weight(W) as a sum of other weights can be expressed as the problem of choosing one weight(w) such that it is not greater than W and then solving the same problem for the remaining weight W-w. For this particular problem, the solution can be expressed easily by choosing all the possible multiples(m) of a given unit, 2^(i), iteratively for all the values of m for which m*2^(i) is less than W, and subsequently solving the same problem for the remaining weight, W-w, and for multiples of weights for higher order. So, our recursion function would be needing 2 variable, one signifying multiples of which order of weight should be used this time and other signifying remaining weight to be accrued. -

-

-
-

Problem 2

-

-Let us assume we have kept weight D on left pan. From amongst the N weights you can choose to keep some weights on left side and some weights on right side and we may not use some weights at all. Lets say we keep a total weight of w1 on left side and w2+D on right pan, then for balancing w1=w2+D.We keep track the difference between the two pans and if at any stage the difference of weights between two pans is 0 we report yes. Consider the ith weight and suppose the current difference between left pan and right pan is x. If x is 0 then yes we donot choose any weight and thus return 1. -

-

-Otherwise we have three options -

-
-

-Option1: - -Put the ith weight on right pan.In which case the difference between left and right pan becomes x - weight[i]. -
-Option2: -Put the ith weight on left pan.In which case the difference between left and right pan becomes x + weight[i]. -
-Option3: -Donot put the ith weight on either pan.In which case the difference between left and right pan remains x. -

-

-
-This gives the following Recursive Function : -

-

-Let F(i,x) denotes whether it is possible to obtain a difference of x using the weights
-w[i],w[i+1],...,w[n-1].
-Obviously, F(i,0) is 1, Otherwise
-F(i,x) = F(i+1,x)||F(i+1,x-w[i])||F(i+1,x+w[i]);
- -F(i+1,x) corresponds to Option3.
-F(i+1,x-w[i]) corresponds to Option1.
-F(i+1,x+w[i]) corresponds to Option2.
-






-

-

-
+ + OJ + + + + +
- - - - - - - - - - - - - - - +
+ +
+
+ + +
+
+ +
+ +
+

Theory

+

Problem 1

+
	        Recursion can be applied to a problem if the problem for the given input can be expressed as dependent upon the solution of the same problem for simpler inputs. One has to hardcode the solution for some simple cases, so that this recursion does not go on endlessly. Now, the given problem of expressing a weight(W) as a sum of other weights can be expressed as the problem of choosing one weight(w) such that it is not greater than W and then solving the same problem for the remaining weight W-w. For this particular problem, the solution can be expressed easily by choosing all the possible multiples(m) of a given unit, 2^(i),   iteratively for all the values of m for which m*2^(i) is less than W, and subsequently solving the same problem for the remaining weight, W-w, and for multiples of weights for higher order. So, our recursion function would be needing 2 variable, one signifying multiples of which order of weight should be used this time and other signifying remaining weight to be accrued.
+
+
+

+

Problem 2

+
	Let us assume we have kept weight D on left pan. From amongst the N weights you can choose to keep 
+	some weights on left side and some weights on right side and we may not use some weights at all.
+	Lets say we keep a total weight of w1 on left side and w2+D on right pan, then for balancing 
+	w1=w2+D.We keep track the difference between the two pans and if at any stage the difference of 
+	weights between two pans is 0 we report yes. Consider the ith weight and suppose the 
+	current difference between left pan and right pan is x.
+	If x is 0 then yes we donot choose any weight and thus return 1.
+	Otherwise we have three options
+	
+
Option1:
+ Put the ith weight on right pan.In which case the difference between left and right + pan becomes x - weight[i]. +
Option2:
+ Put the ith weight on left pan.In which case the difference between left and right + pan becomes x + weight[i]. +
Option3:
+ Donot put the ith weight on either pan.In which case the difference between left and right + pan remains x. - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp7/Objective.html b/src/lab/exp7/Objective.html index 930586b6..5cca27b8 100644 --- a/src/lab/exp7/Objective.html +++ b/src/lab/exp7/Objective.html @@ -1,218 +1,59 @@ - - + + OJ + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Advanced Arithmatic

-

- To learn to solve problems related to Advanced Arithmatic using Computer Programming. -

-
-
+
+
+ +
+ +
+

Objective

+

    +
  1. To learn about the meaning of operators +
  2. +
  3. To learn about the precedence and assosciativity of the operators +
  4. +
  5. To learn how to evaluate an expression by evaluating its sub expressions +
  6. + +

    +
+
+ - - - - - -
- - - -
- - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp7/Theory.html b/src/lab/exp7/Theory.html index ce699ce9..e255f699 100644 --- a/src/lab/exp7/Theory.html +++ b/src/lab/exp7/Theory.html @@ -1,235 +1,73 @@ - - - - - - - - - - Welcome to Virtual Labs - A MHRD Govt of india Initiative - - - - - - - - - - - - - - - - - - -
-
- - -
- -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Advanced Arithmatic

-

Problem 1

-
-

-If numbers are to big to fit into standard data types, then we can use strings to store the number. In this case, addition of two number would require doing digit by digit addition along with required carry over getting transferred to the next higher order cell. Lets suppose that the longer of two of the input numbers is of length L. Then the size of the result would be at maximum L+1. Now, for doing addition, you need to place two separate indices at the end of the two numbers annd do an addition of the two digits there. Beware that the two digits are stored in character format, so subtract 10 from each of them before adding them. If this addition results in a number greater than 10, then write down the unit digit of the result in right most cell of the result string and note down the carry forward. If the result of the addition is less than 10 then then no need to worry about the carry forward. Now repeat this process by having moved all the three indices one place to the left, and keep repeating till the longer of the two numbers is traversed. If one of the input number runs out of digits then assume it to be supplying 0. Finally, output the result string on the screen. - -

-

-
-

Problem 2

-
-

-A number x is said to be a square root of N if x*x=N.Thus is it quite obvious that the square root a positive integer > 1 lies in between [1 N]. Suppose P is a number such that P*P > N then the result must be in the interval [1 P-1] oterwise if P*P < N then the result lies in [P+1 N]. We use this idea to find the square root of a positive integer. Suppose we know that the square root lies in between (start,end).If mid = (start+end)/2.0, depending upon the value of mid*mid-N we chose either (mid+1,end) or (start,mid-1) as our next search interval or conclude that mid is the square root of N.While coding do take care of the fact of precision since mid*mid may not be exactly equal N. -
-

-

Time complexity

-
-

-If you analyze the number of operations it takes this function to run it is easy to see that it will take logN (logN to base 2) operations. At every step of the search we chose either (start,mid-1) or (mid+1,end) which means the interval size gets reduced by half. Initially the range is N, in the next step it will become N/2, then N/4, and so after x steps the search range will be N/(2^x) which will be 1 when x is logN. So, the number of iterations is log(N). -

-

-
-
+ + OJ + + + + +
- - - - +
+ +
+
+ + +
+
+ +
+ +
+

Theory

+

Problem 1

+
If numbers are to big to fit into standard data types, then we can use strings to store the number. In this case, addition of two number would require doing digit by digit addition along with required carry over getting transferred to the next higher order cell.
+        Lets suppose that the longer of two of the input numbers is of length L. Then the size of the result would be at maximum L+1. Now, for doing addition, you need to place two separate indices at the end of the two numbers annd do an addition of the two digits there. Beware that the two digits are stored in character format, so subtract 10 from each of them before adding them. If this addition results in a number greater than 10, then write down the unit digit of the result in right most cell of the result string and note down the carry forward. If the result of the addition is less than then then no need to worry about the carry forward. Now repeat this process by having moved all the three indices one place to the left, and keep repeating till the longer of the two numbers is traversed. If one of the input number runs out of digits then assume it to be supplying 0. Finally, output the result string on the screen.
+
+
+

+

Problem 2

+
	A number x is said to be a square root of N if x*x=N.Thus is it quite obvious that the square root a positive 
+	integer>1 lies in between [1 N]. Suppose P is a number such that P*P> N then the result must be in the interval 
+	[1 P-1] oterwise if P*P< N then the result lies in [P+1 N]. We use this idea to find the square root of a positive
+	integer. Suppose we know that the square root lies in between (start,end).If mid = (start+end)/2.0, depending 
+	upon the value of mid*mid-N we chose either (mid+1,end) or (start,mid-1) as our next search interval
+	or conclude that mid is the square root of N.While coding do take care of the fact of precision since 
+	mid*mid may not be exactly equal N. 
+	

Time complexity

+ If you analyze the number of operations it takes this function to run it is easy to see that + it will take logN (logN to base 2) operations. At every step of the search we chose either + (start,mid-1) or (mid+1,end) which means the interval size gets reduced by half.Initially + the range is N, in the next step it will become N/2 , then N/4,...and so after x steps the search + range will be N/(2^x) which will be 1 when x is logN.So the number of iterations is logN. - +
- - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp8/Objective.html b/src/lab/exp8/Objective.html index 04b60c35..5cca27b8 100644 --- a/src/lab/exp8/Objective.html +++ b/src/lab/exp8/Objective.html @@ -1,218 +1,59 @@ - - + + OJ + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Searching and Sorting

-

- To learn to solve problems related to Searching and Sorting using Computer Programming. -

-
-
+
+
+ +
+ +
+

Objective

+

    +
  1. To learn about the meaning of operators +
  2. +
  3. To learn about the precedence and assosciativity of the operators +
  4. +
  5. To learn how to evaluate an expression by evaluating its sub expressions +
  6. + +

    +
+
+ - - - - - -
- - - -
- - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp8/Theory.html b/src/lab/exp8/Theory.html index 6166b82f..7bfc1958 100644 --- a/src/lab/exp8/Theory.html +++ b/src/lab/exp8/Theory.html @@ -1,227 +1,69 @@ - - - - - - - - - - Welcome to Virtual Labs - A MHRD Govt of india Initiative - - - - - - - - - - - - - - - - - - -
-
- - + + OJ + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Searching and Sorting

-

Problem 1

-

-Consider three numbers from the set say a,b,c. If either a+b< c or b+c< a or c+a< b then (a,b,c) cannot form a triangle. Lets state the problem little differently for each pair (a,b) we want to find out how many numbers c are there such that a+b < c. We consider each pair (a,b) and search for how many numbers are there which are greater than a+b. This can be done easily using binary search. Sort the array and consider the interval (start,end). If arr[mid]> a+b then (mid-end+1) numbers are greater than a+b otherwise if arr[mid]< a+b then we don't add anything to the result and search in (start,mid-1). - -

-

-
-

Problem 2

-

-Consider the given string. We need to find the smallest substring which contains all the characters of the given set. Any substring which qualifies has to end with some character.For each index in the input string lets find out how much we have to extend from that point to the left so that we get all the characters in the input set. Lets say we are scanning the string from the left and we know the latest occurrences of the characters of input set in the input string, say they are stored in an array by name pos[]. From the i th character we need to extend to the minimum value in the pos[] array so that we get all the characters. For each index i we do this and report the minimum length. - -

-
-
+
+
+ +
+ +
+

Theory

+

Problem 1

+
	Consider three numbers from the set say a,b,c. If either a+b< c or b+c< a or c+a< b  then (a,b,c) cannot
+	form a triangle.Lets state the problem little differently for each pair (a,b) we want to find out how many 
+	numbers c are there such that a+b < c. We consider each pair (a,b) and search for how many numbers are there
+	which are greater than a+b. This can be done easily using binary search. Sort the array and 
+	consider the interval (start,end) . If arr[mid]> a+b then (mid-end+1) numbers are greater than a+b 
+	otherwise if arr[mid]< a+b then we dont add anything to the result and search in (start,mid-1). 
+
+

+

Problem 2

+ Consider the given string. We need to find the smallest substring which contains all the characters of the given set. + Any substring which qualifies has to end with some character.For each index in the input string lets find out how much + we have to extend from that point to the left so that we get all the characters in the input set. Lets say we are + scanning the string from the left and we know the latest occurrences of the characters of input set in the input string, + say they are stored in an array by name pos[]. From the i th character we need to extend to the minimum + value in the pos[] array so that we get all the characters. For each index i we do this and report the minimum length. + +
					
+
+
+				
+
+ - - - - - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp9/Objective.html b/src/lab/exp9/Objective.html index 838f9e52..5cca27b8 100644 --- a/src/lab/exp9/Objective.html +++ b/src/lab/exp9/Objective.html @@ -1,218 +1,59 @@ - - + + OJ + + + + + - -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Permutations

-

- To learn to solve problems related to Permutation using Computer Programming. -

-
-
+
+
+ +
+ +
+

Objective

+

    +
  1. To learn about the meaning of operators +
  2. +
  3. To learn about the precedence and assosciativity of the operators +
  4. +
  5. To learn how to evaluate an expression by evaluating its sub expressions +
  6. + +

    +
+
+ - - - - - -
- - - -
- - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/lab/exp9/Theory.html b/src/lab/exp9/Theory.html index 61e20e4f..c33b13f7 100644 --- a/src/lab/exp9/Theory.html +++ b/src/lab/exp9/Theory.html @@ -1,241 +1,77 @@ - - - - - - - - - - Welcome to Virtual Labs - A MHRD Govt of india Initiative - - - - - - - - - - - - - - - - - - -
-
- - -
- -
-
-
-
-
-
- - - -
-

Computer Science & EngineeringProblem Solving Lab →List Of Experiments

- -
- - -
- - -

Permutations

-

Problem 1

-
-

- Recursion can be applied to a problem if the problem for the given input can be expressed as dependent upon the solution of the same problem for simpler inputs. One has to hardcode the solution for some simple cases, so that this recursion does not go on endlessly. Now, the given problem of expressing a weight(W) as a sum of other weights can be expressed as the problem of choosing one weight(w) such that it is not greater than W and then solving the same problem for the remaining weight W-w. For this particular problem, the solution can be expressed easily by choosing all the weight(w) as the first weights one by one, also taking care the the total weight(S) is not greater than reqired weight W. Those weights which make the total weight(S) greater than W are exluded from the list of avaliable weights for the next recursive. Now we only have to solve the same problem for a simpler case to get the complete solution, i.e., solving the same problem for the remaining weight, W-w, and available pool of weights now also does not have w. If accumulated weight is equal to w, then we increment the counter. If at any time, the pool of remaining weights is exhausted, then that attempt is aborted. So, our recursion function would be needing 2 variables, one containing the list of available weights and the other signifying remaining weight to be accrued. - -

-

-
-

Problem 2

-
-

- For each weight in the input we keep it on right pan and try using other weights to balance it. Let us say we have kept ith weight on the right pan, out task is now to keep weights on left side of the pan so that the sum of the weights on left side of the pan is equal to the weight on the right side,i.e weight[i]. For each weight W[k], we can keep it either on left pan or we donot to keep it at all. Make sure to disregard the weight when k is equal to i because that weight is already on right side. -

-

Recursive formulation

-

- Let F(index,i,S) denotes the number of ways in which we can obtain weight[i] using weights from weight[index], weight[index+1], weight[index+2],..., weight[n-1] and currently because of choosing some weights from weight[0], weight[1],..., weight[index-1] the sum of the weights has become S. So we need to achieve weight[i]-S by choosing some weights from weight[index], weight[index+1],..., weight[n-1]. -

-

- A pseudo code would look like:
- - F(index,i,S) = F(index+1,i,S) If index=i
- = 1 If index=N and S=weight[i]
- = 0 If index=N and S!=weight[i]
- = F(index+1,i,S+weight[index])+F(index+1,i,S) otherwise
-

-

-
-
+ + OJ + + + + +
- - - - - - - - - - - - - - - +
+ +
+
+ +
+
+
+ +
+ +
+

Theory

+

Problem 1

+
This is a fairly straight-forward problem. We have to determine the length of the longest subsequence in which all the elements are smaller than the previous ones. It is easy to see that each of these decresing subsequences will end either when the current number is bigger than the previous number, or when the current number is the final number in the sequence. Also, the end of one sequence marks the beginning of another sequence. So, this problem is easy to
+solve if we can note down the lengths of these sequences and find the largest number in them. All this can be done while the input is being read. You just ne
+ed to keep track of the length of the current sequence and the length of the largest sequence which has been seen till now. As discussed earlier, if the curr
+rent number is lesser than the previous number then the length of the current sequence is incremented by 1, and if the current number is greater than the pre
+vious number, then the current sequnce ends and we check whether its length is the greatest that has been seen till now, and we also start a new sequence with length equal to 1. When, then input sequence ends then also the current sequence is deemed as terminated, and we again check its length against the length of the largest sequence seen till now.
+
+
+

+

Problem 2

+
	This is a very famous problem.Its known as longest increasing subsequence problem.Let us consider a
+	naive approach of solving this problem. For every subsequence if it is a increasing subsequence we 
+	try to update the maximum length of the longest increasing subsequence.If we analyse the time complexity
+	of this appraoch it is clear that it is goin to take 2^N * N operations.So if N = 30 , this approach would
+	take 32212254720 (~3*10^11) operations.Looking at the constraints it is obvious that this algorithm is not feasible.
+	Now we look at the standard solution.You may refer wikipedia for the same.
 	
-	
-	
-
-
 
-
\ No newline at end of file
+
\ No newline at end of file

From de34a03710addfd5f4b416487a7a21738e18fe9a Mon Sep 17 00:00:00 2001
From: manuchandu111 
Date: Wed, 24 Jun 2020 20:33:27 +0530
Subject: [PATCH 2/4] link was updated

---
 src/lab/exp9/Experiment.html | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lab/exp9/Experiment.html b/src/lab/exp9/Experiment.html
index 2fec8e42..6d6362b9 100644
--- a/src/lab/exp9/Experiment.html
+++ b/src/lab/exp9/Experiment.html
@@ -43,7 +43,7 @@
 			                    
 			                    
 			                
-			                
+			                
 			            
@@ -215,4 +215,4 @@

Follow Us

- \ No newline at end of file + From 0f62e46b9c8ac0fdc8f1d2ca18368193abc7f4d2 Mon Sep 17 00:00:00 2001 From: manuchandu111 Date: Wed, 24 Jun 2020 20:50:27 +0530 Subject: [PATCH 3/4] link was updated --- src/lab/TargetAudience.html | 219 ++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 src/lab/TargetAudience.html diff --git a/src/lab/TargetAudience.html b/src/lab/TargetAudience.html new file mode 100644 index 00000000..d0e1340b --- /dev/null +++ b/src/lab/TargetAudience.html @@ -0,0 +1,219 @@ + + + + + + + + + + Welcome to Virtual Labs - A MHRD Govt of india Initiative + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+
+
+
+
+
+ + + +
+

Computer Science & Engineering

+ +
+ + +
+ + +

Problem Solving Lab

+

The experiments are targeted at students who have just finished a first course in programming. Knowledge of writing programs in any programming language is expected. No prior experience with data structuers is required. +

+
+
+
+ + + + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + From 128dd3c78978cf893e21b212ae2501fa4d5e9e2e Mon Sep 17 00:00:00 2001 From: manuchandu111 Date: Mon, 29 Jun 2020 12:28:17 +0530 Subject: [PATCH 4/4] link was updated --- src/lab/List_of_experiments.html | 259 +++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 src/lab/List_of_experiments.html diff --git a/src/lab/List_of_experiments.html b/src/lab/List_of_experiments.html new file mode 100644 index 00000000..3b335f55 --- /dev/null +++ b/src/lab/List_of_experiments.html @@ -0,0 +1,259 @@ + + + + + + + + + + Welcome to Virtual Labs - A MHRD Govt of india Initiative + + + + + + + + + + + + + + + + + + +
+
+ + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + +