ICSE Class 10 Computer Applications Question 52 of 59

Arrays — Question 54

Back to all questions
54
Question

Question 48

Given the following array :

13071622133542528664745839510111\underset{0}{\boxed{13}}\underset{1}{\boxed{7}}\underset{2}{\boxed{6}}\underset{3}{\boxed{21}}\underset{4}{\boxed{35}}\underset{5}{\boxed{2}}\underset{6}{\boxed{28}}\underset{7}{\boxed{64}}\underset{8}{\boxed{45}}\underset{9}{\boxed{3}}\underset{10}{\boxed{5}}\underset{11}{\boxed{1}}

Write a program to sort the above array using exchange selection sort. Give the array status after every iteration.

public class KboatSelectionSort
{
    public static void main(String args[]) {
        int X[] = {13, 7, 6, 21, 35, 2, 28, 64, 45, 3, 5, 1};
        int n = X.length;
        
        for (int i = 0; i < n - 1; i++) {
            int idx = i;
            for (int j = i + 1; j < n; j++) {
                if (X[j] < X[idx])
                    idx = j;
            }
            
            int t = X[i];
            X[i] = X[idx];
            X[idx] = t; 
            
            System.out.println("Pass : " + (i + 1));
            for(int k = 0; k < n; k++) {
                System.out.print(X[k] + " ");
            }
            System.out.println();
        }
        
        System.out.println("Sorted Array:");
        for (int i = 0; i < n; i++) {
            System.out.print(X[i] + " ");
        }
    }
}
Output
BlueJ output of KboatSelectionSort.java
Answer

Source: This question is from Arrays, Computer Applications — Class 10, ICSE Board.

Key Concepts Covered

This question tests your understanding of the following concepts from the chapter Arrays: Question, Array, Underset, Boxed, Program, Sort. These are fundamental topics in Computer Applications that students are expected to master as part of the ICSE Class 10 curriculum.

A thorough understanding of these concepts will help you answer similar questions confidently in your ICSE examinations. These topics are frequently tested in both objective and subjective sections of Computer Applications papers. We recommend revising the relevant section of your textbook alongside practising these solved examples to build a strong foundation.

How to Approach This Question

Read the question carefully and identify what is being asked. Break down complex questions into smaller parts. Use the terminology and concepts discussed in this chapter. Structure your answer logically — begin with a definition or key statement, then provide supporting details. Review your answer to ensure it addresses all parts of the question completely.

Key Points to Remember

  • Write programs with proper indentation and comments.
  • Trace through your code with sample inputs to verify correctness.
  • Explain the logic behind each step of your solution.
  • Familiarise yourself with common library functions and methods.

Practice more questions from Arrays — Computer Applications, Class 10 ICSE