Posts

Showing posts from September, 2022

Space Complexity

  Simply put, the space complexity of an algorithm or a code indicates how much space is used up while executing that code.  int sum(int n)          {               int i,sum = 0;               for(i=n;i>=1;i--)               sum=sum+i;               return sum;          } The space complexity of this code is just O(1), because irrespective of the size of n, the amount of space used is constant (the variable 'sum' uses some fixed space).  Causes of Space Complexity 1. Variables 2. Data Structures 3. Function Call 4. Allocations In using some data structure or an algorithm, there is always a tradeoff between time and space complexity. You have to decide, according to your problem statement, if you are optimizing for time or space or both, what resources yo...

Rule Book For Calculating Big O

Now, let's talk about some rules to be followed while calculating any algorithm's Big O time complexity.  Rule 1: Always consider the worst case. Even though your algorithm does only four operations for your specific input case, always think about the number of operations it would take if the input was the worst case you could ever get.  Rule 2: Get Rid of Constants. This should sound very obvious to you by now. Therefore, since the definition of the Big O is how proportional it is to the amount of data or inputs, bringing in any constant would be meaningless. For example, if the number of operations is proportional to the number of inputs (Linear Time Complexity), then the Big O of that algorithm would be O(n). Although the Big O of that algorithm can be written as O(n/2), the number of operations remains proportional to the number of data points, correct? Hence, it is always preferred to remove the constants while calculating Big O. Rule 3: Different terms for in...

Big O : Intuition and Cheat Sheet

Image
  As problem solvers, we are expected to produce efficient codes for the problems rather than any working code. But, how do we define what an efficient or better code is? Let's think about it. Would you prefer clumsily written code that only the user understands? Or a code that is well-written and easily readable? Would you prefer a code that takes minutes to execute or a code that executes lightning-fast?  Therefore, the parameters to measure the efficiency and applicability of any code would be, 1. Readability 2. Scalability - Speed (Time Complexity) and Memory (Space Complexity) Now, how do we measure the speed of any code relative to the other? How can we exactly quantify the execution speed? Maybe, we can use a timer to calculate the total time a processor takes to execute that one complete code. Although, this is a valid approach, but the time taken to execute a code is highly dependent on the processor, RAM, and ROM used. Your computer might be able to execute ...

Tips to Get More Interviews

1. Resume A resume is just a brief document of your skills that an interviewer will glance at for like 10 seconds to decide whether you are worthy enough for this role. Therefore, no recruiter will hire you for a role, just because you have a good and attractive resume.  Always personalize your resume corresponding to which job role and company you are applying to. Include the keywords given in the job description in your resume.  Spend very little time creating your own resume (unless you are a designer). Use free online tools to create your own resume. Two of them would be,  ResumeBuild  and  Resume.io . As a developer or coder, your time is better spent enhancing your skills, instead of designing your resume from scratch.  Features of a nice resume:   1. Resumes should always be on one single page . 2. It should include all your relevant skills for that particular job description. 3. It should be personalized for that particular job role and...