Question

Write a ML language function stripmin of type int list -> int list that will return a list from which every instance of the lowest value has been removed.

Here are a few examples of expected behavior: - stripmin [1,0,2,3,0,5]; val it [1,2,3,5] : int list - stripmin [1,0,2,3,0,5,~

Hints:

• Only stripmin itself should be visible at the top level;

•You should have two recursive helper functions tucked away inside a let … in … end; structure

• Also include a val to avoid having to pass a value that never changes to one of these functions.

• Use appropriate pattern matching in your parameters.

• The efficiency of the solution is O(n).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

fun remove_element (elemlist, elem) =
case elemlist of
[] => []
| head::tail => if elem = head
then remove_element (tail, elem)
else head::remove_element (tail, elem)

fun stripmin list = remove_element(list, minimum(list))

try this code and get your answer

here minimum is the inbuilt function in some of the machines otherwise use below minimum function


fun minimum(xs)=
   case xs of
       [] => NONE
   | (head::[]) => SOME head
   | (head::neck::rest) =>   if head < neck
                   then minimum (head::rest)
                   else minimum (neck::rest)

then you will get exact answer

but it look like while using minimum function it will be O(n2) if it is inbuilt then the answer will be in O(n)

Add a comment
Know the answer?
Add Answer to:
Write a ML language function stripmin of type int list -> int list that will return...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function isaset which takes a list of any equality type2 and returns true if the list is a set (each element app...

    Write a function isaset which takes a list of any equality type2 and returns true if the list is a set (each element appears exactly once). So, the type of isaset is ' 'a list -> bool. Hints: • Do not try for efficiency. A brute-force O(n2 ) solution is appropriate to this exercise. 3 • You might find it easier to develop an algorithm if you consider how to determine the list is not a set. • A recursive...

  • Write a function isaset which takes a list of any equality type2 and returns true if...

    Write a function isaset which takes a list of any equality type2 and returns true if the list is a set (each element appears exactly once). So, the type of isaset is ' 'a list -> bool. Hints: • Do not try for efficiency. A brute-force O(n2 ) solution is appropriate to this exercise. 3 • You might find it easier to develop an algorithm if you consider how to determine the list is not a set. • A recursive...

  • a) You must write a recursive function that takes something of the form: ([(Int, Int, Int),...

    a) You must write a recursive function that takes something of the form: ([(Int, Int, Int), Int, Int) as an argument and returns something of the form: LE(Int, Int, Int)]] which should be interpreted as a list of lists of 3-tuples of RGB values. You may use helper functions if you wish, but your solution must be recursive. You must document the name of your function at the beginning of your code using a comment like -- foo :: ([(Int,...

  • Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function...

    Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function that takes in a string containing some combination of letters, numbers, and spaces, and return the starting index of the first instance of “waldo” contained in that string. If the string does not contain “waldo”, return -1. This function IS case sensitive, so “waldo” is not the same as “WALDO”. Code using string functions such as .index() and .find() that oversimplify the problem will...

  • in ml language or sml Exercise 14 Write a function maxpairs of type (int * int)...

    in ml language or sml Exercise 14 Write a function maxpairs of type (int * int) list -> int lise that takes a list of pairs of integers and returns the list of the max elements from each pair. For example, if you evaluate maxpairs ((1,3), (4,2), (-3,-4)] you should get [3,4,-3).

  • match_enzymes: (str, List[str], List[str]) -> List[list] The return type is a list of two-item [str, List[int]]...

    match_enzymes: (str, List[str], List[str]) -> List[list] The return type is a list of two-item [str, List[int]] lists The first parameter represents a strand of DNA. The last two parameters are parallel lists: the second parameter is a list of restriction enzyme names, and the third is the corresponding list of recognition sequences. (For example, if the first item in the second parameter is 'BamHI', then the first item in the third parameter would be 'GGATCC', since the restriction enzyme named...

  • In python please 6 annoying_int_sequence(n) In annoying_recursion.py, write the function annoying_int_sequence(n) which takes a single integer...

    In python please 6 annoying_int_sequence(n) In annoying_recursion.py, write the function annoying_int_sequence(n) which takes a single integer parameter (which must be non-negative). It must return a list of intgers. The contents of the integers are defined recursively. Basically, each version of this sequence is made up of the next-smaller one, repeated n times - and with the number n in-between. For instance, the sequence for n = 3 is: ???? 3 ???? 3 ???? Just drop in the the sequence for...

  • Java Write the function void insertAtTail (int v). Don’t add any class variables to the List...

    Java Write the function void insertAtTail (int v). Don’t add any class variables to the List class. Here are the class definitions of Node and List that implement a linked list. class Node {private Node next; private int key; Node (Node nxt, int keyValue);//constructor Node getNext(); int getKey(); void putNext(Node nxt);} class List {//assume the class does not use a dummy Node private Node head; List ();//constructor boolean exists (int ky);//returns true if v is in the list void insertAtHead(int...

  • You are tasked with implementing a recursive function void distanceFrom(int key) on the IntList class (provided)....

    You are tasked with implementing a recursive function void distanceFrom(int key) on the IntList class (provided). The function will first search through the list for the provided key, and then, recursively, change all previous values in the list to instead be their distance from the node containing the key value. Do not update the node containing the key value or any nodes after it. If the key does not exist in the list, each node should contain its distance from...

  • C PROGRAMMING #include <stdio.h> #include <stdlib.h> struct nodet { int data; struct nodet *link; }; struct...

    C PROGRAMMING #include <stdio.h> #include <stdlib.h> struct nodet { int data; struct nodet *link; }; struct nodet *makeAnode(int val) { struct nodet *box; box = malloc(sizeof(struct nodet) ); box->data = val; box->link = NULL; return box; } void printList(struct nodet *L) { struct nodet = *mov; mov = L; while(mov != NULL) { printf("%d ", mov->data); mov = mov->link; } printf("\n"); } // THIS SHOULD COUNT HOW MANY ITEMS (NODES) ARE IN THE LIST. int listLen(struct nodet **L) { int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT