Implementation of strstr function in Java
Write an efficient algorithm to implement the strstr
function in Java, which returns the index of the first occurrence of a string in another string.
- Implement strstr function in Java Iterative Implementation (Naive)
- Recursive Implementation
- Using KMP Algorithm (Efficient)
Details about strdup function
The function strdup() is used to duplicate a string. It returns a pointer to null-terminated byte string.
Comparing strcpy and strdup
Both copy a string. strcpy requires a buffer to copy into. strdup allocates a buffer using malloc().
Understanding strrev function
The strrev() function is a built-in function in PHP and is used to reverse a string. If a number is passed to it instead of a string, it will also reverse that number.
Comparing memcpy and memmove
When running memcpy twice, the second run is faster than the first one. If "touching" the destination buffer of memcpy, then the first run of memcpy is also faster. memcpy is slightly slower than memmove.
Difference between memmove and memcpy
memcpy() function is used to copy a specified number of bytes from one memory to another. memmove() function is used to copy a specified number of bytes from one memory to another or to overlap on the same memory.