Code:-
![RepeatedArr = 12,2,2,1,1,1,1,1,1,1,1,2,2,1,2,1,2,1,1,2,1,1,1,1,1] #array with two distinct elements SizeofArray = len(Repeate](http://img.homeworklib.com/questions/aaa46f90-a073-11ea-b629-b7ced30d8316.png?x-oss-process=image/resize,w_560)
Output:-

code
# Python3 program to print
# sorted distinct elements.
RepeatedArr =
[2,2,2,1,1,1,1,1,1,1,1,2,2,1,2,1,2,1,1,2,1,1,1,1,1] #array with two
distinct elements
SizeOfArray = len(RepeatedArr) #calculating the size
setOfArray = set() #adding to set
for i in range(SizeOfArray): #for loop
if RepeatedArr[i] not in setOfArray: #adding to set
setOfArray.add(RepeatedArr[i])
for i in setOfArray: #printing the array
print(i,end=" ")
Give a code fragment that sorts an array that is known to consist of items having...
2. In class, we discussed the recursive Merge-Sort algorithm. This sorts the whole array by sorting the left side, sorting the right side, and then merging them. Write a similar recursive algorithm that finds the maximum element of an array. (Find the max of the left side, then find the maximum of the right side, then compare the two.) Write pseudo-code for this algorithm. Give the recurrence relation that describes the number of comparisons that your algorithm uses.
7. The code segment given sorts an array. Show how this works on the given array by redrawing the array each time one of the entries changes value. const int Isize·6; // list size int list [lsize]; int j, x; for (int i = !size-1; i > 0; i-) { x = list [i]; ji; for (int k = i-1 ; k >= 0; k-) { if (list [k] > x) f j -k; x = list(k); list [j] list...
Need help with my Java Hw: Consider an algorithm that sorts an array of n elements by finding the smallest and largest elements and then exchanges those elements with the elements in the first and last positions in the array. Then the size of the array is reduced by two elements after excluding the two elements that are already in the proper positions, and the process is repeated on the remaining part of the array until the entire array is...
6. Give an efficient algorithm to rearrange an array of n keys so that all negative keys precede all nonne- gative keys. Your algorithm must be in-place meaning you cannot allocate another array to temporarily hold the items.
I'm trying to code a C program so it sorts an array of integer numbers of size n in ascending order. My code is written below but its not working properly, its giving me errors, I think my sort and swap functions aren't done right maybe, please help and fix. It says "undefined reference to "SelectionSort" as an error. But the question asks to not change the PrintArray and Main function. #include <stdio.h> void PrintArray(int size, int array[]) { for...
Do problem 4-20: Give an efficient algorithm to rearrange an array of n keys so that all the negative keys precede all the nonnegative keys. Your algorithm must be in-place, meaning you cannot allocate another array to temporarily hold the items. How fast is your algorithm?
Give a code fragment that removes the last node in a linked list whose first node is first. for java
Assume L is an array, length (L) returns the number of records in the array, and qsort \((L, \quad i, j)\) sorts the records of \(L\) from \(i\) to \(j\) (leaving the records sorted in L) using the Quicksort algorithm. What is the average-case complexity for the following code fragment?$$ \begin{array}{c} \text { for }(\mathrm{i}=0 ; \text { i<length }(\mathrm{L}) ; \mathrm{i}++) \\ \text { qsort }(\mathrm{L}, 0, \mathrm{i}) ; \end{array} $$You should provide a formula for computing the total...
Question 2 (10 pts): Code evaluation, 2 pts each For each C code fragment, give the final value of the indicated variable after the code fragment is run. If the final value cannot be determine, then give N/A. a. Final value of cb is (in hex) b. Final value ofwcei RAAS ww wAAAAA= 0x55; (in hex) //As sume w AAAAA ¡s located at OxFFFF FC00 c. Final value of?AAAA is sex oy RAAK _ 0x55; (in hex) Assume w AAA,...
(12 pts) The following code fragment processes an array and produces two important values in registers $v0 and $v1. Assume that the array consists of 5000 words indexed 0 through 4999, and its base address is stored in $a0 and its size (5000) in $a1. Describe what this code does. Specifically, what will be returned in $v0 and $v1? add $al, şal, $al add $al, şal, $al add $v0, şzero, $zero add $to, şzero, $zero add $t4, $a0, $to lw...