Develop an algorithm in pseudocode to find the median value in a list containing N unique numbers. The median of N numbers is defined as the value in the list in which approximately half the values are larger than it and half the values are smaller than it. For example, consider the following list of seven numbers. 26, 50, 83, 44, 91, 20, 55 The median value is 50 because three values (20, 26, and 44) are smaller and three values (55, 83, and 91) are larger. If N is an even value, then the number of values larger than the median will be one greater than the number of values smaller than the median.
Algorithm for find the median value of list containing N unique numbers.
Step 1: START
Step 2: declare and define the value of N (Size of the list)
Step 3: declare List of size N
Step 4: Assign N values in the List.
Step 5: Sort the List
Step 6: If N is Odd, Goto Step 7
Else Goto Step 8
Step 7: Assign (N+1/2)th element of a list as Median.
Step 8: Assign (N/2)th element of a list as Median.
Step 9: Print Median
Step 10: STOP.
#Python Code to demonstrate the median finding in the list:-
def main():
list1=[26,50,83,44,91,20,55]
list1.sort()
n=len(list1)
if n%2==0:
t=int((n-1)/2)
median=list1[t]
else:
t=int(n/2)
median=list1[t]
print("Median : ",median)
if __name__=="__main__":
main()
![main.py 1. def main(): 2 list1=[26,50,83,44,91,20,55] 3 listi.sort() 4 n=len(list) 5 if n%2==0: 6 trint((n-1)/2) 7 median=lis](http://img.homeworklib.com/questions/177a2bc0-0435-11eb-8e6e-edff0670e297.png?x-oss-process=image/resize,w_560)
Note:- In algorithm and program, there is a difference in indexing . In algorithm indexing starts with 1 but in program indexing starts with 0.
Develop an algorithm in pseudocode to find the median value in a list containing N unique...
need help in this algorithm question
Let A be an array containing n numbers (positive and negative). Develop a divide and conquer algorithm that finds the two indices 1 sisjsn such that A[k] (the sum of the elements from i to j) is maximized. For example, in the array A [10,-5,-6,5, 7,-2,4, -11], the sub-array A[4:6] has the sum 5+ 7-2+4-14 and no other sub-array contains elements that sum to a value greater than 14, so for this input the...
You will develop a program that will read a list of integers into an array. Data entry will end when a negative number is entered. When data entry is completed, the program will ask for a nominal value. When this number is entered, two lists will be displayed-one containing the numbers equal to or above the nominal value and a second one with the values below the nominal. A typical output is shown below: This program inputs a list of...
Example 1.9:
1.23 "The median of an ordered set is an element such that the number of elements less than the median is within one of the number that are greater, assuming no ties. a. Write an algorithm to find the median of three distinct integers a, b, and c. b. Describe D. the set of inputs for your algorithm. in light of the discussion in Sec- tion 1.4.3 following Example 1.9. c. How many comparisons does your algorithm do...
Add a method called median() to the ArrayIns class in the insertSort.java program (Listing 3.3). This method should return the median value in the array. (Recall that in a group of numbers half are larger than the median and half are smaller.) Do it the easy way. LISTING 3.3 The insertSort.java Program // insertSort.java // demonstrates insertion sort // to run this program: C>java InsertSortApp //-------------------------------------------------------------- class ArrayIns { private long[] a; // ref to array a private int nElems;...
Directions: Problem 1: Write (using pen-and-paper rather than code) the list after each pass of quick and merge sort for the following list of numbers. Assume that you are sorting the numbers into ascending order. For quick sort, assume that the first number from the sublist is chosen as the pivot. 54 17 21 18 4 7 19 41 Problem 2: Write the list after each pass of the quick sort algorithm for the following list of numbers, using the...
Define a function called get_n_largest(numbers, n) which takes a
list of integers and a value n as parameters and returns a
NEW list which contains the n
largest values in the parameter list. The values in the
returned list should be in increasing order. The
returned list must always be of length n. If the number of values
in the original list is less than n, the value
None should be repeated at the end of the returned list to...
IN PYTHON Develop the program that will allow you to obtain an ordered list of whole numbers from least to greatest from two lists of whole numbers. The individual values of the input lists are captured by the user one by one and then both lists will be joined and then sorted in ascending order (from lowest to highest value). Your program should allow the capture of the entire values of the lists without making use of messages (legends) to...
Question 4 CLO3 The following Python script implements an algorithm to find and prints the max value in a list of values. MAX 0 def MaxVal (Ist): for i in Ist: if( MAX < i): MAX = i return (MAX) Marks (20,24,26,19,5,31,24,32,32,45 print (MaxVal (Marks) a. Express the number of operations in terms of a function f(n), where n is the input size. (1 Mark) b. What is the total number of operations in the for loop of the algorithm...
3. Modify the insertion sort algorithm discussed in class so
that it can sort strings. That is, its input will be an array, the
type of which is string. The insertion sort algorithm will sort the
elements in this array. Finally, its output will be a sorted
array.
As the solution of this problem, you need to submit the
following answer(s): (1). The implementation of your algorithm in
C# (20points).
Algorithm: At each array-position, it checks the value there against...
Hello! I'm looking for help with this assignment. Complete a program in pseudocode and Python that performs the following tasks. Open the file called M4Lab1ii.py linked below these instructions in your M4 Content module in IDLE. Save as M4Lab1ii.py. Replace ii with your initials. [example for someone with the initials cc: M4Lab1cc.py] Complete Steps 1-7 as requested within the code’s comments. Run your program and test all four calculations, then exit the program. Save your program as M4Lab1ii.py using your...