uppose that you are in a competition where you need to visit some nodes to earn
ID: 384980 • Letter: U
Question
uppose that you are in a competition where you need to visit some nodes to earn points and to come back to your starting point as quickly as possible. You are given a set of nodes N = {1, ,n). You start at i N then you earn Pa poin units of time to go from node i to node j. You have to earn at least Ppoints. person who returns to the starting point the first to decide which nodes to visit and in which order to earn at least P points and minimize the total travel time. node 1 . If you visit a n ode ts. You can visit each node at most once. It takes ty wins the competition. So you need to (a) (20) Model this problem.Explanation / Answer
Use two iterators p and q, both initially at the start of the list. Advance p one step at a time, and q two steps at a time. If q reaches the end there is no cycle; otherwise, p and q will eventually catch up to each other in the middle of the cycle
2) Like stacks the linked list and array implementation gives give fast O(1) running times for every opertion so that the linked list is straight forward and left in an exercise.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.