Enable contrast version

# Tutor profile: Derrick T.

Inactive
Derrick T.
Software Engineer and Critical Thinker
Tutor Satisfaction Guarantee

## Questions

### Subject:Software Engineering

TutorMe
Question:

Describe the iterator design pattern and where it is appropriate to use.

Inactive
Derrick T.

An iterator is a design pattern that allows for a variable to be looped over because it contains a collection of items. A very common example of using an iterator is for list-like data structures. Iterators abstract away how the underlying collection of items is stored and allow the caller to focus on looping over each item one-by-one. For example, a collection of items may be too large to store in memory, so the iterator would be responsible for keeping track of where it is in the collection and loading the next items into memory when the caller requests them. The caller in this case does not need to concern itself with loading items from disk.

### Subject:Computer Science (General)

TutorMe
Question:

Suppose you are looking to create a priority queue data structure that will never need to hold more than 100 items at a time. As a requirement, you have been restricted to using either a fixed-size array or linked list to construct this queue. Which option would you choose and why?

Inactive
Derrick T.

Let's start by defining a queue, and more specifically, a priority queue. A queue is generally a data structure in which items are added to a list and removed from the list in the same order. For example, if two items are added to a queue, the first item added would be the first one to be removed. With a priority queue, each item added is given a priority value so that items with the highest priority are removed before items of lower priority. Priority queues therefore need be able to sort items as they are added since this will incur the lowest overall cost between adding and removing items from the list. Regardless of the underlying data store (fixed-size array or linked list), the cost of removing an item from the queue can be performed in constant time ($$O(1)$$). Adding items to the priority queue, however, differs in performance between these data stores. With a linked list, finding the place to insert an item has a worst-case runtime of $$O(n)$$ and inserting the item has a worst-case runtime of $$O(1)$$. For a fixed-size array, finding the place to insert an item again has a worst-case runtime of $$O(n)$$, but actually inserting the item has a worst-case runtime of $$O(n)$$ since items may need to be shifted over to make space for the new item. Since adding items is less expensive for a linked list, the preferred option would be to use a linked list over a fixed-size array.

### Subject:Physics

TutorMe
Question:

Suppose you throw a ball straight outwards from the top of the Eiffel Tower (300 meters) and are looking to just miss the base of the tower when the ball hits the ground. Given that the base of the Tower is a 100 meter square and assuming zero air resistance, how fast must the ball be going when it leaves you hand?

Inactive
Derrick T.

Let's first figure out how long it will take the ball to reach the ground. We can then use this time to determine the velocity along the horizontal axis. The following equation can be used to describe an objects position when acted on by a constant acceleration: $$y = \frac{1}{2}at^{2} + v_{0}t + y_{0}$$ Assuming acceleration due to gravity is $$10 m/s^{2}$$, to keep numbers simple, we can just plug in each of our variables. $$0 = \frac{1}{2}(-10)t^{2} + 0t + 300$$ Notice that $$v_{0}$$ is zero in this equation since the ball initially has no velocity in the vertical axis. Solving this expression, we get that $$t = 60$$ seconds. Now, let's solve for the horizontal axis. Since the tower is 100 meters at its base and we're situated in the center of this square, our ball must therefore travel at least 50 meters to reach the edge. Using the same equation from before, but given there is no acceleration in the horizontal axis, we have the following: $$x = vt - x_{0}$$ $$50 = 60v - 0$$ $$v = 0.833 m/s$$ (only 1.86 mph!)

## Contact tutor

Send a message explaining your
needs and Derrick will reply soon.
Contact Derrick