Plz tell me how I would calculate time complexity of the program:

for (i=0; i<points.length; i++) 
        {
            if (points[i].lng()<lon && points[j].lng()>=lon ||  points[j].lng()<lon && points[i].lng()>=lon) 
            {
                if (points[i].lat()+(lon-points[i].lng())/(points[j].lng()-points[i].lng())*(points[j].lat()-points[i].lat())<lat) 
                {
                    inPoly=!inPoly; 
                }
            }
            j=i; 
        }

thnx in advance

Looks like O(n) from here.

The routine is dependent on points.length. The inner part can be considered constant execution time. As the number of points grow, the amount of time grows in direct 1:1 to them. So O(n).

Looks like O(n) from here.

The routine is dependent on points.length. The inner part can be considered constant execution time. As the number of points grow, the amount of time grows in direct 1:1 to them. So O(n).

ya it's looking tht it has a complexity of O(n) bt how it is calculated. Can u plz explain it and wht is it's exact complexity.

please explain to us what the algorithm does and wrap the code part in code tags, it's difficult to read.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.