Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

note the following error in the algorithm in HW#:Q . 1 . Consider the following pseudocode for the selection sort algorithm and answer the questions

note the following error in the algorithm in HW#:Q.1. Consider the following pseudocode for the selection sort algorithm and answer the questions below.
Algorithm 1: Selection Sort.
Input Variables:
n : size of array of integers
A: array of n integers
Temporary Variables:
minj: index of current minimum number
temp: value of current minimum number
i,j : Loop/array indexing variables.
for ilarr0 to n-1 do
minjlarri
for jlarri+1 to n do
if minjlarrjminjilarrA[minj]A[minj]larrA[i]A[i]larrA[j] then
minjlarrj
if minji then
temp larrA[minj]
A[minj]larrA[i]
A[i]larr temp
a) Write an ARM assembly code for the selection sort (Algorithm 1). Assume A and n are both variables stored in memory. Assume the array A is defined as volatile.
b) Simulate the program you have written using VisUAL ARM emulator with an input array {15,60,2,7,39,77,5}. Include a snapshot to show that your program produced the correct output. Make sure to include both registers and memory view in your snapshots. Use the "View Memory Content" to show the sorted array.
c) Consider a modified version of the algorithm called Algorithm 2. In this version, the search for the index of the minimum number is performed by a function call. Repeat Part a) using Algorithm 2. You may need to add instructions before and after the function call to do what is necessary to perform the function call. Use the stack to preserve and restore all needed registers before and after the function call.
Algorithm 2: Selection Sort.
Input Variables:
n : size of array of integers
A : array of n integers
Temporary Variables:
minj: index of current minimum number
temp: value of current minimum number
i,j : Loop/array indexing variables.
for ilarr0 to n-1 do
minj=findMIN(i,n,A)
if minji then
temp larrA[minj]
A[minj]larrA[i]
A[i]larr temp
int fundMIN(int i, int n, int*A):
minjlarri
for jlarri+1 to n do
if minjlarrjA[j] then
minjlarrj
return minj
d
Incorrect:5:
if A[j] A[i] then
Correct:5:
if A[j] A[minj] then
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

2. Describe the use of social networks in business communication.

Answered: 1 week ago

Question

Nonprofit firms can legally raise funds by issuing stock.

Answered: 1 week ago