Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(a) Write an algorithm that takes a list that contains words and find the longes

ID: 3560734 • Letter: #

Question

(a) Write an algorithm that takes a list that contains words and find the longest word that has no repeated characters. If there is more than one word that is longest, your program should produce all equally long words. Your algorithm may also use the following operations on lists:

Make a list

Add item to the end of a list

Delete item at position k

Insert item at position k

Get the item at position k

Change the item at position k

Get the length of the list

Turn a word into a list of letters

Sort the items in a list

Return

Explanation / Answer

(A) In this algorithm we would calculate the length of all the words in the list and find the maximum length of a word which has non-repeating-characters. Then we will pick all such words whose length is equal to this maximum length.

Steps

(B)In this algorithm we will first sort the items in the list. If the list has repeated item, those repeated item would get arranged next to each other after sorting. Finally, we would check for consecutive same item in sorted list.

Steps
1. Sort the items in the given list
2. run through each item in list(get the item at position k where k goes from 1 to length of the given list)
3.a if item at position k is equal to item at position k-1 ( repeating character exists)
3.b return false
4. if method has not returned in step 3 ( no repeating characater exists)
5. return true