This is a tutorial on how to create an animated pumpkin using JavaScript, CSS, and HTML. It’s so easy you’ll be able to make a pumpkin animated. Just open up a text editor and download our source code for free. Halloween Pumpkin Animation Tutorial Free – HTML CSS JavaScript
Problem 5:
I set this problem in the 2017 NCPC Contest Preliminaries. n to you
There is a bulb, initially all bulbs are off. You can randomly select a bulb on each move. Now if the bulb is off then you toss a coin, if you get heads then you turn the bulb on, if you get tails you do nothing. And if the bulb is already on then you don’t need to do anything in that move. Expected How many moves can you turn on all the bulbs? The coin is not a fair coin, the probability of getting a tail each time is p.
This problem should also be solved recursively. You basically need to know how many bulbs are currently on. Let x be present
The bulb is on and the expected move will be e(x). Then the probability of selecting a bulb that is already on is xn, in which case the expected move will take more \fractxn(1+e(x)) t. The probability of selecting a bulb that is already off is n−xn. In that case again 2 events can happen, you get tails with probability p and more e(x) moves, or heads with probability 1−p and more e(x+1) moves.
T move will be required.
The total equation will be e(x)=xn⋅(1+e(x))+n−xn⋅(p⋅(1+e(x))+(1−p)⋅(1+e(x+1) )
You can read this CodeChef article to know more about Expected Value. Check out lightoj’s Probability section for practice.
Happy Coding!
Halloween Pumpkin Animation Tutorial Free – HTML CSS JavaScript
Robin-Karp string matching
Rabin-carp is a string matching algorithm. Given two strings, this algorithm can tell whether the 2nd string is a substring of the first string. Robin-Karp performs string matching using the rolling hash technique. Although it is better to use the KMP algorithm for string matching, learning Robin-Karp is important mainly to learn how rolling hashes work.
Before reading this article, you should know about modular arithmetic.
While doing string matching, we will call the first string as Text and the second as Pattern. Our job is to find patterns in the text.
First we consider a bruteforce algorithm. We can extract each substring of the text and match it to the pattern:
The complexity of the naive string matching algorithm is O(n∗m), where n is the length of the text and m
is the length of the pattern.
If we compare two strings without looking for a single character like an integer then O(1)
If we could do this comparison, we could do string matching very quickly. Using hashing technique we can convert string into integer. Robin-Karp algorithm takes advantage of that.
We call any string a Base-B
can be visualized as a number where the value of B is equal to or greater than the number of characters in ASCII. Then we can write a function that converts s from Base-B numbers to Base-10
will convert to numbers. This could be our hash function:
Hash(s)=s0⋅Bm−1+s1⋅Bm−2+…+sm−1⋅B1+sm−1⋅B0
A string is passed as a parameter to this function. si
is the ASCII value of the ith character. Different hashvalues can be obtained for any string with this hash function. But the problem is overflow, the value of the hashvalue will easily become larger than 64-bits. For this we need to divide the hash value by M to get the quotient (modulo). Then the number is M
will be smaller than:
Hash(s)=(s0⋅Bm−1+s1⋅Bm−2+…+sm−1⋅B1+sm−1⋅B0) mod M
But the problem in this case is that the hash value of multiple strings can become the same. This problem is called hash collision. But B
And if M is a prime number and the value of M is very large then the probability of collision is very less. (However, even if the probability decreases, it does not become zero, which is why Robin Karp’s worst case complexity is O(n∗m)
, coming to that point later)
Now our first task will be to extract the hash value of the pattern. Then every m of text
The hash value for the substring of length must be extracted and matched with Hash(pattern). Now the question is how to find the hash value for each m length substring? If you pass each substring to the hash function above, the complexity becomes O(n∗m). We need to figure out a way to just run a loop over the string every m in O(n).
Halloween Pumpkin Animation Tutorial Free – HTML CSS JavaScript
Hashvalues can be extracted for substrings of length . This is where the rolling hash method comes in handy.
Think Hi
is m starting at the i-th index of s
The hash value of the length string. Then we can write:
Hi=si⋅Bm−1+si+1⋅Bm−2+…+si+m−1⋅B0
Now if m=3
Then H0 and H1
Who can write to:
Ho=so⋅B2+s1⋅B1+s2
H1=s1⋅B2+s2⋅B1+s3
Now look at H1
Who How H0
It can be expressed through:
H1=((so⋅B2+s1⋅B1+s2)–(so⋅B2))×B+s3
H1=(H0–So∗B2)⋅B+s3
Generally speaking:
Hi=(Hi−1–Si−1⋅Bm−1)⋅B+si+m−1
Now easily O(n) using this formula
The hash value of each substring of length m can be extracted. At the beginning, the hash value for the first m characters will be extracted and then the rest will be extracted using the rolling hash method.
The complexity of this code is O(n+m).
. But there is a big problem here. When hash_text and hash_pattern match we assume that the two strings are matched. But I said earlier that due to taking the mod, multiple strings may have the same hash value (collision). In that case this code will give wrong output.
One way to avoid errors due to collisions is to loop back character by character whenever hash_text = hash_pattern. But in that case the worst case complexity is O(n∗m)
Which is equivalent to brute force complexity.
Another way is to do double hashing. Double hashing means using different B and M to produce two hash values for each string. In that case the possibility of collision in both places will be greatly reduced. If desired, hashing can be done more than 2 times. Double hashing can get you through programming contests most of the time, but it’s not a very good way to do it in real life, because the probability of collision is reduced but not zero.
For these reasons, Robin-Karp is not used much for string matching, preferring to use KMP. But the rolling hash technique is useful for solving many types of problems, which is why we learn Robin-Karp.
Issues to ponder:
You have two strings s1,s2
is given You need to find the length of their longest common substring. That is to find the largest string which is a substring of two strings.
Solution:
First consider any integer k
For this you can find whether there is a longest common substring of length k. This can easily be derived in O(n) complexity using rolling hashes. Find the hash value of each length k substring of s1, then find the hash value of each k length substring of s2. If any hashvalue is common then k
There is a longest common substring of length
Now the maximum length of the longest common substring can be maxlen=min(s1.length,s2.length)
. Now you can easily solve the problem by doing a binary search on maxlen from 0. The complexity will be O(n⋅logn)
.
Happy Coding!
Before Download
You must Join our Facebook Group and Subscribe YouTube Channel
All Links in Below:
Join Our FreeWebsiteCreate Facebook Group to get an instant update for projects, templates, design resources, and solutions.
Join Our YouTube Channel & Subscribe with Bell Icon for New Video:
Join Our Official Facebook Page For the Latest updates All Code Projects are Free:
Visit our service page to get premium services.
Free Website Create – HTML CSS, PHP, JavaScript Programming Projects For Free
Follow Us
Thank You,
Before Download
You must Join our Facebook Group and Subscribe YouTube Channel
FreeWebsiteCreate.net tries to provide HTML, CSS, SCSS, JavaScript, React, Android Studio, Java, PHP, Laravel, Python, Django, C#(C Sharp), and ASP.net-related projects 100% free. We try to make learning easier. Free Website Create always tries to give free projects to those who are new learners. Free projects and source code will help to learn easily.
They can save time and learn more. In this post, we share a free portfolio project website code with HTML and CSS. This free code portfolio contains a single landing page with a responsive design. In this post, we get a free best carpenter and craftsman service website designed by FreeWebsiteCreate with HTML, CSS, Bootstrap, and JavaScript.