Professional Documents
Culture Documents
Counting microseconds
a. Counting the number of statements
b. Counting the number of key operations
c. Counting the kilobytes of algorithm
a. f(n) is O(n3)
b. f(n) is O(n2)
c. all the above
d. none of the above
4. The best big-O function that bounds the following function: F(n)= 1 + 2 + ... + n is
a. O(n2)
b. O(n)
c. O(logn)
5. What is the running time for the following code:
for i = 1 to n do begin
for j = i+1 to n do
print "*";
print carriage return
end
a. O(n)
b. O(n2)
c. O(n3)
10. The running time for adding element at position i to an array list is:
a. O(n)
b. O(n2)
c. O(1)
Recursion:
a. super_write_vertical(-1023)
b. super_write_vertical(0)
c. super_write_vertical(100)
d. super_write_vertical(1023)
12. In a real computer, what will happen if you make a recursive call without making the
problem smaller?
DeleteNumber(Num)
{
AddEmployee(EmployeeName)
{
For( i=0; i<=array.lenght; i++)
If array[i] > studentName{
For( j = arraySize, j>=i ; j--)
Array[j+1] = array[j];
Array[i] = studentName;
}
c. InsertBefore (x, y) that inserts a node to the linked list with element y before the
node containing element x.
Current = head;
prev = head;
While(current != null)
If (current.element = x){
newNode.next = current;
prev = newNode;
}
Prev = current;
Current = current.next;
}
d. countHowMany(x) : counts the number of x occurrences in a linked list.