'How Can I find the Worst-case Time Complexity of a code like this
This code snippet here might not work very well but the idea is that I want to know how to find the worst-case time complexity when you have a Sorting algorithm (mergeSort) function inside of a function and with two for loops. I'm now trying to understand how to find the worst-time complexity and I know that two nested loops will give a quadratic function of O(n^2). I hope someone can throw more light on this for me and sorry if I broke any rules in the process.
function part(vector){
var n = vector.length;
if (n == 0){
return False;
}
var vector = MergeSort(vector);
for(var i=0; i < n; i++) {
for(var j = 0; i< n; j++) {
var a = i;
var b = n;
while (a <= b){
var c = math.floor((a + b)/2);
if (vector[c] = -vector[i] - vector[j]){
return True;
}
else if (vector[c] < -vector[i] -vector[j]){
a = c + 1;
{
else {
b = c -1;
}
}
}
{
return False;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
