• Home
  • Blog
  • it is related to algorithms subject and please solve accordingly

it is related to algorithms subject and please solve accordingly

0 comments

  1. Give a linear time algorithm to solve the circular-list-detection problem (CLD):

Input: A, an array of tuples (v, i), where v is some data and i is an index of a location in the array or -1 to indicate null. Each tuple is a node of a linked list where v is the data inside the node and i is a pointer to the next node in the list. You may assume that -1ilength(A), i.e., that every second item in a tuple is a valid index of the array A.

Output: YES if any linked list represented by tuples in A is circular, NO otherwise.

Example Input 1: A = [(x, 2), (x, -1), (x, 3), (x, 0), (x, 4)]

Example Output 1: YES

Example Input 2: A = [(x, 2), (x, -1), (x, 3), (x, -1), (x, 1)]

Example Output 2: NO

Your solution must:

  1. must solve CLD
  2. Provide an explanation of how your algorithm works
  3. Formal pseudocode of the algorithm
  4. A proof that the algorithm is correct
  5. A symbolic runtime analysis of the algorithm

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}