0

Strings and binary numbers

can you help me to write code these problem above : Problem: Given two binary strings, A (of length 10) and B (of length 5), output 1 if B is a substring of A and 0 otherwise. Input: Binary string A and B separated by a space. Output: The logical value of: 'B is a substring of A'. ie. 1 if B is substring of A else 0. Constraints: Sample Input: 1010110010 10110 Sample Output: 1

8th Mar 2017, 11:20 AM
Mohamed Abdalla
Mohamed Abdalla - avatar
5 ответов
+ 8
Homework , isn't? Code it by yourself. If you have doubts or errors , post them here.
8th Mar 2017, 11:48 AM
Mr.Robot
Mr.Robot - avatar
+ 1
I know there approaches to solve this problem. 1. Naive Approach 2. Robin- corp algorithm 3. Kmp algorithm I can tell you about Naive method...others are matching algorithms , learn from google or cormen.
8th Mar 2017, 11:51 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
+ 1
1. Naive: start from starting of A, put B below it and match first data of B's from A's. if there is any match then check for next data of B's and A's. if you finding match keep doing it till last element of B. and if is not match move B by one. and start matching it from starting. run this loop till length of A- length of B. time complexity will be higher ~ (n-m) m (n for A and m for B) start coding in this approach if you struck somewhere I will help you.
8th Mar 2017, 11:57 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
+ 1
I am no sure I could make you understand or not. these things can be better explained on pen and paper.
8th Mar 2017, 11:58 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
0
hi Raj kumer! where's the code?
8th Mar 2017, 12:35 PM
Mohamed Abdalla
Mohamed Abdalla - avatar