Time and space complexity in simple way

Time and space complexity in simple way

When we look at any computer program ,on first hand it should perform its requirement that is functional criteria . To test we generate input data(test data or test case) and invoke function with input data(test data) as argument and validate output with expected value .

Performance of program depends processor and memory .Processor is directly proportional to amount of instruction (program statement ) to execute per unit time .Memory is directory proportional size of state of program under execution .For example when we open 2 huge game , code execution speed of processor shared by 2 games and state of 2 game save in memory (RAM).

On other way if you decrease number of instruction to execute on constant processor capacity, and if you reduce states of size of state of program on constant memory performance can improved .

The of number of instruction execution expressed by Time complexity and size of state of program allocated expressed by Space complexity .

Let's take an example on time complexity .

int x=n;

while (x>0){

x=x/2;

}

The loop will run till x=1 (N.B int 1/2 is 0) .The amount of iteration required to make x to 0.

if n=8 then on iteration x become 4 ,2,1 i,e 8/2,8/2^2,8/2^3

So it is 3 time loop will execute and we can get 3 by 8/2^3 =1 from that 3 is log8 base 2

hence for input N ,total number of iteration = time complexity =logN base 2

NB:Normally time complexity evaluated keeping mind of input(N) is huge ,so declaration ,assignment statements are ignored.It is basically focused on iterations evalution with huge inpute.This type of analysis is called Big-Oh analysis .O(logn)

Let's take an example on space complexity .

public void fun(int n){

if(n==0)

return ;

fun(n-1);

}

This is recursive function the number of stack it will generate on memory in otherwards number of state this program have is n(number of input) hence space complexity is n.O(n)

































Yatheesh Kumar

QA Analyst at Oracle

8 年

Good One, thank you

回复

要查看或添加评论,请登录

Brahmananda Kar的更多文章

  • Gradient descent

    Gradient descent

    Gradient descent is a widely used optimization algorithm in machine learning and artificial intelligence. It is used to…

  • Master in SQL in 10 min

    Master in SQL in 10 min

    It is required to hands-on on SQL for multiple reason .Below query designed in such a way that go to start as there no…

  • Kubernete Usecases

    Kubernete Usecases

    UseCase :1 From an automation perspective, Since selenium grid confirm of high availabity of node to distribute test…

  • Decomposition of data analytics

    Decomposition of data analytics

    Data analytics is combination of data science , deep learning and big data (+7TB) Data science : math, structured…

  • CI & CD in cloud with JenkinFile

    CI & CD in cloud with JenkinFile

    Background: Historically jenkins served as continuous integration and then moved to continuous delivery tool . Life…

  • Design Pattern as tale

    Design Pattern as tale

    Design patterns are best practice to tackle certain problems . In Object oriented language , involves 3 step to model…

    1 条评论
  • What problem docker solves

    What problem docker solves

    1.Background Since inspection of agile methodology , cycle time is very unfair for testing guys to put ui/api test…

  • What is test Automation ?

    What is test Automation ?

    So many buzz word flowing around us and still trying to understand test automation. If you consider software components…

社区洞察

其他会员也浏览了