Tutor profile: Nafseer K.
Subject: Python Programming
How to be more memory efficient when processing large lists in Python?
Use Generators instead of creating the full list. For example, instead of the below List comprehension: sum([i * i for i in range(1, 10000001)]) # creates the full list in memory Use the below generator expression: sum((i * i for i in range(1, 10000001)))
Subject: Java Programming
Can Singleton Design pattern guarantee the creation of only one instance of the object?
No. You can use Java reflections to make the constructor public and then create additional instances of the class.
Subject: Computer Science (General)
compare HeapSort vs QuickSort vs MergeSort
Theoretically, when comparing worst-case performance, HeapSort and MergeSort (O(nlogn)) fares better than QuickSort (O(n2)). But practically, occurrence of the worst case of QuickSort can be greatly minimized by using Randomization or Median of Medians. Moreover the hidden constant factors of QuickSort is better than the others. To summarize: 1. Use Heap Sort if you want in-place sorting 2. Use Merge Sort if you want stable sort and is OK with being not in-place 3. Use Quick Sort otherwise, but do remember it runs in O(n2) time in worst-case
needs and Nafseer will reply soon.