0
* 안녕하세요,이 주제를 다루기 시작 했으므로 여기서는 무엇을해야할지 잘 모르겠습니다. 책의 예는 나를 돕지 않습니다. 이 프로그램은 다음과 복잡성은 N + 1 예를 들어, 우리의 선생님이 그런 식으로 떠나 n으로 단순화하지를 원하는알고리즘의 시간 복잡도를 찾는 방법은 무엇입니까?
public static Stack<Queue<Integer>> qq(Stack<Queue<Integer>> q1)
{
Stack<Queue<Integer>>copy=new Stack<Queue<Integer>>(); // 1
Stack<Queue<Integer>>copy1=new Stack<Queue<Integer>>(); // 1
while(!q1.isEmpty()) // n+1
copy.push(q1.pop()); // n
while(!copy.isEmpty()) // n+1
{
q1.push(copy.top()); // n
copy1.push(copy.pop()); // n
}
while(!copy1.isEmpty()) // n+1
{
Queue<Integer>q=new Queue<Integer>(); // n
copy.push(q); // n
int n1=copy1.top().remove(); // n
while (!copy1.top().isEmpty()==true)
{
for (int i=n1+1;i<copy1.top().head();i++)
copy.top().insert(i);
n1=copy1.top().remove();
}
copy1.pop(); // n
}
while(!copy.isEmpty()) // n+1
copy1.push(copy.pop()); // n
return copy1; // 1
합니다.
내가 쓰지 않은 복잡도를 계산하는 방법을 잘 모르겠다. 나머지는 정확하다고 생각한다. 아무도 나에게 설명 할 수 있을까? 감사합니다.