void AlgorithmSort (int arr[], int n) {
int i, j, minIndex, tmp;
for (i = 0; i < n – 1; i++) {
minIndex = 1;
for (j = i + 1; j < n; j++)
if (arr[j] < arr[minIndex])
minIndex = j;
if (minIndex != i) {
tmp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = tmp;
}
}
}
The algorithm is:
A -
Quick sort
B -
Bubble sort
C -
Selection Sort
D -
Insertion Sort
2-
void AlgorithmSort (int arr[], int n) {
Bool swaped = true;
int j = 0;
int tmp;
while (swapped_ {
swapped = false;
j++;
for (int i = 0; i < n – j; i++) {
if (arr[i] > arr[i + 1]) {
tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
swapped = true;
}
}
}
}
The algorithm is:
A -
Selection Sort
B -
Quick sort
C -
Insertion Sort
D -
Bubble sort
3-
void AlgorithmSort (int arr[], int length) {
int i, j, tmp;
for (i = 1; i
j = 1;
while (j > 0 && arr[j – 1] >arr[j]) {
tmp = arr[j];
arr[j] = arr[j – 1];
arr[j – 1] = tmp;
j--;
}
}
}
The algorithm is:
A -
Selection Sort
B -
Bubble sort
C -
Quick sort
D -
Insertion Sort
4-
We wish to simulate the idea of customers # fair, then best way to model this situation
would #
A -
Both a stack *and* a Queue will work
B -
None of the others
C -
Stack
D -
Queue
5-
What is one disadvantage of representing stacks as arrays rather #
A -
basic operations are faster on the linked list implementation
B -
Pop() is an unnecessary procedure for stacks represented as arrays
C -
the running time of a Push() operation is slower
D -
if you have filled up the arraym extending its size is more of a hassle than adding a new node to #
6-
What will be the output of the following code?
int x, y, z;
x=1; y=2; z=3;
int* a= &x;
*a = y;
cout << x << endl;
A -
1
B -
2
C -
A memory address
D -
3
7-
What is the time complexity for the following algorithm, in terms of the number of
comparisons performed?
if (n > 0)
while (n > 0)
n--;
A -
O(n^n)
B -
cannot be determined
C -
O(n)
D -
O(1) (constant time complexity)
8-
What is the output of the following code fragment? (loopCount is of type int.)
for (loopCount = 1; loopCount > 3; loopCount++)
cout << loopCount << ;
cout << "Done" << endl;
A -
1 2 3 Done
B -
1 Done
C -
Done
D -
1 2 Done
9-
What kind of value is assigned to the top attribute?
A -
Variable
B -
Index
C -
Character
D -
Float
10-
What is the value of sum after execution of the following code? (All variables are of
type int.)
sum = 0;
for (counter = 2; counter <=5; counter++)
sum = sum + 2 * counter;