Name (print): ________________________________

Honor Code Acknowledgment: _____________________________

## Random Quiz 4

Due: October 1

### Problem 1: Iteration (3 pts)

Write a nonrecursive function called RemoveEveryThird which removes every third node of a linked list.

Let each item in the list be represented by the struct Node:

```struct Node
{
string name;
Node * next;
};

```

For example, consider the following list:

RemoveEveryThird(names) returns 2 and the list names is modified to look like:

Calling RemoveEveryThird(names) again returns 2 and the list names is modified to look like:

Complete the function RemoveEveryThird below.

```int RemoveEveryThird(Node * list)
// postcondition: Removes every third node from list and returns the
//                number of nodes removed. If the list has two or fewer
//                nodes, no nodes are removed and 0 is returned.
{
```

### Problem 2: Recursion (3 points)

Write a recursive version of RemoveEveryThird using the same header as above.

### Problem 3: How fast does it take? (2 points)

Assume list has N nodes.

• What is the worst case running time (Big-Oh) that best describes the running time of the function you wrote in problem 1?
• Write a recurrence relation describing the running time of the function you wrote in problem 2. You do not need to solve the recurrence. (T(N)=?, T(0)=?)