a. A list/array of size N has integer data. There may be duplicate values in the list. You have at your disposal, a genie, who can return the index or all indices (in case of duplicates) of a given data in 2 nanosecond. What is the Big-O order of an algorithm that uses such a genie to determine the locations in the list of a given data? Explain your answer in detail. Note: you do not need to write any code for this question. b. How would the Big-O order change in problem a., if the genie were to take time proportional to the number of duplicates? Explain your answer in detail. Note: you do not need to write any code for this question.
Q: A shrinkable word is a word with more than two characters that can be reduced down to a…
A: In this question, the coding language is not specified then we are doing this question in the CPP…
Q: Write a Python function called append to all that takes two parameters (Ist and s) and returns a new…
A: Below I have provided Python Programming. Also, I have attached the screenshot of the code and…
Q: A[2] * A[3] - ....etc. For this exercise, we would like to implement two solutions and compare their…
A: Code: #include <stdio.h>#include <stdlib.h>#include <time.h>void solution1(long…
Q: Can you answer with the Python software language ? Write a function that takes two arguments:…
A: Python code :- stock = {"salt":100, "sugar":100, "flour":50, "apple":3, "cream":10} ingr =…
Q: Consider an integer array a of length n with indexing starting at 0, where n is a positive integer.…
A: As per the company guidelines answer will be provided to the only one question. Please ask another…
Q: you are given a string X of length n and another string Y of length m ≤n. Say, the indexes p1, p2,…
A: Pseudo code is a term which is frequently utilized in programming and calculation based fields. It…
Q: Task 13 Suppose you have been given the following list of tuples. ist = [("a", 1). ("b", 2). ("a",…
A: PROGRAM CODE: from collections import defaultdict # initializing listtest_list = [("a", 1), ("b",…
Q: Presented with a list of X objects, use a Single Linked List to make a program in Python which does…
A: Singly-linked list A singly linked list is a kind of linked list that is unidirectional, that is, it…
Q: Later in the course, we will use two basic but important data structures: dictionaries and priority…
A: Input : File name Output : List of words
Q: Consider an array of N integers. Describe an algorithm with an 0(N) runtime that processes the array…
A: Please refer below for your reference: Below is a O(n) approach: I have counted the number of null…
Q: Suppose you have declared int list [max_size], int length globally for a static arraylist. Here…
A: To solve this problem basic knowledge of global variables and arraylist is required.
Q: Suppose we have two arrays, a and b, containing numbers of size n and m, respectively. a and b…
A: - We need to code for the common element sum in the arrays.
Q: Write a program, which reads two arrays from the console and checks whether they are equal (two…
A: Objective: This program reads two arrays from the console and checks whether they are equal or not.…
Q: What is the number of element movements required, to insert a new item at the middle of an…
A: We need to find the correct option for the given questions. *** As per the guidelines only 1st…
Q: As we have seen in the previous problem, character strings in Pascal have fixed length. However, we…
A: PROCEDURE SUBSTRING (S1: string; var S2: string, p, n: integer); VAR I, J: integer; BEGIN IF…
Q: Implement the function prototype for binary search below, where a[] is the array to be searched…
A: Lets analyse the binary search method for its complexity : -binary search takes, a sorted list A…
Q: Let A be an array of integers of size 10, whose ith entry is represented by A[i] for i = 0 to 9, and…
A: - According to the rules, we have to check for the element 85 position in the array.
Q: Write a Java program that generates randomly a list of N integers, sorts the generated list using…
A: The Java program is given in step-2.
Q: Write a function that divides an array into chunks of size n, where n is the length of each chunk.…
A: 1. create the method with 2 array 2. create a new array 3. Iterate on the arr argument 4. new res…
Q: 5. Write a program in Java to implement Insertion sort algorithm to sort a given set of elements and…
A: public class Main{ public static int[] sort(int a[]) { int l = a.length; for…
Q: Presented with a list of X objects, Sebastian made a program in Python which does the following:…
A: If we notice cautiously the usefulness of both the techniques func1 and func2 are like turning the…
Q: Later in the course, we will use two basic but important data structures: dictionaries and priority…
A: Input : Name of file Output : List of words in the file
Q: For this problem, we define a word as a sequence of non-empty alphabetic characters (i.e. a, b, z,…
A: The code implementation in C language is shown below. Algorithm: Split string from spaces and store…
Q: Please answer it in Python Sorting a list is to take the minimum and put it at the beginning, then…
A: Introduction: Selection sort is a sorting algorithm that picks the smallest element from an unsorted…
Q: •For the following algorithm, explain what it computes, state what the input size for analysis is,…
A: The given code is used for sorting an array The algorithm that is used here is called bubble sort,…
Q: In python, The Longest Subsequence Problem is a well-studied problem in Computer Science, where…
A: The longest decreaing and increasing ssequence is solved using dynamic programming that the…
Q: Below are my codes, small.txt file, and the output that needs to be printed. Thank you! #include…
A: The required code is given below, modifications has been done at 3 places, it can be found from…
Q: Presented with a list of X objects, Jonathan made a program in Python which does the following:…
A: def fun1(l): a=l[-1] for i in range(len(l)-1,0,-1): l[i]=l[i-1] l[1]=a; return…
Q: b) Consider a program component Binary_Search (list, searched_string) which search a string in an…
A: Binary search : It a searching technique where in you search for an element [key] in an sorted…
Q: Can you ask with the python software language? A 2D matrix can be represented as a list and a…
A: In step 2, you will the Python code.In step 3, you can see the sample output.In step 4, you will…
Q: Implement the following function, without using any data structure. /* Given two vectors of chars,…
A: / include headers #include <bits/stdc++.h> // deinfe the namespace using namespace std; //…
Q: What is the (worst case) time complexity of the following find function, which searches for a key in…
A: The recursive relation of given code T(n) = T(n-1) + K = T(n-2) + K +K = T(n-3) + K…
Q: Given a list of X objects, create a program in Python using a Dequeue that performs the following: •…
A: dequeue dequeue has the features of adding and removing the element from end or starting queue…
Q: A list/array of size N has integer data. There may be duplicate values in the list. You have at your…
A: - The question is to examine and find the time complexity of the algorithms showed. - We have to…
Q: Given an array of integers, return a new array such that each element at index i of the new array is…
A: #include <bits/stdc++.h> using namespace std; /* Function to print product array for a…
Q: The insertion sort was discussed and the implementation was demonstrated in the sorting lecture. In…
A: Code screenshots :
Q: given an array of lets say 30 items, make a function that prints the highest n values, in this case…
A: Given: Array to sort elements upto 10 steps using easiest sorting Algorithm.
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: Consider the given alorithm where A(1:n) is an array of n integers... A) What does the program do?…
A: Please refer below for your reference: Part a) The program finds the largest and smallest elements…
Q: a. Write a version of the sequential search algorithm that can be used to search a sorted list. (1,…
A: //Include the template of class elemType for the sequential //algorithm. template //Begin the…
Q: You want to design an algorithm, called minMax(A,p,r), that takes an array of integers and indexes…
A: Below is the minmax algorithm using divide and conquer technique:
Q: implement QuickSort of ints that sorts the numbers in the non-decreasing order. Implement the…
A: As you have not specified the language in which you want the code. so i will provide the code in c++…
Q: Given a sequence like [1, 2, 3, 4, 5], and an array of sub sequences like [[1,2], [3, 4], [5]],…
A: - We have to check if the subsequences can create the sequence provided or not.
Q: Write a c++ program to add two large integers with up to 300 digits. One approach is to treat each…
A: The program for the above given question is given below:
Q: Write a function in Python, Haskall, or Picat to remove duplicates from a given list. For example,…
A: Answer: we have written function in python to remove duplicate form the list in time complexity O(n)…
Q: Determine whether the sequence of items is strictly ascending so that each element is strictly…
A: The if-else code can be used inside a while loop to check if each element of a list is strictly…
Q: Create a python code that takes a list and find the sequence of consecutive numbers where the…
A: Program Explanation: Python 3 program to print the absolute difference of the consecutive even and…
Q: Write a program that sorts an array of random or sorted numbers using Radix sort algorithms, fill…
A: #include <stdio.h> int findMax(int a[], int n) { int maxx = a[0],i; for(i = 1;…
Q: In python, remove_from_list(my_list, indices): Takes two lists as input. Creates a new list from…
A: 1. create an empty list 2. iterate over the list of words 2.1 if i is in the list of indexes then…
Step by step
Solved in 2 steps
- Write a program in java for the below given problem statement: Given 2 sorted arrays (in increasing order), find a path through the intersection that produces themaximum sum and return the maximum sum. That is, we can switch from one array to another array only atcommon elements. If no intersection element is present, we need to take the sum of all elements from thearray with greater sum.Sample Input:61 5 10 15 20 2552 4 5 9 15Sample Output :81Explanation :We start from array 2 and take sum till 5 (sum = 11). Then we'll switch to array at element 10 and take till15. So sum = 36. Now, no elements are left in array after 15, so we'll continue in array 1. Hence the sum is81.You are given a string X of length n and another string Y of length m ≤n. Say,the indexes p1, p2, p3, p4 and q1, q2, q3, q4 form two sub-sequences, i.e., 0 ≤ p1 < p2 < p3 < p4 < nand 0 ≤q1 < q2 < q3 < q4 < n; then, they are non-overlapping if p4 < q1.The task is to count the maximum number of non-overlapping sub-sequences of X that are thesame as Y . Thus, if X = GAXTYAWBGTAUGBTABGRGTAXB and Y = GTAB, then the answer is3 as shown by the red fonts. We cannot select the underlined GTAB as it overlaps with a red GTAB(i.e., among overlapping sub-sequences, you can select only one of them).Describe an O(m + n) time algorithm to obtain the count. Write a pseudo-code.Create a python code that takes a list and find the sequence of consecutive numbers where the absolute difference of the odd and even indexed numbers are maximum. The code must have a worst-case complexity of O(n*log[n]), you can use a divide-and-conquer approach in the code.input 1: [86, 43, 45, 68, 21]output 1: 0, 1, 2explanation: 86 + 45 - 43 = 8843 + 68 - 45 = 6645 + 21 - 68 = |-2| or 286 + 45 + 21 - 43 - 68 = 41since 88 is the highest, we return 0, 1, 2
- Consider an array A of N values (N entered by the user). Write a C program that creates a second array B such that the i-th element of B, i.e., B[i] is equal to A[0] *A[1] * A[2] * ... A[i]; In other words:- B[0] = A[0]- B[1] = A[0] * A[1];- B[2] = A[0] * A[1] * A[2];- B[3] = A[0] * A[1] * A[2] * A[3]- ....etc.For this exercise, we would like to implement two solutions and compare their complexity /performance in terms of computation time.Solution 1: Implement blindly the following algorithms: for each element B[i], compute A[0] *A[1] * A[2] * .... *A[i] and save the result in B[i];To test the solution, create an array A of 1000 elements and initialize each of its elements with arandom value (instead of asking the user to . To do that, use the function rand, which, every timecalled, returns a random number Questions:- How long does your program take to produce the solution?- Analyze the solution above and explain why it is taking long time. What are the mainfactors that affect how long…The linked list provided below:2 > 3 > 1 > 7 > 5 > 18 > NULLHere the > symbol means a pointer.Write a complete Python program which deletes the third last node of thelist and returns to you the list as below2 > 3 > 1 > 5 > 18 > NULLThe third last node (with a value 7) has now been dislodged from the list.Here are the few things to consider :(a) We do NOT know the length of the list.(b) Your solution should be in O(n) time and O(1) space having madejust a single pass through the list.Write a programme that, given an array of N double values, a[], discovers the closest pair, or two values whose difference (in absolute value) is not higher than that of any other pair. In the worst scenario, your program's execution time should be linearithmic.
- You are given a list of randomly arranged numbers, for example (11,7,18,5,17,13). The triple (11,7, 5) is called the "inversion triple" because (5<7<11) in terms of value, while the index of 5 in the list is greater than the index of 7, and the index of 7 is greater than 11. Therefore, we can find 2 inversions in such list as follows: (11,7,5), and (18,17,13). Your main task is to find the total number of inversions in any given list. a) Design a brute-force algorithm to return the number of possible inversions, and analyse the complexity of your solution b) Develop a python code to implement your brute-force algorithm. [The marks depend on the correctness of the code, indentation, comments, test-case] c) Design a more efficient algorithm to do the same task with less complexity, and analyse the complexity of your solution. [Important instruction to be followed: Create an arbitrary unsorted list of 8 characters and use it to provide full explanation of how your proposed…Given an array of locations in memory of n dimensions we want to find out what ordering it has in memory. For example, given the following input array [[[ 0 4 8 12] [16 20 24 28] [32 36 40 44]] [[48 52 56 60] [64 68 72 76] [80 84 88 92]]] your function has to return the tuple: [2,1,0] As a suggestion: - Loop through the number of dimensions - For each dimension generate a list of slices equivalent to the above indexing notation - Get the first two elements of each axis - Order the axes by the difference between those two elements Complete the code: def get_storage_order(r): import numpy as np return to check the code manually: r = np.array([[[ 0, 4, 8, 12], [32, 36, 40, 44], [64, 68, 72, 76]], [[16, 20, 24, 28], [48, 52, 56, 60], [80, 84, 88, 92]]]) get_storage_order(r)Given an array of locations in memory of n dimensions we want to find out what ordering it has in memory. For example, given the following input array [[[ 0 4 8 12] [16 20 24 28] [32 36 40 44]] [[48 52 56 60] [64 68 72 76] [80 84 88 92]]] your function has to return the tuple: [2,1,0] As a suggestion: - Loop through the number of dimensions - For each dimension generate a list of slices equivalent to the above indexing notation - Get the first two elements of each axis - Order the axes by the difference between those two elements Complete the code: def get_storage_order(r): import numpy as np return
- Consider sorting n numbers stored in array A by first finding the smallest elementof A and exchanging it with the element in A[1]. Then find the second smallestelement of A, and exchange it with A[2]. Continue in this manner for the first n-1elements of A. Write pseudocode for this algorithm, which is known as selectionsort. What loop invariant does this algorithm maintain? Why does it need to run foronly the first n - 1 elements, rather than for all n elements? Give the best-case andworst-case running times of selection sort in Θ -notation.Problem Alice was given a number line containing every positive integer, x, where 1<=x<=n. She was also given m line segments, each having a left endpoint, l (1<=l<=n), a right endpoint, r (1<=r<=n), and an integer weight, w. Her task is to cover all numbers on the given number line using a subset of the line segments, such that the maximum weight among all the line segments in the chosen subset is minimal. In other words, let S=(l1,r1,w1),(l2,r2,w2),....,(lk,rk,wk), represent a set of k line segments chosen by Alice, max(w1,w2,...,wk) should be minimized. All numbers 1,2,....n should be covered by at least one of k the chosen line segments. It is okay for the chosen line segments to overlap. You program should output the minimized maximum weight in the chosen subset that covers all the numbers on the number line, or -1 if it is not possible to cover the number line. Input format The first line of the input contains an integer, n - denoting the range of numbers…We learned how to merge two ordered lists with the two-finger method, and we generalizedthis to merge k ordered lists, to obtain one sorted list with all the n items. k is a parameter that canbe set as needed, as long as 2 ≤ k ≤ n. However, for some values of k it is faster to simply sort all thenumbers ignoring the initial order. For which (big O) range of k is worth to merge the lists rather thansort?