Ask your own question, for FREE!
Mathematics 14 Online
OpenStudy (anonymous):

sorting insertion

OpenStudy (anonymous):

Insertion Sort (01) insertionsort:=proc(B,n) (02) local i,j,A,minIndex,temp; (03) A:=B; (04) for i from 1 to (n-1) do (05) minIndex:=i; (06) for j from (i+1) to (n-1) do (07) if (A[j]<A[minIndex]) then (08) minIndex:=j; (09) end if; (10) end do; (11) if (minIndex!=i) then (12) temp:=A[i]; (13) A[i]:=A[minIndex]; (14) A[minIndex]:=temp; (15) end if; (16) end do; (17) print(A); (18) end proc:

OpenStudy (anonymous):

" A:=B " that make their size equal?

OpenStudy (anonymous):

Then check out my code: sortins:=proc(x) local n,y,k,s,id,j,temp; n:=LinearAlgebra:-Dimension(x); y:=x[1..n]; for k from 1 to n do s:=y[k]; id:=k; for j from k+1 to n do if y[j]<s then s:=y[j]; id:=j; end if; end do; temp:=y[k]; y[k]:=s; y[id]:=temp; end do; return y; end proc;

OpenStudy (anonymous):

what A=B is suppose to mean, is that we are replacing A with B

OpenStudy (anonymous):

"passing the input data to a working vector" in my case

OpenStudy (anonymous):

k. what's n?

OpenStudy (anonymous):

In their program, i have no idea what n is, i guess its the number of elements they have, but in my case i decided that i dont neet that beacuse i have an index work with due to the vectors

OpenStudy (anonymous):

Here is the original problem: 22. Sorting by insertion (Computer Science ) For an input vector x = [x1, . . . , xn], it can be sorted into ascending order by the following insertion method: First of all, pass the input data to a working vector y = [y1, . . . , yn]. Consider initially y1 is sorted. Generally, assume y1, . . . , yk are sorted into ascending order, then yk+1 will be compared with y1, y2, . . ., yk one by one and inserted into the proper place so that the new entries y1, . . . , yk+1 are in ascending order. This process is continued for k = 1, 2, . . . , n−1 and end up with a sorted vector y. Write a program to implement this sorting method.

OpenStudy (anonymous):

so basically, i dont know if what i have would be considered a sorting insertion program

OpenStudy (anonymous):

reading... sec

OpenStudy (anonymous):

does it actually work?

OpenStudy (anonymous):

yeah, its does

OpenStudy (anonymous):

Maple is crazy.

OpenStudy (anonymous):

i put in a:=Vector[row]([6,5,4,3,2,1]) and then x:=sort(my program name)(a); and i got back x:=[1,2,3,4,5,6]

OpenStudy (anonymous):

Looks to me like it qualifies as sorting by insertion

OpenStudy (anonymous):

but i feel like, i am not implementing the "insertion sort" method you know

OpenStudy (anonymous):

I wish I had appreciated it more. I learned it in math class before I ever took any comp-sci. It seems like it's smarter than most languages

OpenStudy (anonymous):

yeah, well, I might need your help with this other problem, but that will have to wait till tommorw cause i am tired.Catch you later. Hey but if you think about anyhting with regard to the sorting insertion method let me know

OpenStudy (anonymous):

sure. nite:)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!