Write an algorithm to detect if there is a loop in a singly linked list. Hint: The best solution can be done in O(n) time using constant memory.
Write an algorithm to detect if there is a loop in a singly linked list. Hint: The best solution can be done in O(n) time using constant memory.
Come up with an algorithm to shuffle a deck of cards. Discuss how uniform a distribution your solution would achieve, and how you could potentially improve upon it.
Describe an advantage for a linked list over an array and vise-versa.
Consider a singly linked list that has two members: mFirst, a pointer to the first element in the list, and mLast, a pointer to the last element in the list. The time of which of the following operations depends on the length of the list?
a) Delete the last element of the list.
b) Delete the first element of the list.
c) Add an element after the last element of the list.
d) Add an element before the first element of the list.
e) Interchange the first two elements of the list.
Steve writes down a number between 1 and 1000. Jill must determine that number by asking “yes/no” questions of Steve. Jill knows that Steve always tells the truth. If Jill uses an optimal strategy, then she will determine the answer at the end of exactly how many questions in the worst case?