public class Soru2 { static void sort(char a[]) { for(int i = 0; i < a.length; i++) { for(int j = i + 1; j < a.length; j++) { if(a[j] == 'X' && a[i] == 'O') { char temp = a[j]; a[j]=a[i]; a[i]=temp; } } } for(int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } } public static void main(String[] args) { char a[] = {'X','O','X','O','X','O','X','O','X','O'}; sort(a); } } Calculate the time complexity and number of steps of the algorithm?
public class Soru2 { static void sort(char a[]) { for(int i = 0; i < a.length; i++) { for(int j = i + 1; j < a.length; j++) { if(a[j] == 'X' && a[i] == 'O') { char temp = a[j]; a[j]=a[i]; a[i]=temp; } } } for(int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } } public static void main(String[] args) { char a[] = {'X','O','X','O','X','O','X','O','X','O'}; sort(a); } } Calculate the time complexity and number of steps of the algorithm?
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
public class Soru2 {
static void sort(char a[]) {
for(int i = 0; i < a.length; i++) {
for(int j = i + 1; j < a.length; j++) {
if(a[j] == 'X' && a[i] == 'O') {
char temp = a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
for(int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
public static void main(String[] args) {
char a[] = {'X','O','X','O','X','O','X','O','X','O'};
sort(a);
}
}
Calculate the time complexity and number of steps of the
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps