counting


Binary Strings of the form *111*


Given an integer N, we have to count the number of possible binary strings(string is madeup of only 0s and 1s) of length N, and matches the regular expression pattern [111]. For example if N is 4, then 1110 , 0111 , 1111 are the possibilities.
I have worked on it, and have got the following recurrence:
count(a,N) = 4*count(0,N-3) + 2*count(1,N-3)+ count(2,N-3); if(a == 0)
count(a,N) = 2*count(0,N-2)+ count(1,N-1); if(a == 1)
count(a,N) = count(0,N-1); if(a == 2)
Answer is [(2^N) - Count(0,N)].
By using memorization, we can compute the the Count(0,N) in O(N).
but is there any better algorithm other than O(N)
Without completely answering your homework, try combinatorics,
For length N,
There are (N-2) ways to place a 111 in the block (Starting at the 0 index, 1 index, 2 index).. And then 2^(n-3) ways to fill the remaining space.
You just need to be careful about dupes..

Related Links

How to answer queries of type l,r,k which finds number of elements in an array in range l to r which occurs atleast k times?
Dafny and counting of occurences
Counting the number of capital letters in each row in [R]
python: count values of dictionary
How to apply hyperloglog to a timeseries stream
Counting the number of occurrences of C in each line and outputting this number plus the total number of characters in that line
Digit Counting Issue in C++ Program
Binary Strings of the form *111*

Categories

HOME
hpoo
office365
windows-8.1
yii
android-fragments
barcode-scanner
writefile
windows-10
whmcs
portable-class-library
lvm
openflow
save
port
yeoman-generator-angular
vimeo
squirrel-sql
trace32
mailgun
corona
texas-instruments
android-5.1.1-lollipop
clr
pe
el
candlestick-chart
tortoisemerge
tf-idf
annotation-processing
openbr
google-play-developer-api
winrm
gnu-classpath
spring-rabbitmq
grails-2.5
des
iscroll
oauth2
imgur
oauth2-playground
type-inference
react-intl
xcode8.2
bit-shift
dredd
deployd
nusoap
ilrepack
word-2016
bigdecimal
java-2d
logical
tsqlt
msbuild-4.0
android-4.2-jelly-bean
apache-pig-grunt
jeditable
gravatar
univocity
outlook.com
knife
wso2ml
supercomputers
prism-4
camus
debug-symbols
pass-by-value
lifetime
flurry-analytics
angular-ui-select
xcode6.3.1
accessory
reference-counting
wso2bam
armv6
facebook-game-groups
visual-c++-2005
google-code-prettify
django-filebrowser
xmlwriter
user-forums
multiscaleimage
sfinae
hardcode
prototypal-inheritance
wiktionary
servlet-container
webresponse
gaelyk
downgrade
browser-based
tacit-programming
downloadfile

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile