Doubt regarding the variable by which time complexity is measured












0












$begingroup$


In order to assert that a given algorithm for graphs runs in polynomial time, must the variable in the big-O function that represents the run time (denoted henceforth as $O(f(n))$) be the number of vertices? Or can one say that a graph algorithm runs in polynomial time if the variable $n$ is something else (like the number of edges in a graph).



Edit: Could an algorithm that is $O(N)$ (where $N$ is the number of trees in the graph) also be considered as being in $P$?










share|cite|improve this question











$endgroup$








  • 1




    $begingroup$
    The variable could be either of them or a subset of them. It will depend on the case for which time complexity is being determined.
    $endgroup$
    – toric_actions
    Dec 29 '18 at 12:29






  • 1




    $begingroup$
    $Nodesleq 2Edges$ and $Edgesleq Nodes^2$ so a polynomial result for one implies a polynomial result for the other. (Assuming all nodes touch at least one edge)
    $endgroup$
    – Michael
    Dec 29 '18 at 15:49










  • $begingroup$
    If an algorithm is $O(N)$ (Where $N$) is the number of trees in a graph. then is that algorithm still in the complexity class $P$?
    $endgroup$
    – Aryaman Gupta
    Dec 29 '18 at 17:34
















0












$begingroup$


In order to assert that a given algorithm for graphs runs in polynomial time, must the variable in the big-O function that represents the run time (denoted henceforth as $O(f(n))$) be the number of vertices? Or can one say that a graph algorithm runs in polynomial time if the variable $n$ is something else (like the number of edges in a graph).



Edit: Could an algorithm that is $O(N)$ (where $N$ is the number of trees in the graph) also be considered as being in $P$?










share|cite|improve this question











$endgroup$








  • 1




    $begingroup$
    The variable could be either of them or a subset of them. It will depend on the case for which time complexity is being determined.
    $endgroup$
    – toric_actions
    Dec 29 '18 at 12:29






  • 1




    $begingroup$
    $Nodesleq 2Edges$ and $Edgesleq Nodes^2$ so a polynomial result for one implies a polynomial result for the other. (Assuming all nodes touch at least one edge)
    $endgroup$
    – Michael
    Dec 29 '18 at 15:49










  • $begingroup$
    If an algorithm is $O(N)$ (Where $N$) is the number of trees in a graph. then is that algorithm still in the complexity class $P$?
    $endgroup$
    – Aryaman Gupta
    Dec 29 '18 at 17:34














0












0








0





$begingroup$


In order to assert that a given algorithm for graphs runs in polynomial time, must the variable in the big-O function that represents the run time (denoted henceforth as $O(f(n))$) be the number of vertices? Or can one say that a graph algorithm runs in polynomial time if the variable $n$ is something else (like the number of edges in a graph).



Edit: Could an algorithm that is $O(N)$ (where $N$ is the number of trees in the graph) also be considered as being in $P$?










share|cite|improve this question











$endgroup$




In order to assert that a given algorithm for graphs runs in polynomial time, must the variable in the big-O function that represents the run time (denoted henceforth as $O(f(n))$) be the number of vertices? Or can one say that a graph algorithm runs in polynomial time if the variable $n$ is something else (like the number of edges in a graph).



Edit: Could an algorithm that is $O(N)$ (where $N$ is the number of trees in the graph) also be considered as being in $P$?







graph-theory asymptotics computational-complexity computability






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 29 '18 at 17:31







Aryaman Gupta

















asked Dec 29 '18 at 12:25









Aryaman GuptaAryaman Gupta

507




507








  • 1




    $begingroup$
    The variable could be either of them or a subset of them. It will depend on the case for which time complexity is being determined.
    $endgroup$
    – toric_actions
    Dec 29 '18 at 12:29






  • 1




    $begingroup$
    $Nodesleq 2Edges$ and $Edgesleq Nodes^2$ so a polynomial result for one implies a polynomial result for the other. (Assuming all nodes touch at least one edge)
    $endgroup$
    – Michael
    Dec 29 '18 at 15:49










  • $begingroup$
    If an algorithm is $O(N)$ (Where $N$) is the number of trees in a graph. then is that algorithm still in the complexity class $P$?
    $endgroup$
    – Aryaman Gupta
    Dec 29 '18 at 17:34














  • 1




    $begingroup$
    The variable could be either of them or a subset of them. It will depend on the case for which time complexity is being determined.
    $endgroup$
    – toric_actions
    Dec 29 '18 at 12:29






  • 1




    $begingroup$
    $Nodesleq 2Edges$ and $Edgesleq Nodes^2$ so a polynomial result for one implies a polynomial result for the other. (Assuming all nodes touch at least one edge)
    $endgroup$
    – Michael
    Dec 29 '18 at 15:49










  • $begingroup$
    If an algorithm is $O(N)$ (Where $N$) is the number of trees in a graph. then is that algorithm still in the complexity class $P$?
    $endgroup$
    – Aryaman Gupta
    Dec 29 '18 at 17:34








1




1




$begingroup$
The variable could be either of them or a subset of them. It will depend on the case for which time complexity is being determined.
$endgroup$
– toric_actions
Dec 29 '18 at 12:29




$begingroup$
The variable could be either of them or a subset of them. It will depend on the case for which time complexity is being determined.
$endgroup$
– toric_actions
Dec 29 '18 at 12:29




1




1




$begingroup$
$Nodesleq 2Edges$ and $Edgesleq Nodes^2$ so a polynomial result for one implies a polynomial result for the other. (Assuming all nodes touch at least one edge)
$endgroup$
– Michael
Dec 29 '18 at 15:49




$begingroup$
$Nodesleq 2Edges$ and $Edgesleq Nodes^2$ so a polynomial result for one implies a polynomial result for the other. (Assuming all nodes touch at least one edge)
$endgroup$
– Michael
Dec 29 '18 at 15:49












$begingroup$
If an algorithm is $O(N)$ (Where $N$) is the number of trees in a graph. then is that algorithm still in the complexity class $P$?
$endgroup$
– Aryaman Gupta
Dec 29 '18 at 17:34




$begingroup$
If an algorithm is $O(N)$ (Where $N$) is the number of trees in a graph. then is that algorithm still in the complexity class $P$?
$endgroup$
– Aryaman Gupta
Dec 29 '18 at 17:34










1 Answer
1






active

oldest

votes


















1












$begingroup$

Informally: An algorithm is polynomial time if the algorithm runs in time polynomial in the size of the input. Suppose the input for an algorithm is a graph $G$. Then letting $n$ be the number of vertices and $m$ the number of edges, if the algorithm runs in time polynomial in either $n$ or $m$, then that algorithm is considered a polynomial-time algorithm, since the size of $G$ is $n+m$.



An algorithm that runs in time say linear in the number of trees $G$ has [which may be exponential in the size of $G$] is not in $P$. Why? The graph $G$ itself encodes all the information needed for the algorithm and so could be the input. So the algorithm would not run in time polynomial in the size of $G$.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    @HenningMakholm sure. But the OP asked about graphs explicitly, and generalizing, it is whether an algorithm runs in time polynomial in the size of the input.
    $endgroup$
    – Mike
    Dec 30 '18 at 2:44






  • 1




    $begingroup$
    Ah, I think you're right, actually. Never mind.
    $endgroup$
    – Henning Makholm
    Dec 30 '18 at 2:46












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3055793%2fdoubt-regarding-the-variable-by-which-time-complexity-is-measured%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1












$begingroup$

Informally: An algorithm is polynomial time if the algorithm runs in time polynomial in the size of the input. Suppose the input for an algorithm is a graph $G$. Then letting $n$ be the number of vertices and $m$ the number of edges, if the algorithm runs in time polynomial in either $n$ or $m$, then that algorithm is considered a polynomial-time algorithm, since the size of $G$ is $n+m$.



An algorithm that runs in time say linear in the number of trees $G$ has [which may be exponential in the size of $G$] is not in $P$. Why? The graph $G$ itself encodes all the information needed for the algorithm and so could be the input. So the algorithm would not run in time polynomial in the size of $G$.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    @HenningMakholm sure. But the OP asked about graphs explicitly, and generalizing, it is whether an algorithm runs in time polynomial in the size of the input.
    $endgroup$
    – Mike
    Dec 30 '18 at 2:44






  • 1




    $begingroup$
    Ah, I think you're right, actually. Never mind.
    $endgroup$
    – Henning Makholm
    Dec 30 '18 at 2:46
















1












$begingroup$

Informally: An algorithm is polynomial time if the algorithm runs in time polynomial in the size of the input. Suppose the input for an algorithm is a graph $G$. Then letting $n$ be the number of vertices and $m$ the number of edges, if the algorithm runs in time polynomial in either $n$ or $m$, then that algorithm is considered a polynomial-time algorithm, since the size of $G$ is $n+m$.



An algorithm that runs in time say linear in the number of trees $G$ has [which may be exponential in the size of $G$] is not in $P$. Why? The graph $G$ itself encodes all the information needed for the algorithm and so could be the input. So the algorithm would not run in time polynomial in the size of $G$.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    @HenningMakholm sure. But the OP asked about graphs explicitly, and generalizing, it is whether an algorithm runs in time polynomial in the size of the input.
    $endgroup$
    – Mike
    Dec 30 '18 at 2:44






  • 1




    $begingroup$
    Ah, I think you're right, actually. Never mind.
    $endgroup$
    – Henning Makholm
    Dec 30 '18 at 2:46














1












1








1





$begingroup$

Informally: An algorithm is polynomial time if the algorithm runs in time polynomial in the size of the input. Suppose the input for an algorithm is a graph $G$. Then letting $n$ be the number of vertices and $m$ the number of edges, if the algorithm runs in time polynomial in either $n$ or $m$, then that algorithm is considered a polynomial-time algorithm, since the size of $G$ is $n+m$.



An algorithm that runs in time say linear in the number of trees $G$ has [which may be exponential in the size of $G$] is not in $P$. Why? The graph $G$ itself encodes all the information needed for the algorithm and so could be the input. So the algorithm would not run in time polynomial in the size of $G$.






share|cite|improve this answer









$endgroup$



Informally: An algorithm is polynomial time if the algorithm runs in time polynomial in the size of the input. Suppose the input for an algorithm is a graph $G$. Then letting $n$ be the number of vertices and $m$ the number of edges, if the algorithm runs in time polynomial in either $n$ or $m$, then that algorithm is considered a polynomial-time algorithm, since the size of $G$ is $n+m$.



An algorithm that runs in time say linear in the number of trees $G$ has [which may be exponential in the size of $G$] is not in $P$. Why? The graph $G$ itself encodes all the information needed for the algorithm and so could be the input. So the algorithm would not run in time polynomial in the size of $G$.







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Dec 30 '18 at 2:38









MikeMike

4,686512




4,686512












  • $begingroup$
    @HenningMakholm sure. But the OP asked about graphs explicitly, and generalizing, it is whether an algorithm runs in time polynomial in the size of the input.
    $endgroup$
    – Mike
    Dec 30 '18 at 2:44






  • 1




    $begingroup$
    Ah, I think you're right, actually. Never mind.
    $endgroup$
    – Henning Makholm
    Dec 30 '18 at 2:46


















  • $begingroup$
    @HenningMakholm sure. But the OP asked about graphs explicitly, and generalizing, it is whether an algorithm runs in time polynomial in the size of the input.
    $endgroup$
    – Mike
    Dec 30 '18 at 2:44






  • 1




    $begingroup$
    Ah, I think you're right, actually. Never mind.
    $endgroup$
    – Henning Makholm
    Dec 30 '18 at 2:46
















$begingroup$
@HenningMakholm sure. But the OP asked about graphs explicitly, and generalizing, it is whether an algorithm runs in time polynomial in the size of the input.
$endgroup$
– Mike
Dec 30 '18 at 2:44




$begingroup$
@HenningMakholm sure. But the OP asked about graphs explicitly, and generalizing, it is whether an algorithm runs in time polynomial in the size of the input.
$endgroup$
– Mike
Dec 30 '18 at 2:44




1




1




$begingroup$
Ah, I think you're right, actually. Never mind.
$endgroup$
– Henning Makholm
Dec 30 '18 at 2:46




$begingroup$
Ah, I think you're right, actually. Never mind.
$endgroup$
– Henning Makholm
Dec 30 '18 at 2:46


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3055793%2fdoubt-regarding-the-variable-by-which-time-complexity-is-measured%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?