1 / 7

what is Big O Notation

Learn in Digital strongly sticks to the quote u201cIf you get, give. If you learn, teachu201d. We believe that depth-wise knowledge should be more concentrated than breadth-wise. So we Learn in Digital strives hard to deliver the depth-wise knowledge to our amigos.<br>https://learnindigital.com/

bellajack
Télécharger la présentation

what is Big O Notation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Learn In Digital Learn To Teach, Teach To Learn Big O Notation Hola Amigos, Let’s Discuss about Big O Notation in today’s post. Big O Notation is used to describe the efficiency of Algorithm and in Big O we will be considering only the worst-case scenario, because as a Developer it’s our responsibility to scale up for the worst case as the input size grows. Thus, Big O Notation is exhibited in terms of the input size. Big O Notation usually deals with two types of complexities, • Time Complexity - The time required by your algorithm to run completely • Space Complexity - The extra space required by your algorithm to run Space Complexity: It is to define the amount of extra space our code took to compute the result. But in today’s world, our main concern is time complexity because, we have large volume of storage, whereas the time is a main concern since it is a fast-moving world. So, we will look into time complexity in detail.

  2. Time Complexity: In order to find the Time complexity of your solution, • Count the number of times the single statement gets executed in your code • Get the sum of counts of your entire code • After summing up the counts, neglect the Leading constants • Then neglect the Lower order terms The types of Big-O complexities are, Let us see the different types of Complexities through a real-life example, Let us consider, you are going to Multi-Cuisine Restaurant. Based on the conversation between you and the waiter we can see different types of time complexities, Scenario 1 - You have decided what to eat before entering the Restaurant. So, you won’t take time to order your food.

  3. Waiter - What do you like to have sir? You - 1 Fried Rice. In this case, the waiter has no need to say about the menu items to us. So This is an example of Constant Time Complexity - O(1). Scenario 2 - The Restaurant is a Multi-Cuisine. And you decided to go with Chinese or Italian. So, you won’t be looking into other Cuisines like Indian or French. Thus, you will be checking the menu items only related to Chinese and Italian instead of checking the entire menu list of a restaurant. Our view is now reduced to half items of restaurant’s menu in this case. Waiter - What do you like to have sir? You - I’m likely to go with Chinese or Italian. Waiter - Dim Sums, Noodles, Spring Rolls from Chinese and Panzenella, Bruschetta, Margherita Pizza from Italian You - 1 Margherita Pizza. This is an example of Logarithmic Time Complexity - O(logn) Similarly, If you have no idea on what you are going to have. Then ideally you will be enquiring the entire menu list irrespective of Cuisine and then you will be coming to a conclusion. This is an example of Linear Time Complexity - O(n). And If you are enquiring about the list of cuisines available in the restaurant and from the list we will enquire about the dishes related to at most two cuisines . This is an example of Linearithmic Time Complexity - O(nlogn). And Finally if it is a bad day for the waiter, then you will be enquiring about the entire cuisines available in restaurant and in addition to it you will also be enquiring about all the items in each and every cuisine. Then it is the example of Quadratic Time Complexity - O(n2).

  4. ### Types of Complexities ### cuisines = ['Indian','Chinese','Italian1,'French'] dishes = {cuisines[8] cuisines[l] cuisines[2] cuisines[3] [' Biryani',' Naan',' R< ['Dim Sums','Noodles','Spring Rolls','Fried Rice'], [' Panzenella','Bruschetta','Margherita Pizza'], [' Cassoulet','Flamiche','Ratatouille' ]} i Fried Rice before entering the restaurant.\nso I t interested t print("Ordered : “ + dishes['Chinese'][3]) ### Logarithmic | O(logn) ### print("\n### Logarithmic Function ###") print(*I have decided to go with either Chinese o interested to know the Indian and French menu") myChoiceCuisine = ['Chinese','Italian'] for myCuisine in myChoiceCuisine: print(dishes[myCuisine]) print("I will go with Italian cuisine. And I am o print("Ordered : “ + dishes['Italian'][2]) ### Linear | 0(n) ### print("\n### Linear Function ###") print("Say me the entire menu available irrespect Italian before entering the restaurant.\nso I a h Margherita Pizza") ### Linearithmic | O(nlogn) ### print("\n### Linearithmic Function ###") printf'Say me the Cuisines available and I will choose any t selected=D if(selected>l): break print{cuisine + ". Are you Interested s choice = input() if {choice == "yes” and selected < 2): selected+=l print("The dishes in “ + cuisine + for cuisineDish in dishes[cuisine]: print!cuisineDish) ### Quadratic | O(nlogn) ### print("\n### Quadratic Functio print!"Say me all the Cuisines i respective dishes t print(cuisine) print!"The dishes in " + cuisine + ' for cuisineDish in dishes[cuisine]: print{cuisineDish) ### Lokesh Raj M | Learn in Digital ### The Need for Big-O Notation is, We can’t predict the performance based on the execution time of your algorithm. Because the time required to execute code is machine dependent. The code execution time is dependent on multiple factors like processor, network load and so on. So instead of measuring actual time required in executing each statement in the code, we consider how many times each statement execute. And it is known as Big-O Notation. To get the source code for reference, Please do check my GitHub profile https://github.com/imlokeshraj/LearnInDigital/tree O-Notation For any Queries, please do connect with me on LinkedIn at https://www.linkedin.com/in/lokeshrajm or shoot me an e-mail at lokesh@learnindigital.com

  5. NEXT ARTICLE -► YOU MAY ALSO LIKE... August 23, 2020 Recursion 6 COMMENTS Ashwin Kumar On August 16, 2020 at 3:28 PM Nice article.. Keep up the work § ^ REPLY admin On August 18, 2020 at 10:23 AM Thank you bro ^ REPLY Kailash On August 17, 2020 at 9:16 AM It’s Sooper work! ' i ^ REPLY admin On August 18, 2020 at 7:01 PM Thank you bro!! ^ REPLY Ramkumar On August 21,2020 at 2:00 AM

  6. A unique way of writing, especially the analogy part. Looking forward to see more such interesting articles like this. Good job folks. ^ REPLY admin On August 23, 2020 at 1:15 PM thanks bro ^ REPLY LEAVE A REPLY Your email address will not be published. Required fields are marked * Comment Name* Email* Website r Save my name, email, and website in this browser for the next time I comment. POST COMMENT

  7. LEARN DIGITAL Learn in Digitalstrongly sticks to the quote “If you get, give. If you learn, teach”. We believe that depth-wise knowledge should be more concentrated than breadthwise. So we Learn in Digital strives hard to deliver the depth-wise knowledge to our amigos. WEBSITE LINKS About usBlog DisclaimerPrivacy policyTerms and Conditions FIND US LOCATION Coimbatore FAZIL fazil@learnindigital.com LOKESH lokesh@learnindigital.com © Copyright 2020Learn In Digital. All Rights Reserved. Powered byLearnInDigital. 03 O03

More Related