
According to me, if we delete both third and second line, then the function goes in an infinite loop for every input except for an empty array input.
Execution is shown below:
- use "ms.sml";
[opening ms.sml]
val merge = fn : int list * int list -> int list
val split = fn : 'a list -> 'a list * 'a list
val mergesort = fn : 'a list -> int list
val it = () : unit
- mergesort([]);
val it = [] : int list
- mergesort([1]);
(* infinite loop *)
This is due to fact - everytime when mergesort reaches at single
element level i.e., [a], it calls split function which splits it
into [a] and []. [] is handled correctly by mergesort() but the
same thing written above happens for [a] i.e., single element
level. Hence repititive calls of mergesort() and split() lead to
infinite loop.
Another observation, if we just remove the second line (case [a])
but keep the third line (case [a,b]) intact, then the inifinite
loop thing doesnt occur and gives correct output for power of
2-sized arrays except 1 (size = 2,4,8,..) . Since [a,b] is handled
correctly by third line.
-
Thanks.
Please answer this and leave copyable code and output for this question along with the question...
How would I be able to get a Merge Sort to run in this code? MY CODE: #include <iostream> #include <fstream> #include <stdlib.h> #include <stdio.h> #include <time.h> using namespace std; class mergersorter { private: float array[1000] ; int n = 1000; int i=0; public: void fillArray() { for(i=1;i<=n;i++) { array[i-1]= ( rand() % ( 1000) )+1; } } void arrayout () { ...
can someone help me answer the following #Fsharp multiple choice questions along with explanations for each question please. 7. How does F# interpret the type int * bool -> string list? Select one: a. (int * (bool -> string)) list b. ((int * bool) -> string) list c. int * (bool -> (string list)) d. (int * bool) -> (string list) 8. Let F# function foo be defined as follows: let rec foo = function | (xs, []) -> xs...
Hi All, Can someone please help me correct the selection sort method in my program. the output for the first and last sorted integers are wrong compared with the bubble and merge sort. and for the radix i have no idea. See program below import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class Sort { static ArrayList<Integer> Data1 = new ArrayList<Integer>(); static ArrayList<Integer> Data2 = new ArrayList<Integer>(); static ArrayList<Integer> Data3 = new ArrayList<Integer>(); static ArrayList<Integer> Data4 = new ArrayList<Integer>(); static int...
6) Show the output of the following program. You mus trace the code to show how you reached the answer. (5 points) #include <stdio.h> int x 18; int y = 5; int z ·e; void my first function) void my_second_function); int main() int ys y = x; if (z) my_first functionO else my-second-function(); x++ : if (z) my_first_function(); else my_second_function(); return e; void my_first_function) x+y); is %d\n", printf("The value of x+y in my-first-function() void my_second_function) ( x=100; is %d\n", x);...
Your running times will probably be different than these. Please
do a better job with the snipping tool than I did.
Java program provided:
// Student Name Today's Date
import java.util.Arrays;
import java.util.Random;
public class SortTimer {
// Please expand method main() to meet the lab
requirements.
// You have the following sorting methods
available:
// insertionSort(int[] a);
// selectionSort(int[] a);
// mergeSort(int[] a);
// quickSort(int[] a);
// The array will be in sorted order after the
routines are called!
...
Please give a output Linux/Ubuntu and how to run it (compile) this program ,my assigment is below : : Merge Sort algorithm using 2 processes a.) Define an integer array of 100 integers. Populate this array with random numbers. You can use int rand(void); function. Do not forget to initialize this function. You will sort the numbers in the array using merge-sort algorithm. In merge sort algorithm the half of the array will be sorted by one process and second...
The code is in python. The file does not have to be the data
set from HW2. What I need is a code combing selection sort and
merge sort. The 2-1 is what the problem in refers to as Q1.
d) [10 points] Write a code combining both selection sort and mergesort algorithms (NOT insertion and merge sorts) as described in Q1) to find out the most optimal k minimizing time efficiency of your algorithms using 1 M data set...
Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In this project, we combine the concepts of Recursion and Merge Sorting. Please note that the focus of this project is on Merging and don't forget the following constraint: Programming Steps: 1) Create a class called Art that implements Comparable interface. 2) Read part of the file and use Merge Sort to sort the array of Art and then write them to a file. 3)...
Modify the given code below which uses Simpson's 3/8 method with
6 subintervals to answer the question above.
if a==b
I=0
else
N=3;
h=(b-a)/N;
x=a:h:b;
y=Fun(x);
I=3*h/8*(y(1)+2*sum(y(4:3:(N-2)))+y(N+1));
N=2*N;
check=0;
% Calculating subsequent valus of I
while check==0;
h=(b-a)/N;
x=a:h:b;
y=Fun(x);
% Composite Simpson's 3/8 method, Eq. (9.22)
I_new=3*h/8*(y(1)+2*sum(y(4:3:(N-2)))+y(N+1));
I_new=I_new+3*h/8*3*(sum(y(2:3:(N-1)))+sum(y(3:3:N)));
% Compare solution with that calculated in the previous
iteration
error=abs((I-I_new)/I)*100; % (*)
if error>0.1 % continue iteration
check=0;
N=N*2;
I=I_new;
elseif error<=0.1 % end iteration
check=1;
I=I_new;
end
end
end...
Hello, I want to check if my C++ code is correct and follows the
requeriments described thanks.
Requeriments:
Assignment Sorting
Benchmark each of the sorting methods listed below.
Insertion Sort
Bubble Sort
Selection Sort
Heap Sort.
Quick Sort.
Merge Sort.
Benchmark each of the above sorting methods for data sizes of
10000, 20000, 30000, 40000 and 50000. Display the results in a
table as shown below. The table should have rows and columns.
However, the rows and columns need not...