What is the complexity of this simple piece of code?

This seems to be a question of mislead, because I happened to read that book just now. This part of text in the book is a typo! Here is the context: =================================================================== Question: What is the running time of this code? 1 public String makeSentence(String[] words) { 2 StringBuffer sentence = new StringBuffer(); 3 for … Read more

multiset, map and hash map complexity

map, set, multimap, and multiset These are implemented using a red-black tree, a type of balanced binary search tree. They have the following asymptotic run times: Insertion: O(log n) Lookup: O(log n) Deletion: O(log n) hash_map, hash_set, hash_multimap, and hash_multiset These are implemented using hash tables. They have the following runtimes: Insertion: O(1) expected, O(n) … Read more

Is there anything that guarantees constant time for accessing a property of an object in JavaScript?

Is there anything in the JavaScript guaranteeing that the values are looked up in O(1) time? No. JavaScript does not give any complexity guarantees whatsoever, except for ES6 collections. I know the access operator [] gives a seasoned programmer the impression that he’s dealing with an O(1) lookup structure Yes you are, this is a … Read more

What is the best way to get the minimum or maximum value from an Array of numbers?

The theoretical answers from everyone else are all neat, but let’s be pragmatic. ActionScript provides the tools you need so that you don’t even have to write a loop in this case! First, note that Math.min() and Math.max() can take any number of arguments. Also, it’s important to understand the apply() method available to Function … Read more