A list is sorted in ascending order if it is empty or each item except the last one is less than or equal to its successor. Define a predicate isSorted that expects a list as an argument and returns True if the list is sorted, or returns False otherwise. (Hint: For a list of length 2 or greater, loop through the list and compare pairs of items, from left to right, and return False if the first item in a pair is greater.)
Q: b. Add a class member function which outputs if the linked list in Problem a. is a palindrome. What…
A: class member function which outputs if the linked list in Problem a. is a palindrome. Using a stack:…
Q: A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are…
A: A palindrome reads the same, when read straight or in reverse. A palindrome may be a single word or…
Q: Python. A list A1, ..., An is given. Leave the list unchanged if its members are sorted…
A: num = [20, 19, 15, 10, 9, 8]res = [num[0], num[1]] if num[0]<num[1]: for i in…
Q: Python Programming You are given a list of M positive numbers, Ao. A1, .., AM-1. You have to answer…
A: As per the given above listed problem statement we are required to develop a python code to solve…
Q: The Binary Search algorithm works by testing a mid-point, then eliminating half of the list. In…
A: Here is the Answer
Q: Write a prolog function, called remove_dup(X,Y), that takes a list X as the input, remove dup(X.Y)…
A: Answer: Prolog Source Code: remove_dub(X,[H|_]) :- X==H,!.remove_dub(X,[_|Y]) :-…
Q: Algortimhs Recursive Thinking) Carefully read the comment of the following function, then complete…
A: Answer: I have done code and also I have attached code as well as output
Q: empty string) and xy is their concatenation. Show that if x, y and xy are all in PALINDROME, then…
A: We have to answer the following questions, Please find in step2.
Q: Write down a recursive definition of the set A that consists of all binary strings that satisfy all…
A: CONDITIONS: The strings are binary represented by 0's and 1's. should be recursive, should end with…
Q: Count growlers def count_growlers(animals): Let the strings 'cat' and 'dog' denote that kind of…
A: Required: def count_growlers(animals): Let the strings 'cat' and 'dog' denote that kind of animal…
Q: 2- Construct a RE over E={0,1} such that It does not contain any string with two consecutive "O"s It…
A: Solution:- 2- Construct a RE over E={0,1} 1) It does not contain any string with two…
Q: Profile the performance of the memoized version of the Fibonacci function defined in Project 6. The…
A: Solution:: class Counter(object): def __init__(self,count=0): self.count=count def…
Q: Path: p Words:0 QUESTION 6 Draw the complete memoized recursive function tree for the Fibonacci…
A: Dynamic programming: Dynamic programming is a concept in programming in which the complex problem…
Q: Only do D part
A: d) ∀ is universal quantifier which means conjunction of all given propositions must be true. ∃ is…
Q: Write a program which reads from a user, a list of positive integers that ends with a sentinel -1.…
A: The ask is to write a program which reads a list of positive integers ending with a sentinel value…
Q: Write a function, called isSymmetric, which returns true if a directed graph is symmetric, false…
A: // C++ program to check if a given Binary// Tree is symmetric or…
Q: Suppose P(x, y) is some binary predicate defined on a very small domain of discourse: just the…
A:
Q: Write a function in a racket code that takes as input a list of elements and returns a list with…
A: Recursion is when a function calls itself in its definition.
Q: 1. Consider the sets: U = {A,B,C,D, E, F,G, H,I,J}, A = {A,C, E} and B = {B,C, D, F,G}. Write the…
A: Given: U={A,B,C,D,E,F,G,H,I,J} A={A,C,E}B={B,C,D,F,G}
Q: Write a recursive function (no auxiliary functions, for/while loops, STL containers or functions,…
A: Here is the C++ function as asked in the question:…
Q: Given a set of buildings, the skyline is the silhouetted shape formed by the highest boundaries of…
A: Here, n rectangular buildings in a 2-dimensional city are given that computes the skyline of these…
Q: 1. Write a program given two binary trees, A and B, searches Tree B for an occurrence of Tree A by…
A: The answer is in below steps:
Q: 8 15 root 10 16 11 1 12 6 17 13 14 18 19 23 20 21 22 24 25 Suppose we implement contains(x) using…
A: How many times is helper function is called in total?
Q: Write a program that replaces words in a sentence. The input begins with an integer indicating the…
A: Program: #include<iostream>#include<vector> using namespace std; int…
Q: Proof of Correctness In this question, you will use strong induction to prove that your new…
A: The, answer has given below:
Q: Change words so that it counts sentences. In particular, deal with the problem of mistakenly…
A:
Q: The reverse of a string x denoted by rev(x) and is defined by the following recursive rule:…
A: A is regular, so there exists a DFA M accepting A. Now, let's construct an NFA N from M as follows.…
Q: Problem In this assignment, you are required to implement the fractional knapsack problem. In a…
A: Program:- class ItemValue: def __init__(self, wt, val, ind): self.wt = wt…
Q: Given an JavaScript object list of books that each have a pages attribute to define the number of…
A: NOTE : I HAD RUN THIS ON COMPILER, IF YOU HAVE NOT COMPILER THEN FOLLOW THESE STEPS: Firstly,…
Q: python code Write a recursive function such that, given a list of intergers (say v) and an integer…
A: Please refer below code and output: def subset(set, n, sum): # Base Case for subset if (sum…
Q: hyphen denotes set difference and ɛ de- notes the empty string. (Hint: L consists of the strings…
A:
Q: A prime that is lesser than the arithmetic mean of the primes before and after it is called weak…
A: In this problem, we need to design the code in the js programming language. Input - Integer Output…
Q: write a function that returns True if, and only if, graph g is a forrest g is represented by an…
A: In this question we have to code a python code to check wether a given list or graph is forest or…
Q: Each case below gives a recursive definition of L≤ {a, b}*. Give a simple nonrecursive definiton of…
A: Consider the subset L, which consists of all strings over the alphabet a, b, including an empty…
Q: A fibonacci series is defined as a series where the number at the current index, is the value of the…
A: Given :- A fibonacci series is defined as a series where the number at the current index, is the…
Q: Give a recursive definition for the set of all strings of a’s and b’s that begins with an a and ends…
A: GIVEN: Give a recursive definition for the set of all strings of a’s and b’s that begins with an a…
Q: Count growlers def count_growlers(animals): Let the strings 'cat' and 'dog' denote that kind of…
A: Python Code: def count_growlers(animals): #Create two lists to store count of cats and dogs…
Q: 20. Consider an algorithm intending to store all prime numbers between 2 and 20 (inclusive) in a…
A: (a) if is_prime(2*i): prime_list.append(2*i) i=i+1increment of i is being done inside the if…
Q: Write a classifier algorithm for p(Y |X,α)
A: Explain a classifier algorithm for p(Y |X,α).
Q: Line with most polnts def line_with_most_points(points): 4 point on the two-dimensional grid of…
A: Given the coordinate points as list find the maximum count of points which belong to same line if…
Q: Please answer the following in Python programming language Assuming that my_tuple is a correctly…
A: Tuples in python are immutable which means we can't modify them i.e. they cannot be changed only few…
Q: In C++ Write a program that replaces words in a sentence. The input begins with an integer…
A: Step 1 The code is given in the below step.
Q: Each case below gives a recursive definition of a subset L of {a, b}". Give a simple non-recursive…
A: It is defined as the procedures or subroutines implemented in a programming language, whose…
A list is sorted in ascending order if it is empty or each item except the last one is less than or equal to its successor. Define a predicate isSorted that expects a list as an argument and returns True if the list is sorted, or returns False otherwise.
(Hint: For a list of length 2 or greater, loop through the list and compare pairs of items, from left to right, and return False if the first item in a pair is greater.)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
- Question 1 write a curried SML function, filter, that takes two arguments, a predicate ( a function that takes a single argument and returns a bool) and a list. Calling filter f L returns a list containing only those elements of L that satisfy f (that is, only those elements that f returns true for are in the resulting list). Calling filter with an empty list returns an empty list. List members should appear in the same order in the results as in L. Do not use explicit recursion Full explain this question and text typing work only thanksConsider the following definition of class Person: 1 public class Person 2 { 3 public final String name; 4 5 public Person(String name) 6 { 7 if (name == null) this.name = "<NoName>"; //No null names... 8 else this.name = name; 9 } 10 } and the definition of class PersonListUtils implemented by a student... 1 public class PersonListUtils 2 { 3 //Replaces the first occurrence of a Person in the list with the given oldPersonName with a new Person having the newPersonName. 4 //Returns true if the substitution is successful, false otherwise 5 public static boolean substitute(ArrayList<Person> list, String oldPersonName, String newPersonName) 6 { 7 for (Person person: list) { 8 if (person.name == oldPersonName) { 9 person = new Person(newPersonName); 10 return true; 11 } 12 } 13 return false; 14 } 15 16 //Removes from the list the first occurrence of a Person with the given nameToRemove. 17 //Returns true if the deletion is successful, false otherwise 18 public static boolean…A fibonacci series is defined as a series where the number at the current index, is the value of the summation of the index preceding it (index -1) and (index-2). Essentially, for a list fibonacci_numbers which is the fibonacci numbers series, fibonacci_numbers[i] = fibonacci_numbers[i-1] + fibonacci_numbers[i-2] The fibonacci series always begins with 0, and then a 1 follows. So an example for fibonacci series up to the first 7 values would be - 0, 1, 1, 2, 3, 5, 8, 13 Complete the fibonacci(n) function, which takes in an index, n, and returns the nth value in the sequence. Any negative index values should return -1. Ex: If the input is: 7 the output is: fibonacci(7) is 13 Important Note Use recursion and DO NOT use any loops. Review the Week 9 class recording to see a variation of this solution. def fibonacci(n): if (n < 0 ): return -1 else: return n fibonacci_numbers = (fibonacci[n - 1] + fibonacci[n - 2]) return fibonacci_numbers(n) # TODO: Write…
- The for construct is a recursive procedure that operates on a given list. Thus, it works so long as there are objects to process. Is this a genuine or untrue claim?Define a recursive function removeAll that expects an item and a Lisp-like list as arguments. This function returns a Lisp-like list with all of the instances of the item removed. In the lisplist.py file, make sure to include the insert() and equal() methods from Programming exercise 9.7 and Programming exercise 9.8. Hint: Keep on removing the item if it equals the list’s first item. Here is an example of its use: >>> lyst = cons(2, cons(2, (cons 3, THE_EMPTY_LIST))) >>> lyst (2 2 3) >>> removeAll(2, lyst) (3) >>> removeAll(3, lyst) (2 2) File: lisplist.py Project 9.9 Adds a removeAll function for Lisp lists. Add the insert() and equal() methods from Programming Exercise 9.7 and 9.8 """ class Node(object): """Represents a singly linked node.""" def __init__(self, data, next = None): self.data = data self.next = next def __repr__(self): """Returns the string representation of a nonempty lisp list."""…Example: (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)⟶(1 2 3 4 8 7 6 5 9 10 11 12 16 15 14 13) You may use an auxiliary function to reverse the order of elements in a list. respectively a Prolog predicate, solve it by prolog how to solve this please solve it in detail. please I need it today
- (a) Write a function top_students(marks) that takes as a parameter a non-empty list of (name, mark) tuples, where name is the name of a student (a string) and mark is the student's mark for some course (an int). The function returns a list of the names of all students whose mark equals that of the top student. If there is just a single student with the maximum mark, the return value will be a list of length 1, as in the first example in the table below. The names in the return list should be in the same order as in the input parameter list. Test Result marks = [('Beatrice', 50), ('Nerly', 90), ('Uniza', 70)] print(top_students(marks)) ['Nerly'] marks = [('Beatrice', 80), ('Nerly', 75), ('Uniza', 66), ('Joshua', 80)] print(top_students(marks)) ['Beatrice', 'Joshua'] (b) Write a function char_counts(string) that takes a string as a parameter and returns a dictionary in…In Kotlin A. Write a function lengthGreaterThan() with an expression body that takes a String s and an Int n and returns true if the String is at least n characters long. Then revise the function so that it can accept null values. If it receives null as the parameter, it should return false. B. Write a recursive function with an expression body that takes a list of nullable Strings and and Int an returns a list of just the Strings from the original list for which the function you wrote in the first part returns true C. Get the same result as in part B by using filter()In C++, write a program that outputs the nodes of a graph in a breadth first traversal. Data File: Please use this data file. Text to copy: 100 1 3 -9991 4 -9992 5 -9993 2 -9994 -9995 7 8 -9996 4 7 -9997 -9998 -9999 7 8 -999 Diagram: Also, please take a look at the attached figure on and calculate the weights for the following edges: 0 -> 1 -> 4 0 -> 3 -> 2 -> 5 -> 7 0 -> 3 -> 2 -> 5 -> 8 6 -> 4 6 -> 7 9 -> 7 9 -> 8 To calculates these weights, please assume the following data: 0 -> 1 = 1 0 -> 3 = 2 1 -> 4 = 3 3 -> 2 = 4 2 -> 5 = 5 5 -> 7 = 6 5 -> 8 = 7 6 -> 4 = 8 6 -> 7 = 9 9 -> 7 = 10 9 -> 8 = 11
- Complete the examples in the docstring and then write the body of thefollowing function:def same_first_last(L):""" (list) -> boolPrecondition: len(L) >= 2Return True if and only if first item of the list is the same as thelast.>>> same_first_last([3, 4, 2, 8, 3])True>>> same_first_last(['apple', 'banana', 'pear'])>>> same_first_last([4.0, 4.5])"""Consider a (singly) linked list. Describe an algorithm to remove every second element from the list. (HINT: The algorithm is similar to the one that is used when we delete a single node. Here, we need to skip an element after every deletion, and then if we have not reached the end of the list repeat this procedure until the list is exhausted.). (a) Write the steps to removeEverySecondElement from the linked list. (b) Write a function removeEverySecondElement() that implements the taskWrite a program that replaces words in a sentence. The input begins with an integer indicating the number of word replacement pairs (original and replacement) that follow. The next line of input begins with an integer indicating the number of words in the sentence that follows. Any word on the original list is replaced. Ex: If the input is: 3 automobile car manufacturer maker children kids 15 The automobile manufacturer recommends car seats for children if the automobile doesn't already have one. then the output is: The car maker recommends car seats for kids if the car doesn't already have one. You can assume the original words are unique. For coding simplicity, follow each output word by a space, even the last one. Hint: For words to replace, use two vectors: One for the original words, and the other for the replacements. Your program must define and call the following function that returns index of word's first occurrence in wordList. If not found, then the function returns -1.int…