Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


The String struct doesn’t provide a count or length property or method to count the number of characters it contains. Instead a global countElements<T>() function is available. When applied to strings, what’s the complexity of the countElements function:

O(1)

O(n)

and why?



The String struct doesn’t provide a count or length property or method to count the number of ..

Answer / iosraj

Swift strings support extended grapheme clusters. Each character stored in a string is a sequence of one or more unicode scalars that, when combined, produce a single human readable character. Since different characters can require different amounts of memory, and considering that an extreme grapheme cluster must be accessed sequentially in order to determine which character it represents, it’s not possible to know the number of characters contained in a string upfront, without traversing the entire string. For that reason, the complexity of the countElements function is O(n).

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Apple iOS Swift Interview Questions

What is swift? How is it different from objective-c?

0 Answers  


What are floating point numbers? How many types of floating number are there?

0 Answers  


What are classes in swift?

0 Answers  


What are the half open range operators in swift?

0 Answers  


What are the new feature in swift 4.0?

0 Answers  


What is mutating keyword in swift?

0 Answers  


What type of literals does swift language have?

0 Answers  


Explain deinitializer in swift programming language?

0 Answers  


What is the floating point numbers and what are the types of floating number in swift?

0 Answers  


What is swift stand for?

0 Answers  


What is nsmutablearray in swift?

0 Answers  


What is encapsulation in swift?

0 Answers  


Categories