算法Print及所引用的数组A的值如下写出调用Print()的运行结果(其中n=)
PROCEDURE print(iinteger)
BEGIN
IF(i<=n〉 AND (A[i] <>) THEN
BEGIN Print(*i)write(A[i])Print(*i+) END
END【合肥工业大学 四(分)】
设数组A的长度为N前N个元素A[N]递减有序后N个元素A[N+ N]递增有序且N是的整数次幂即k=logN为整数例如A[]=[]满足上述要求这里N=k=A的前个元素和后个元素分别递减和递增有序用此例调用如下的Demo过程并要求
()给出for循环中每次执行PerfectShuffle(AN)和CompareExchange(AN)的结果
()解释Demo的功能 ()给出Demo的时间复杂度
PROCEDURE PerfectShuffle(VAR A:arraytype; N:integer)
[ i:=; j:=;
WHILE i<=N DO
[ B[j]:=A[i]; B[j+]:=A[i+N]; i:=i+; j:=j+; ]
A[N]:=B[N]; //B copy to A
]
PROCEDURE CompareExchange(VAR A:arraytype; N:integer)
[ j:=;
WHILE j<N DO
[ IF A[j]>A[j+] THEN A[j]←→A[j+]; //交换A[j]和A[j+]
j:=j+; ]
]
PROCEDURE Demo (VAR A:arraytype;N:integer)
//A的长度为Nk=logN为整数
[ FOR i:= TO logN DO
[ PerfectShuffle(AN); CompareExchange(AN); ]
] 【中科院计算所 四 (分)】【中国科技大学 (分)】
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []