×

# Time Complexity for beginners

 1 1 I request everyone to help beginners to understand time complexity. What is time complexity? How to calculate it? What is the benefit of knowing and calculating time complexity? What is worst case scenario, best case scenario and average case scenario in time complexity? There are many beginner coders who are not that great with maths so I request everyone to keep it as simple as possible and please contribute to it. Please refer to links or explain in a way that doesn't make it more complex, thank you. asked 18 Aug '17, 08:06 69●5 accept rate: 0%

 2 (Consider a hypothetical case) Time Complexity - Think of a dictionary that contains N (very large) name and now you need to find your name, The most brute force solution you'll think of is doing is a linear Search, Since there are N names so your time complexity is O(N) where O stands for 'Big O notation'. For time being assume the Big O notation is something through which we denote time complexity and the value inside is the number of times the program runs. The second solution you'll think of is doing a binary search in dictionary to find your name, now you know that binary search uses divide and conquer technique through which we can find the solution in log(N) iterations. So time complexity is O(log(N)) The third solution you can think using a hashmap which in general take constant time to find a key. So for constant iterations, O(1). Now you know three solutions to solve a single problem but for each solution we have different time complexity, here comes the use of time complexity. From above discussion we came to know that third solution is the best solution. Hope this helps! answered 18 Aug '17, 12:50 798●7 accept rate: 16% Thank you, it really helps. (18 Aug '17, 14:10)
 1 What is time complexity?  It is a rough idea on how "Time taken by program to execute" increases with input data. How to calculate it?  You can roughly approximate it as highest growing function in the expression. Eg, consider 2 loops- for(i=0;i
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×241
×49

question asked: 18 Aug '17, 08:06

question was seen: 407 times

last updated: 19 Aug '17, 09:25