MHB How can an algorithm determine if a list is sorted?

  • Thread starter Thread starter Joystar77
  • Start date Start date
  • Tags Tags
    Algorithm
AI Thread Summary
The discussion centers on how sorting algorithms, specifically Bubble Sort, determine when a list is sorted. It is clarified that an algorithm cannot conclude that a list is sorted until it completes a full pass through the array without any swaps. The example used is the array (7, 12, 5, 22, 13, 32), which illustrates the sorting process. Additionally, there is a brief exploration of the concept of an array, emphasizing its role in mathematics as an orderly arrangement of numbers or objects. The conversation highlights the importance of precise terminology in discussing algorithms and arrays, with participants expressing appreciation for the clarification of these concepts.
Joystar77
Messages
122
Reaction score
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
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?
 
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.
 
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.
 
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
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top