Write a pseudo code for sorting the numbers in an array?

Answer Posted / prabhath

SelectionSort(A)
for i <- length[A]-1 downto 0
for j <- 0 to i
if (A[j]>MAX) // for descending, change this to MIN
MAX=A[j]
MAX_ID=j

temp=A[i]
A[i]=A[MAX_ID]
A[MAX_ID]=temp

Slow motion run of Selection Sort (Bold == sorted region):

5 1 3 2 4
4 1 3 2 5
1 3 2 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5 >> done

Is This Answer Correct ?    22 Yes 14 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the ways to Optimize the Performance of a Difference Amplifier?

1915


Why does the present vlsi circuits use mosfets instead of bjts?

854


What are the steps required to solve setup and hold violations in vlsi?

723


Mention what are three regions of operation of mosfet and how are they used?

686


What is the difference between the mealy and moore state machine?

688






How does a Bandgap Voltage reference work?

3371


Differences between IRSIM and SPICE?

5052


Help with VHDL programming. Write a VHDL code for a D-Latch with clear input ?? (Hint: Set up a “Process” with appropriate sensitivity list to get the desired D-Latch with Clr working.) Inputs AND OUTPUTS: entity Lab4b is Port ( Clr, Clk, D : in STD_LOGIC; Q : out STD_LOGIC); end Lab4b;

1161


How can you construct both PMOS and NMOS on a single substrate?

4594


What is the critical path in a SRAM?

2734


Explain how Verilog is different to normal programming language?

781


Explain Cross section of an NMOS transistor?

657


What types of CMOS memories have you designed? What were their size? Speed?

2739


What are the changes that are provided to meet design power targets?

747


What are the different ways in which antenna violation can be prevented?

765