final review

  1. You are given a template sorting function. You use it to sort an array of ints and an array of doubles, but it wont compile when you give it an array of Jedi. Why won't it work?
    Because Jedi are objects, the compiler does not know when one Jedi is greater than or less than another unless the Jedi class contains overloaded greater than and less than (comparison) operators.
  2. (T/F) A recursive function cannot ever call any function other than itself.
  3. (T/F) If a recursive function's base case is never met, the function will recurse infinitely.
    False, the system will run out of memory causeing a stack overflow error.
  4. A ________ variable will stay in memory even after the function that declared it is removed from the stack.
  5. When deleting from a standard linked list, removing the ________ must be treated as a special case.
    head - because without the head the entire list is inaccessible
  6. List the 4 questions that verify that a problem can be solved recursively.
    • (Remember SBCR - smaller, base case, closer, reduce)
    • 1) Can you define the problem in terms of smaller versions of itself?
    • 2) What is/are the base case(s) - when the problem is solved?
    • 3) Will each step (recursive call) move you closer to the solution?
    • 4) Are you guaranteed to reach a base case?
  7. Which linked list variant contains no null pointers (unless it's empty)?
    a) Circular
    b) Doubly linked
    c) Dummy head node
    d) Queue
  8. Why can't a linked list directly access any of its nodes?
    A linked list node can only be accessed using the pointer to it that is stored in the previous node.
  9. What would you have to do to an array to make it work like a Stack?
    • You would keep track of the index of the top element (the largest index of an element in the array).
    • When an element is added to the stack it must be added to the top + 1 index of the array.
    • When an element is removed from the stack the element at the top position of the array must be deleted.
  10. What would you have to do to a Linked List to make it work like a Queue?
    • You should implement a Linked list with a tail pointer because insertions in a Queue happen at the end, while deletions happen at the head.
    • When you add an item to this queue, you must update the tail pointer and update the previous tail's next to point to the new node.
    • When you delete an item from this queue, you use a pointer (curr) to point to the old head, advance head to head-> next, and delete curr.
  11. What do you have to do when enqueueing and dequeueing an in array-based queue to "wrap-around"?
    ******************Look this up *************************
  12. You have a list of numbers that is almost entirely sorted smallest to largest. Only one small-value number is out of place and it is near the end of the list amongst the large numbers. Why would insertion sort outperform bubble sort in this situation?
    Bubble sort can only move items toward the beginning of the list one position for each iteration of the sort algorithm. Insertion sort will move the small-value number to its proper position in the iteration that positions the small-value number into the sorted portion of the list.
  13. If a sequential search is performed on an array, how many items would have to be looked at to find the n-th item in the list?
    n items. 1st = 1 look, 2nd = 2 looks, ...
  14. If a binary search is performed on an array, how many items would have to be looked at to find the n-th item on the list?
    It depends on the position. Since binary search splits the "list" in half each iteration, it depends on the size of the list.
  15. If you const modify a member function in a class, what is the result?

  16. Class definitions always end with:

  17. If you use the static modifier on a local variable in a function, what is the result?

  18. Select the default constructor:

  19. Select the initializing constructor:

  20. Select the copy constructor:

  21. One of these sentences is false, select it.

  22. The #pragma once and #ifndef - #define - #endif combo serve the same purpose. What is it?
    They both serve to prevent redefining the class in memory.
  23. Public inheritance is which type of class relationship?

  24. (T/F) In C++, you can derive a class directly from more than one superclass.
  25. (T/F) Composition is the same as protected inheritance.
  26. In C++, what notation is used to indicate that a function is a pure virtual function?

  27. (T/F) Any pointer can be used to create a dynamic array.
  28. List the big three functions that you need to make when a class uses pointers to create dynamic memory.
    • overloaded assignment operator
    • copy constructor
    • destructor
  29. When does a class's copy constructor execute?

  30. What are friend functions?

  31. The two overloaded operators shown below can be called using (obj + obj2). Indicate which one is a member function of class Goober and which one is not.
    bool operator < (Goober g1, Goober g2);
    bool operator < (Goober g1);
    The first is a non-member; you can tell because it has two arguments. The second is a member because it has one argument.
  32. To prevent a pointer from 'dangling', set its value to ________.
Card Set
final review
Test 1 + test 2 + end of semester