interview quiz# JobHunting - 待字闺中
a*r
1 楼
For questions 1-4, assume that an array stores integers and has a maximum
size of 100. The array is used to store two distinct data structures, BOTH
a queue and a stack. The answer should be written in C or C++ and should
not use any existing data structure libraries.
1.Write a function that pushes an integer into the stack.
2.Write a function that pops an integer from the stack.
3.Write a function that enqueues an integer into the queue.
4.Write a function that dequeues an integer from the queue.
5.For the given C function, below, please answer the 3 questions below:
int Function()
{
int intArray[N];
int arraySum = 0;
for (int i = 0;i< N;i++)
{
intArray[i] = i;
For(int J = 1;j {
intArray[i] = J * intArray[
i]
}
}
For(int k = 0;k {
arraySum += intArray[k];
}
return arraySum;
}
a)Give the O(n) runtime complexity for the function.
b)Give an optimized version (if one exists) for the function.
c) Give the O(n) runtime complexity for the optimized version.
size of 100. The array is used to store two distinct data structures, BOTH
a queue and a stack. The answer should be written in C or C++ and should
not use any existing data structure libraries.
1.Write a function that pushes an integer into the stack.
2.Write a function that pops an integer from the stack.
3.Write a function that enqueues an integer into the queue.
4.Write a function that dequeues an integer from the queue.
5.For the given C function, below, please answer the 3 questions below:
int Function()
{
int intArray[N];
int arraySum = 0;
for (int i = 0;i< N;i++)
{
intArray[i] = i;
For(int J = 1;j
intArray[i] = J * intArray[
i]
}
}
For(int k = 0;k
arraySum += intArray[k];
}
return arraySum;
}
a)Give the O(n) runtime complexity for the function.
b)Give an optimized version (if one exists) for the function.
c) Give the O(n) runtime complexity for the optimized version.