Skip to main content

Posts

Big OH

Big "OH" Before we proceed we must know what the below graph means If you are wondering what it means let me be very straight forward to you. "You have to write your algorithm with time and space complexity near or below the purple line" When someone asks you to calculate Big-O, you do the below things and you are golden : 1. Worst Case Scenario  Always consider the worst case scenario. As yourself this, question a million times."What if the input is huge, like a million or a trillion ?" If you have to check no of times a string occurs in an array, you would go for a for loop which will loop through the elements and keep increment a counter, which has a complexity of O(N) where N is the number of inputs. Always think, what will happen when N reaches a million or a trillion. How will your code perform. 2. Remove Constants -  I have added the Big-O complexity to the code. Final complexity is 2*O(1) + 2*O(N) If we consider th...
Recent posts

I wonder Why ?

I wonder Why ? #1 W e have "string" and "String" in C# when both does the same thing ? Answer : Answer is fairly simple. string is an alias of String. Hows that ?. To achieve type safety, Microsoft has designed the Managed languages such that they can communicate with each other. For the entire framework we have base types such as System.String and thus their code specific alias such as string in C# and String in VB. When we compile the program in C# it actually refers to System.String(Kinda how alias is suppose to work right) There are plenty of other alias too         object     : System. Object          string       : System. String            bool         : System. Boolean        byte         : System. Byte  ...

Garbage Collector

Garbage Collector : "If you have time to lean, you have time to clean" 1. This is the process that runs when we run our application. This is a DAEMON Thread.      More : Garbage Collector is one of the two processes that runs by default when you run an  application. Second is the Main program (Duh !!) 2. Garbage collector is only called when the application request memory and there is not enough memory. (Myth : It is always called. )  3. "Mark and Sweep" : This is a method comprises of the following. GC assumes everything on the memory is a trash. Prepares a graph of all the memory that is currently referenced by the application. Compacts the heap by moving the memory in use to the start of the Heap. The new heap is formed and the vacant is left and freed.       4. GC is only effective if performed on smaller memory objects. It will obviously have an adverse effect if the GC tries to move let say 30000 byte of ...

Interface Theorem

INTERFACE : " It all started with you :-* "  1. Interface cannot inherit abstract class. In other words, An interface can only inherit other interfaces. 2.  Interface can inherit multiple interfaces 3.  If you have two interfaces, the second one has inherited the first one, if you inherit the second one to any class then all the methods from the first interface will have to be declared too.      4. An interface member functions or variables cannot be declared with Access Modifiers.   5. If you have inherited an Interface, then you must declare all its method as Public when you are declaring. If declared as "Protected", "Private", "Internal" or "Protected Internal", you will see an error.   6.   

Abstract Classes

ABSTRACT CLASSES : "You are so abstract ;-)" 1. Multiple Abstract classes cannot be inherited in an abstract. ( :-/ ) If you have an abstract class and you want multiple abstract classes to be inherited then it is not possible. 2. When inheriting the abstract class, you must follow the convension of inheriting the abstract class first before the interface, other wise it will show an error. COMPILER ERROR - Base class 'YourAbstractClassName' must come before any interfaces   3. An abstract class can inherit multiple interfaces. Duh !! 4. When creating a class library which will be widely distributed or reused—especially to clients, use an abstract class in preference to an interface; because, it simplifies versioning. 5. An abstract method cannot be static.  6. You can use sealed with the abstract methods. In other terms, An abstract class can be sealed.