def first_preceded_by_smaller(items, k=1):
Q: Subject : computer sciences \ operating systems Question : Briefly Explain the following . Virtuali...
A: Operating system virtualization is virtual technology and it is a type of server virtualization It i...
Q: Define a heuristic function for the problem you selected above and in 20 words define how it fulfils...
A: Heuristic functions play a crucial rule in optimal planning and the theoretical limitations of algor...
Q: Lai 16 * Write C program to find the result of X in the following equation X =, A + A3 + A5 + A7 + ....
A: code:-- // for getting the power function #include <math.h>#include <stdio.h> int main()...
Q: Q1/ Write a C + program to calculate the value of W from the following relationship using the for lo...
A: C++ Program for above : #include <bits/stdc++.h> using namespace std; double calculate(int...
Q: How would I answer both these questions in python?
A: We need to write a python code that prints two lines without directly using copy1, copy2 and copy3 v...
Q: Write C program to find the result of X in the following equation
A: Code: #include<math.h>#include <stdio.h>int main(){ //declaring required variables ...
Q: Write a C++ program to calculate Fubanaci numbers Xn, n=1,2, ...,10 Xn+1= Xn+ Xn-1, Xo=1,, Xi=1, n=1...
A: It is defined as a direct descendant of C programming language with additional features such as type...
Q: 2. Write simple programs to illustrate the concepts of following in C+ a. Program to caleculate area...
A: Function overloading: Function overloading is a compile-time polymorphism. One function name and mul...
Q: Write and test the following min () function that returns the min of up to two negative numbers: dou...
A: It is defined as MIN will return the minimum value in a given list of arguments. From a given set of...
Q: Write a complete C program for the following question älaäi 16 Write C program to find the result of...
A: Algorithm:- Input value of A and n. if n is not odd then display invalid input. else int sum=0;...
Q: Q3: Write an 8086 program to evaluate a number if it is divisible by 5 or not by display message in ...
A: 1. First we divide the number by 5, store remiander in register. 2. compare the result with 0. 3. if...
Q: Find the product of the elements of a matrix by other elements of a matrix with integer random eleme...
A: Logic:- take row and column from user . You can also fix it by 4*2 for first matrix and 2*4 for se...
Q: nd the sequence of the counter in the figure below. Begin with the counter cleared. D Qo K CLR K CLR...
A: Logic expression for the input
Q: How could I fill in the blank so both functions return the same thing?
A: Please find the answer below :
Q: Q.1 Consider the logic circuit shown in Fig. below. Determine the Boolean expression at the circuit ...
A:
Q: Question # 2: Show the marking of the following Petri nets? (a) (b)
A: Petri Net is graphical representation of places connected with transitions. Marking of petri net is ...
Q: 1. Create a dfa for L = {w ∈ {0, 1}|w starts with a 1 and has exactly three 0s.}
A: Given language To Create a dfa for L = {w ∈ {0, 1}|w starts with a 1 and has exactly three 0s.} DFA ...
Q: Time left 0:0 are investments made for the purpose of actively controlling property, assets, or comp...
A: __________ are investments made for the purpose of activety property, assets or companies located in...
Q: Which of the following statements about Fixed length subnet mask (FLSM) is true? O a. Subnet mask is...
A: As per our guidelines we are supposed to answer only one question. Kindly repost the remaining quest...
Q: Develop a Java program that serves as a calculator Addition Multiplication Division Subtraction Po...
A: Given, Addition Multiplication Division Subtraction Power (for xy user is asked x and y) S...
Q: A broadband network typically has a bit rate of more than, (a) 128 Kbits per second (b) 256 Kbits ...
A: We need to find the correct option between the given 4 options. The given statement is - "A broadban...
Q: Task 26 Ask the user for a range (a starting number and an ending number). Count how many numbers ar...
A: Given:
Q: Example 3: State the order of evaluat Z = P* R % Q + W/X-Y3B
A: Following given c expression, first we evaluate * , % and / operator, since associativity is from le...
Q: C++ s=1-2+3-4+5-6 .20 باستخدام جملة for. . .next
A: According to your question if i clear understand your question so below the complete C++ program
Q: ihäi 16 Write C program to find the result of X * in the following equation X = A + A³ + A5 + A? + ....
A: According to the question below the solution: If we take value of A and value of limit of power in...
Q: Review each scenario carefully and respond to each question as either (very ethical, ethical, neithe...
A: Actually, given information: A student found a loophole in the university computer’s security syste...
Q: True or false: Merge sort can be implemented using O(1) auxiliary space.
A: Standard merge sort requires O(n) space to consolidate two merge arrays. We can improve this combini...
Q: There is an error in this code, and its making it stop completing the program properly after the do-...
A: C++ program to find the square roots of quadratic equation :- #include <iostream>#include &l...
Q: int and float are examples of
A: Question. int and float are examples of
Q: Using Python Where am I going wrong with my code that the the "Difficult words percentage is :" keep...
A: Actually, python is a easiest programming language. It is a dynamically typed programming language.
Q: Create an array called grades of type double and length 10
A: Answer : First of all We need to understand what is array ? Why it used ? An array is a data st...
Q: C++ I have to do this program but using the STL class stack to convert the infix expressions to post...
A: #include<bits/stdc++.h> #include<string.h>using namespace std; int prec(char c) { if(c...
Q: Write a program using (Subroutine) to find the following re and store the result in memory location ...
A: It is defined as a low-level programming language for a computer or other programmable device specif...
Q: Write equivalent instruction sequences • using string instruction for the following: MOV AL, [DI] CM...
A: The following is the given set of instructions:- MOV AL, [DI] .........(1) CMP AL , [SI] ...........
Q: I need help please in 15 minutes
A: According to the Question below the following Answer Program is for check input number is even or ...
Q: A device which is responsible for ensuring that only authorised packets enter the network is known a...
A: Network adapter is a piece of hardware which acts as an interface for a computer to a network Theref...
Q: A complex number x=(X + JY) contains two parts, a Write a computer program using C++ using data stru...
A: Programming instructions: Include necessary header files, Create a Structure to store the complex...
Q: Review each scenario carefully and respond to each question as either (very ethical, ethical, neithe...
A: Actually, given information: Review each scenario carefully and respond to each question as either (...
Q: c) Provide the Boolean Expression Z from the circuit diagram below. Do B Ol z D
A: C) Provide the boolean expression Z from the circuit diagram: Answer: Z = (AB'+B'C)+(C'+D)C
Q: for 33 you need to have and understanding what is a graph, and a tree. Have an explanation what is a...
A: A tree and a graph both are data structures, that have large applications in real world, they both h...
Q: An email that is from an unsolicited, commercial, bulk emailing system, are often considered spam. S...
A: Spam emails contains unsolicited information in them and they are intended to reach out to the large...
Q: Write a program that calculates y = −x2. 16bit
A: Answer :- include <bits/stdc++.h> using namespace std; void getParabolaDetails(float a, fl...
Q: Use assembly language.
A: In computer programming, assembly language, often abbreviated asm, is any low-level programming lang...
Q: Matlab
A: MATLAB is a programming language used for mathematical calculations, function plotting, controller i...
Q: Write and test the following min () function that returns the min of up to two negative numbers: dou...
A: Since you have not mentioned the programming language choice, we will be answering this question in ...
Q: Instructions Write a program to illustrate how to use the temporary class, designed in Exercises 13 ...
A: Actually, program is an executable software that runs on a computer.
Q: Convert the following Boolean expression to a circuit, draw the circuit on EWB and simulate it to fi...
A:
Q: Which is not part of an interface specification: operations attributes associations O implementation
A: Answer :- A user interface specification (UI specification) is a document that captures the details ...
Q: What does each copy represent, A B or C
A: A shallow copy constructs a new compound object and then (to the extent possible) inserts references...
Q: python
A: Python Code: #LAB 1:Part 2 print("Please enter the radius of circle: ")r = float(input())print("The ...
That's enough for you!
def first_preceded_by_smaller(items, k=1):
Given a list of items, find and return the value of the first element for which at least k smaller elements precede that element in items. If no such element exists inside the list, this function should return None. The required k smaller items do not need to be consecutive immediate predecessors of the current item, but can be any k items positioned before the current element.
items | k | Expected result |
[4, 4, 5, 6] | 2 | 5 |
[42, 99, 16, 55, 7, 32, 17, 18, 73] | 3 | 18 |
[42, 99, 16, 55, 7, 32, 17, 18, 73] | 8 | None |
['bob', 'carol', 'tina', 'alex', 'jack', 'emmy', 'tammy', 'sam', 'ted'] | 4 | 'tammy' |
[9, 8, 7, 6, 5, 4, 3, 2, 1, 10] | 1 | 10 |
[42, 99, 17, 3, 12] | 2 | None |
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
- Count dominators def count_dominators(items): An element of items is said to be a dominator if every element to its right (not just the one element that is immediately to its right) is strictly smaller than it. By this definition, the last item of the list is automatically a dominator. This function should count how many elements in items are dominators, and return that count. For example, dominators of [42, 7, 12, 9, 13, 5] would be the elements 42, 13 and 5. Before starting to write code for this function, you should consult the parable of "Shlemiel the painter" and think how this seemingly silly tale from a simpler time relates to today's computational problems performed on lists, strings and other sequences. This problem will be the first of many that you will encounter during and after this course to illustrate the important principle of using only one loop to achieve in a tiny fraction of time the same end result that Shlemiel achieves with two nested loops. Your workload…def eliminate_neighbours (items): Given the sequence of integer items that are guaranteed to be some permutation of positive integers from 1 to n where n is the length of the list, find the smallest number among those that still remain in the list, and remove from the list both that number and whichever of its current immediate neighbours is larger. The function should repeat this basic operation until the largest number in the original list gets eliminated. Return the number of removal operations that were needed to achieve this goal. For example, given the list [5, 2, 1, 4, 6, 31, the operation would remove element 1 and its current larger neighbour 4, resulting in the list [5, 2, 6, 3]. Applied again, that operation would remove 2 and its current larger neighbour 6, thus reaching the goal in two steps. items Expected result [1, 6, 4, 2, 5, 3] 1 [8, 3, 4, 1, 7, 2, 6, 5] 3 [8, 5, 3, 1, 7, 2, 6, 4] 4 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 5 range (1, 10001) 5000 [1000] + list(range (1, 1000))…The function that will a single items to the list is Oextend (...) Oadd(...) Oappend(...) Olengthen(...)
- flip_matrix(mat:list)->list You will be given a single parameter a 2D list (A list with lists within it) this will look like a 2D matrix when printed out, see examples below. Your job is to flip the matrix on its horizontal axis. In other words, flip the matrix horizontally so that the bottom is at top and the top is at the bottom. Return the flipped matrix. To print the matrix to the console: print('\n'.join([''.join(['{:4}'.format(item) for item in row]) for row in mat])) Example: Matrix: W R I T X H D R L G L K F M V G I S T C W N M N F Expected: W N M N F G I S T C L K F M V H D R L G W R I T X Matrix: L C S P Expected: S P L C Matrix: A D J A Q H J C I Expected: J C I A Q H A D JArithmetic progression def arithmetic_progression(items): An arithmetic progression is a numerical sequence so that the stride between each two consecutive elements is constant throughout the sequence. For example, [4, 8, 12, 16, 20] is an arithmetic progression of length 5, starting from the value 4 with a stride of 4. Given a non-empty list items of positive integers in strictly ascending order, find and return the longest arithmetic progression whose all values exist somewhere in that sequence. Return the answer as a tuple (start, stride, n) of the values that define the progression. To ensure unique results to facilitate automated testing, if there exist several progressions of the same length, this function should return the one with the lowest start. If several progressions of equal length emanate from the lowest start, return the progression with the smallest stride. items expected results [42] (42, 0, 1) [2, 4, 6, 7, 8, 12, 17] (2, 2, 4) [1, 2, 36, 49, 50, 70, 75, 98,…Double trouble def double_trouble(items, n): Suppose, if just for the sake of argument, that the following operation is repeated n times for the given list of items: remove the first element, and append that same element twice to the end of items. Which one of the items would be removed and copied in the last operation performed? Sure, this problem could be finger-quotes “solved” by actually performing that operation n times, but the point of this exercise is to come up with an analytical solution to compute the result much faster than actually going through that whole rigmarole. To gently nudge you towards thinking in symbolic and analytical solutions, the automated tester is designed so that anybody trying to brute force their way through this problem by performing all n operations one by one for real will run out of time and memory long before receiving the answer, as will the entire universe. To come up with this analytical solution, tabulate some small cases (you can implement the…
- Double trouble def double_trouble(items, n): Suppose, if just for the sake of argument, that the following operation is repeated n times for the given list of items: remove the first element, and append that same element twice to the end of items. Which one of the items would be removed and copied in the last operation performed?Sure, this problem could be finger-quotes “solved” by actually performing that operation n times, but the point of this exercise is to come up with an analytical solution to compute the result much faster than actually going through that whole rigmarole. To gently nudge you towards thinking in symbolic and analytical solutions, the automated tester is designed so that anybody trying to brute force their way through this problem by performing all n operations one by one for real will run out of time and memory long before receiving the answer, as will the entire universe.To come up with this analytical solution, tabulate some small cases (you can implement the…A lecturer makes use of a list to store the scores of a test similar to the following: var scores = [45,50,89,90,46,67] Each element in the list represents the score obtained by student i, where i is the respective index. To help the lecturer perform some operations, you are required to write and test the following functions Function called captureScores This function accepts an integer representing the number of students in the class e.g. 5 It then captures the scores for the 5 students, one by one, adding them to a list of integers Finally, it returns the list once all n scores have been captured. Hint – Make use of a loop. Start with an empty list, use the add() method to populate your list with scores, one by one as they are captured.A lecturer makes use of a list to store the scores of a test similar to the following: var scores = [45,50,89,90,46,67] Each element in the list represents the score obtained by student i, where i is the respective index. To help the lecturer perform some operations, you are required to write and test the following functions Function called captureScores This function accepts an integer representing the number of students in the class e.g. 5 It then captures the scores for the 5 students, one by one, adding them to a list of integers Finally, it returns the list once all n scores have been captured. Hint – Make use of a loop. Start with an empty list, use the add() method to populate your list with scores, one by one as they are captured. Function called printResults that takes a list of integers as an argument ( e.g. list scores) and prints the result for each score using the following grading scheme Score Result 0 – 44…
- 2. ID: A Name: 2. A list of numbers is considered increasing if each value after the first is greater than or equal to the preceding value. The following procedure is intended to return true if numberList is increasing and return false otherwise. Assume that numberList contains at least two elements. Line 1: PROCEDURE isIncreasing (numberList) Line 2: { Line 3: count 2 Line 4: REPEAT UNTIL(count > LENGTH(numberList)) Line 5: Line 6: IF(numberList[count] =. YA198ICjavascript Define a function, myIncludes, that accepts two parameters: an array and a searchValue. myIncludes should return true if the searchValue is an element in the array. Otherwise, myIncludes should return false. example myIncludes([10, 20, 30], 20); // => true myIncludes(['apples', 'bananas', 'citrus'], 'pears'); // => falseMax Absolute In List Function Lab Description Implement function max_abs_val(lst), which returns the maximum absolutevalue of the elements in list.For example, given a list lst: [-19, -3, 20, -1, 0, -25], the functionshould return 25. The name of the method should be max_abs_val and the method should take one parameter which is the list of values to test. Here is an example call to the function print(max_abs_val([-19, -3, 20, -1, 0, -25])) File Name maxabsinlst.py Score There are three tests each worth 2 points Note: You do not need any other code including the main method or any print statements. ONLY the max_abs_val method is required. Otherwise, the autograder will fail and be unable to grade your code. (I.e., do not include the above example in your code.) The above example should be used be test your code but deleted or comment out upon submission. PYTHON LAB