Explanation of Solution
The algorithm to compare two circularly linked lists “L” and “M” are same sequence of elements given below:
Algorithm:
Input: Two circularly linked list “L” and “M”.
Output: Return true when two circular linked lists “L” and “M” are same sequence of elements. Otherwise, return false.
equal(L :Circularly linked list, M Circularly linked list):
//Create new node for list "L" and "M"
Create a new node "a" and "b"
/*Call getHead() method using circularly linked list "L" to assign the head of list as "a". */
a = L.getHead();
/*Call getHead() method using circularly linked list "M" to assign the head of list as "b". */
b = M.getHead();
/*Loop executes until the next node of list is not equal to "null" for both lists. */
while (a.getNext()!= null || b.getNext()!= null)
{
/*Loop executes until both list elements are not equal. */
while(a.getElement() != b.getElement())
//Assign next node as "b"
b = b.getNext();
//Assign next node as "a"
a = a.getNext();
/*Call getHead() method using circularly linked list "M" to reassign the head of list as "b". */
b = M...
Trending nowThis is a popular solution!
Chapter 3 Solutions
Data Structures and Algorithms in Java
- 1. Analyze the word finder with wild card characters scenario to form the algorithm and compute the time complexity. You are given a list of characters with size n, m. You need to read character data provided as input into this list. There is also a list of p words that you need to find in the given problem. You can only search in left, right, up and down direction from a position. There are two wild characters *' and '+' ,if there is any instance of wild card characters for example '+' appears you can match whatever character in your word that you are searching at this position (only one character). Similarly, if you got wildcard *' you can skip any number of characters ( A sequence of characters not necessary same in between the characters) but the last character should be matched in the given data. This means you are not allowed to match a first and last character with *' wildeard. Input: The first line of the input will give you two integers n and m. From the next line you will get…arrow_forwardUse Python Only.arrow_forwardThe Sieve of Eratosthenes is an elegant algorithm for finding all of theprime numbers up to some limit n. The basic idea is to first create a listof numbers from 2 to n. The first number is removed from the list, andannounced as a prime number, and all multiples of this number up to nare removed from the list. This process continues until the list is empty.For example, if we wished to find all the primes up to 10, the listwould originally contain 2, 3, 4, 5, 6, 7, 8, 9, 10. The 2 is removedand announced to be prime. Then 4, 6, 8, and 10 are removed, sincethey are multiples of 2. That leaves 3, 5, 7, 9. Repeating the process,3 is announced as prime and removed, and 9 is removed because it is amultiple of 3. That leaves 5 and 7. The algorithm continues by announcingthat 5 is prime and removing it from the list. Finally, 7 is announced andremoved, and we're done.Write a program that prompts a user for n and then uses the sievealgorithm to find all the primes less than or equal to n.arrow_forward
- python Say that a "hidden pattern" in a list is a series of 3 or more adjacent elements that are even numbers, e.g. [2,2,2] or [8,100,4,50]. So given an input list [2,4,6,5,8,10,2,4,12], there are two hidden patterns: [2,4,6] and [8, 10, 2, 4, 12]. Print the number of hidden patterns in an input list. You can hard-code the input list instead of reading it from the keyboard, e.g., setting the input list to be [2,4,6,5,8,10,2,4,12]. Examples: Input list = [1, 2, 2, 4, 6, 3, 4, 4, 4] Output: 2 Input list = [6, 4, 2, 3, 1] Output: 1 input list = [1, 1, 1, 1] Output: 0arrow_forwardWrite an algorithm that searches a sorted list of n items by dividing it into three sublists of almost n/3 items. This algorithm finds the sublist that might contain the given item and divides it into three smaller sublists of almost equal size. The algorithm repeats this process until it finds the item or concludes that the item is not in the list. Analyze your algorithm and give the results using order notation.arrow_forwardImplement MSD string sorting using queues, as follows: Keep onequeue for each bin. On a first pass through the items to be sorted, insert each item intothe appropriate queue, according to its leading character value. Then, sort the sublistsand stitch together all the queues to make a sorted whole. Note that this method doesnot involve keeping the count[] arrays within the recursive method.arrow_forward
- Python has an inbuilt process, in, for doing this.For instance: x in thislist. You should not use this methodarrow_forwardb3arrow_forwardLet I be a list of integers. Below, there are four expressions that involve the list I. Without even knowing the contents of I, match the expressions to the lists that were evaluated from them. [sum (1[:i]) for i in range (len(1))] Choose. Choose. [1[0] for i in enumerate (1)] [0, 1, 2, 3, 4, 5, 6, 7, 8) fo, 49, 112, 148, 160, 251, 348, 366, 388] (1.7, 4, 4, 3, 1, 2, 6, 2] [97, 91, 63, 58, 49, 36, 22, 18, 12] [1776, 3162, 840, 0, 7110, 8160, 102, 210, 2622] [sorted (1) (i] for i in [8,7,6,5,4,3,2,1,01] [118 for i in 1] Choose. (1**2-13*1+12 for i in 1] Choose.arrow_forward
- Don't try to copy other's content otherwise I'll reduce rating and report sure. Don't send plagiarised response ok. Give me both answers in Java.arrow_forwardI keep getting different answers whats the true answerarrow_forwardGiven a list: queens = [5, 8, 2, 1, 3, 7, 6, 4] Where the queens[ i ] is the row and i is the column. how do I implement a Hill climbing algorithm that are implemented to solve the 8-queens problem?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education