Write a program that checks if a string is a palindrome. What's its complexity?
Anonymous
So basically, if we picture a string as an array, and in Java we can read out a single character on a specific place(index) in a string, which takes constant time, we have to iterate through the half of a string and compare char at the index i ( i -> length) and at the index j ( j -> 0). To sum it up, the complexity is O(1 n/2) which is equal to O(n) since Big-Oh notation ignores constant terms So roughly, the upper bound - the worst-case scenario is: O( N
Check out your Company Bowl for anonymous work chats.