How can an algorithm determine if a list is sorted?

  • MHB
  • Thread starter Joystar77
  • Start date
  • Tags
    Algorithm
In summary, the algorithm used in this conversation is Bubble sort, and the array being sorted is (7, 12, 5, 22, 13, 32). The algorithm needs one whole pass without any swap to know when the array is sorted. This means that during the last pass, the array is already sorted, but the algorithm does not know it until it completes one final pass without any swaps. Additionally, an array refers to a set of numbers or objects that follow a specific pattern and can be used in multiplication and division.
  • #1
Joystar77
125
0
The question is as follows: "How does the algorithm know when the list is sorted?"

Is this the correct answer to this question: The array is already sorted, but an algorithm does not know if it is completed. The algorithm need one whole pass without any swap to know it is sorted.
 
Technology news on Phys.org
  • #2
Joystar1977 said:
The question is as follows: "How does the algorithm know when the list is sorted?"
Which algorithm and array do you have in mind?
 
  • #3
I thought of the algorithm as follows:

Bubble Sorting the list of numbers: 7, 12, 5, 22, 13, 32

7, 12, 5, 22, 13, 32
12, 7, 5, 22, 13, 32
12, 5, 7, 22, 13, 32
5, 12, 7, 22, 13, 32
5, 7, 12, 22, 13, 32

In math, an array refers to a set of numbers or objects that will follow a specific pattern. An array is an orderly arrangement, often in rows, columns or a matrix. Arrays are used in multiplication and division as it shows a great visual to show how multiplication can be shown as repeated addition and division can be shown as fair shares.
There are many authentic examples of arrays that help with the understanding of how using arrays can help students to see efficient strategies. Is this true about what an array means? There are no definitions in my textbook or examples given about what an array really is. Please let me know if this is correct.
 
  • #4
I wasn't asking for the definition of an array in general. Since you used "the list" and "the algorithm" in the OP, I was wondering what those specific things are. So, the array is (7, 12, 5, 22, 13, 32) and the algorithm is Bubble sort.

The array is already sorted, but an algorithm does not know if it is completed. The algorithm need one whole pass without any swap to know it is sorted.
I would not say, "The array is already sorted" without specifying which array. You could say, "During the last pass, the array is already sorted, but an algorithm does not know it. The algorithm needs one whole pass without any swap to know the array is sorted". I agree with this statement.
 
  • #5
Thank you Evgeny. Makarov! I am getting used to brand new terms, because I notice in different mathematics courses such as prealgebra, beginning algebra, and intermediate algebra there are other mathematical terms used. Again, thanks for helping me with this and thoroughly explaining the material. I truly and really appreciate it.
Joystar1977
 

Related to How can an algorithm determine if a list is sorted?

1. What is an algorithm?

An algorithm is a step-by-step procedure or set of instructions used to solve a problem or perform a task.

2. How do algorithms work?

Algorithms work by breaking down a complex problem into smaller, simpler steps that can be easily executed by a computer. These steps are repeated until the desired outcome is achieved.

3. What is the importance of algorithms in computer science?

Algorithms are essential in computer science as they allow for efficient and effective problem solving. They are the building blocks of computer programs and are used in a variety of applications, including data analysis, artificial intelligence, and web development.

4. How are algorithms designed and developed?

Algorithms are typically designed and developed by computer scientists and software engineers. They use various techniques, such as problem-solving strategies, mathematical principles, and data structures, to create efficient and effective algorithms.

5. What are some examples of algorithms?

Examples of algorithms include sorting algorithms (such as bubble sort and quicksort), search algorithms (such as binary search and linear search), and optimization algorithms (such as genetic algorithms and simulated annealing).

Similar threads

  • Programming and Computer Science
Replies
6
Views
1K
Replies
9
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
7
Views
995
Replies
3
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
30
Views
4K
  • Programming and Computer Science
Replies
13
Views
2K
Back
Top