Skip to main content

Algorithms language Chapter 2: Algorithm Complexity (Part-1)

Chapter 2: Algorithm Complexity


Section 2.1: Big-Theta notation

Unlike Big-O notation, which represents only upper bound of the running time for some algorithm, Big-Theta is a
tight bound; both upper and lower bound. Tight bound is more precise, but also more difficult to compute.

The Big-Theta notation is symmetric: f(x) = Ө(g(x)) <=> g(x) = Ө(f(x))

An intuitive way to grasp it is that f(x) = Ө(g(x)) means that the graphs of f(x) and g(x) grow in the same rate, or
that the graphs 'behave' similarly for big enough values of x.

The full mathematical expression of the Big-Theta notation is as follows:

Ө(f(x)) = {g: N0 -> R and c1, c2, n0 > 0, where c1 < abs(g(n) / f(n)), for every n > n0 and abs is the absolute value }

An example

If the algorithm for the input n takes 42n^2 + 25n + 4 operations to finish, we say that is O(n^2), but is also O(n^3)
and O(n^100). However, it is Ө(n^2) and it is not Ө(n^3), Ө(n^4) etc. Algorithm that is Ө(f(n)) is also O(f(n)), but
not vice versa!

Formal mathematical definition

Ө(g(x)) is a set of functions.

Ө(g(x)) = {f(x) such that there exist positive constants c1, c2, N such that 0 <= c1*g(x) <= f(x)
<= c2*g(x) for all x > N}

Because Ө(g(x)) is a set, we could write f(x) ∈ Ө(g(x)) to indicate that f(x) is a member of Ө(g(x)). Instead, we
will usually write f(x) = Ө(g(x)) to express the same notion - that's the common way.

Whenever Ө(g(x)) appears in a formula, we interpret it as standing for some anonymous function that we do not
care to name. For example the equation T(n) = T(n/2) + Ө(n), means T(n) = T(n/2) + f(n) where f(n) is a
function in the set Ө(n).

Let f and g be two functions defined on some subset of the real numbers. We write f(x) = Ө(g(x)) as
x->infinity if and only if there are positive constants K and L and a real number x0 such that holds:

K | g(x)| <= f(x) <= L | g(x)| for all x >= x0.

The definition is equal to:

f(x) = O(g(x)) and f(x) = Ω(g(x))

A method that uses limits

if limit(x->infinity) f(x)/g(x) = c ∈ (0,∞) i.e. the limit exists and it's positive, then f(x) = Ө(g(x))

Common Complexity Classes

Name         Notation       n = 10        n = 100
Constant      Ө(1)            1             1
Logarithmic   Ө(log(n))       3             7
Linear        Ө(n)            10            100
Linearithmic  Ө(n*log(n))     30            700
Quadratic     Ө(n^2)          100           10 000
Exponential   Ө(2^n)          1 024         1.267650e+ 30
Factorial     Ө(n!)           3 628 800     9.332622e+157

Comments

Popular posts from this blog

HTML For Beginners The Easy Way: Start Learning HTML

HTML for Absolute Beginners  While many guides on the internet attempt to teach HTML using a lot of mind-boggling theory, this tutorial will instead focus on giving you the  practical skills to build your first site . The aim is to show you ‘how’ to create your first web page without spending the entire tutorial focusing too much on the “why.” By the end of this tutorial, you will have the  know-how to create a basic website  and we hope that this will inspire you to delve further into the world of HTML using our follow-on guides. What is HTML? Okay, so this is the only bit of mandatory theory. In order to begin to write HTML, it helps if you know what you are writing. HTML is the  language in which most websites are written . HTML is used to create pages and make them functional. The code used to make them visually appealing is known as CSS and we shall focus on this in a later tutorial. For now, we will focus on  teaching you how to build rather than desi...

Mastering Blockchain: A deep dive into distributed ledgers, consensus protocols, smart contracts, DApps, cryptocurrencies, Ethereum, and more, 3rd Edition

Mastering Blockchain: A deep dive into distributed ledgers, consensus protocols, smart contracts, DApps, cryptocurrencies, Ethereum, and more, 3rd Edition        Develop a deeper understanding of what’s under the hood of blockchain with this technical reference guide on one of the most disruptive modern technologies Key Features Updated with four new chapters on consensus algorithms, Ethereum 2.0, tokenization, and enterprise blockchains Learn about key elements of blockchain theory such as decentralization, cryptography, and consensus protocols Get to grips with Solidity, Web3, cryptocurrencies, smart contract development and solve scalability, security and privacy issues Discover the architecture of different distributed ledger platforms including Ethereum, Bitcoin, Hyperledger Fabric, Hyperledger Sawtooth, Corda and Quorum Book Description Blockchain is the backbone of cryptocurrencies, with applications in finance, government, media, and other industries. With a ...

The Intersection of Blockchain and AI

  The Intersection of Blockchain and AI  The Intersection of Blockchain and AI: opportunities and implications Today is the need to comprehend and influence the new  technology  revolution, which is one of the biggest and most crucial/vital challenges we confront which is capable of constituting a complete transformation of humanity. Revolution, which we are currently experiencing is altering our way of life, employment and relationships in unprecedented ways. The fourth industrial revolution; as I perceived it, is unique in its magnitude, breadth and in complex level and marks a significant departure from anything humans have ever experienced before that. It is imperative that we adapt to these changes in manners that are both effective and responsible. The Intersection of Blockchain and AI: AI and blockchain are the most amazing and transformative technologies that are now starting to come together, which could change lots of things in different fields. While both ...