For this code
function createArrayOfFunctions(y) {
var arr = [];
for(var i = 0; i<y; i++) {
arr[i] = function(x) { return x + i; }
}
return arr;
}| import kotlinx.coroutines.experimental.* | |
| fun main(args: Array<String>) { | |
| val start = System.currentTimeMillis() | |
| exampleBlocking() | |
| val end = System.currentTimeMillis() | |
| println("executing time: ${end - start}") |
| public void scanBarcode(Bitmap image) { | |
| FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(image); | |
| FirebaseVisionBarcodeDetectorOptions options = | |
| new FirebaseVisionBarcodeDetectorOptions.Builder() | |
| .setBarcodeFormats( | |
| FirebaseVisionBarcode.FORMAT_QR_CODE, | |
| FirebaseVisionBarcode.FORMAT_AZTEC | |
| ) | |
| .build(); |
| public void runCloudTextRecognition(Bitmap selectedImage) { | |
| FirebaseVisionCloudDetectorOptions options = new FirebaseVisionCloudDetectorOptions.Builder() | |
| .setModelType(FirebaseVisionCloudDetectorOptions.LATEST_MODEL) | |
| .setMaxResults(15) | |
| .build(); | |
| FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(selectedImage); | |
| FirebaseVisionCloudDocumentTextDetector detector = FirebaseVision.getInstance() | |
| .getVisionCloudDocumentTextDetector(options); |
| public void runCloudTextRecognition(Bitmap selectedImage) { | |
| FirebaseVisionCloudDetectorOptions options = new FirebaseVisionCloudDetectorOptions.Builder() | |
| .setModelType(FirebaseVisionCloudDetectorOptions.LATEST_MODEL) | |
| .setMaxResults(15) | |
| .build(); | |
| FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(selectedImage); | |
| FirebaseVisionCloudDocumentTextDetector detector = FirebaseVision.getInstance() | |
| .getVisionCloudDocumentTextDetector(options); |
| public void runTextRecognition(Bitmap selectedImage) { | |
| FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(selectedImage); | |
| FirebaseVisionTextDetector detector = FirebaseVision.getInstance().getVisionTextDetector(); | |
| detector.detectInImage(image) | |
| .addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() { | |
| @Override | |
| public void onSuccess(FirebaseVisionText text) { | |
| processTextRecognitionResult(text); |
| laze var cloudTextDetector: VisionCloudTextDetector = Vision.vision().cloudTextDetector() | |
| func runCloudTextRecognition(with image: UIImage) { | |
| let visionImage = VisionImage(image: image) | |
| cloudTextDetector.detect(in: visionImage) { (features, error) in | |
| if let error = error { | |
| print("Received error: \(error)") | |
| } |
| lazy var textDetector: VisionTextDetector = Vision.vision().textDetector() | |
| func runTextRecognition(with image: UIImage) { | |
| let visionImage = VisionImage(image: image) | |
| textDetector.detect(in: visionImage) { (features, error) in | |
| if let error = error { | |
| print("Received error: \(error)") | |
| } |
Let the size of the first array is N and the size of the second array is M. The big O of the time complexity of this algorithm is O(N + M)
In the beginning, we put all elements in the first array into a HashSet object, the time complexity is O(N) because we walk throught all elements, and saving a element into a hash set only costs a constant time.
In order to determine if the second array is a subset of the first array, we walk through all elements in the second array, and check if each element has already been in the hash set. Because finding a element in a hash set also costs a constant time, the time complexity is O(M)
After executing the above steps, we can know if the second array is a subset of the first array. The total time complexity is O(M + N)