Skip to main content

Measuring Efficiency of Algorithms

Hello
it is long time since last time I wrote a blog post , I'm Okay and passion to write more and more posts , I'll talk about measuring efficiency of Algorithms .

there exist two approaches :

  1. using the Concept of bench mark we focus on two aspects :
    • is the output of the program correct ?
    • how much time and resources are needed by the program to produce the correct output?
  2. estimate ! DON'T MEASURE , and we will talk about this approach in details in the next sections. 
discussing approach (bench mark) cost money , resources and time, it used for small problems or execution time relatively  small ,this push us - computer scientists not me of course - directly to find  a new way , estimation of execution time.

we gonna use a new term " Asymptotic Analysis  ":

Asymptotic analysis is an analytical approach to analyze the running time of the algorithms under the following assumptions  :

  • the size of the input .
  • estimating the number of steps required to run an Algorithm we neglect the primitive operations.
Asymptotic analysis is based on the growth of the function , and it tries to predict the behavior of the algorithm in the limit  i.e when the problem size is large or grows to infinity.

there exist many notation used for estimating performance in asymptomatic analysis  :-

  1. Big O notation .
  2. small o notation .
  3. Big Theta notation .
  4. Big Omega notation.
  5. small omega notation .
I'll discuss the Big Oh , informally big oh represents a set of functions that grow no faster than function , i.e.

  •  1000 , 5 n , log (n) , 1/2 n are all Big-Oh of n,  O ( n )
  • 10 , 2n , n^2 , 10000 n^2 are all O (n^2)
we use big-Oh to classify algorithms according to their Growth ( running time )

  • Constant growing function O (1)
  • Logarithmic growing function O ( log n)
  • Linear growing function O ( n )
  • n log n growing function O ( n log n )
  • Quadratic   growing function O (n^2)
  • Polynomial growing function O ( n^k ) where k is constant 
  • Exponential growing function O (2^n)
the Big Oh measure the upper bound of the function in other words it measure the worst case , the maximum running time for an algorithm .

The Formal Definition of the Big - Oh 


  • We say that t(n)=O(f(n)) if and only if there are two nonnegative constants no and c such that t(n)≤cf(n) for all n≥no and c>0
    • The expression t(n)=O(f(n)) is read as
    • T of n is in Big-Oh of f of n,
    • T of n is in the set Big-Oh of f of n,” or
    • T of n is Big-Oh of f of n.
  • The definition means that if the problem size n equals or exceeds no, t(n) will be bounded from above by cf(n), i.e. the value cf(n) will eventually exceed the value of t(n) when n>=no
there exist two approaches to show that a function t ( n ) is in O ( n ) 

  1. By showing that there exists two nonnegative numbers no and c such that t(n) ≤ cf(n) for all n ≥ no 
  2. For really large n, we can use the limit theorem to show that there exists a nonnegative number c<∞ such that


example  1 : 




 example 2 :



example 3 :


example 4 :

I finished Big-Oh in shaa Allah I'll complete the others soon , I hope you like the Article , and if you like it please can you share it .


this Article main source is PhD / Ahmed Kamal lecture slide , thank you for reading :)



to be Continued ........................





Comments

Popular posts from this blog

DevExpress C# Chart Tutorial

Hello , this blog post about Charting in DevExpress , I faced many problems I visited hundreds of pages to solve this problems , actually it was the first time I use DevExpress Charts, Work is not like school or university , in school if you don't know thing you can learn it any time you want , in work you have to do today task yesterday, I like to share my knowledge and skills with you , I hope this Post help you . // clear series on chart  chart.Series.Clear(); // clear Titles of chart chart.Titles.Clear(); // legend alignment  chart.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Center; chart.Legend.AlignmentVertical = LegendAlignmentVertical.Bottom; chart.Legend.Direction = LegendDirection.LeftToRight; // creating series // series view Type example Line DevExpress.XtraCharts.Series series = new DevExpress.XtraCharts.Series("series name ", ViewType.Line); // add title  DevExpress.XtraCharts.ChartTitle chtTitle = new DevExpress.XtraCharts.Cha

Designing Entity Relationship Diagram (ERD)

Al Salmo Aliko . Hello, in this post I'll discuss with you how to design good Entity Relationship Diagram ERD . this article for: IT Students learning about database. you are having difficulties in creating ERD. you are developer that need help in database design.   let's ask ourselves Why good database design is good ? or why we need ERD?         when I started programming Eng / Eman Ahmed was my First teacher, she said you must write your code with pen, and now I told you good database design start with paper and pen or in technological terms start with ERD, ERD is the model which shows logical layout of your database. let's List some advantages of good database design : very low or no redundant data is stored.  supporting planed or unplanned queries. good design easy to maintain and modify. from first glance you can understand it. an ERD consist from Entities and relationships between them; there exist many notation in textbooks and all are right I

LeetCode Problem #15. 3Sum

Problem statement  Given an array   nums   of   n   integers, are there elements   a ,   b ,   c   in   nums   such that   a   +   b   +   c   = 0? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain duplicate triplets. Example : Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ] this problem is medium but I think it is much harder especially with the condition of non duplicate,  I'll write two solutions