Interesting new sort algorithm... - Page 1
Forum section: electronics / general

author: westfw
author_rank: Super Contributor
timestamp: July 22, 2022, 06:26:02 am
content: There's an interesting new sort algorithm:Algorithm (1) ICan’tBelieveItCanSort(A[1..n])Code://sorts an array A of n elements in non-decreasing order.for i = 1 to n dofor j = 1 to n doif A < A thenswap A and Ahttps://arxiv.org/pdf/2110.01111.pdfFTA:Quote

author: ataradov
author_rank: Super Contributor
timestamp: July 22, 2022, 06:39:47 am
content: How is this new? Is not this a thing that you would naturally implement if you are just starting programming and don't know anything about sorting?This is just compare every element with every other element. This can be quickly optimized to bubble sort pretty much by anyone interested in spending some time. The rest of the sorting algorithms are much less obvious.

author: magic
author_rank: Super Contributor
timestamp: July 22, 2022, 07:32:48 am
content: Hardly new.Code:for i = 1 to n dofor j = 1 to i doif A < A thenswap A and AThis is a simple implementation of Insertion Sort. Find one difference.Their version simply performs some additional pointless work. Their big discovery is that the extra work is actually harmless.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 22, 2022, 07:22:33 pm
content: Fascinating use of public money.

author: gamalot
author_rank: Super Contributor
timestamp: July 22, 2022, 09:39:41 pm
content: Isn't this the famous bubble sort method?

author: magic
author_rank: Super Contributor
timestamp: July 22, 2022, 09:48:24 pm
content: Quote from: SiliconWizard on July 22, 2022, 07:22:33 pmI have read a scientific paper which basically demonstrated that splitting a certain obviously parallelizable task onto two processors brings the expected 200% speedup. Apparently multiprocessing is a big theme in this decadeNow, that has me wondering what's the fastest time a for-all-practical-purposes-infinitely-core machine could sort an array of N elements, hmm...

author: golden_labels
author_rank: Super Contributor
timestamp: July 23, 2022, 12:10:56 am
content: arXiv is a publication service with no peer review. It is moderated, but with the focus on content relevance and meeting some minimal quality. The person given as the authordoes not listthis work among his publications.(1)Which makes me think that may be a joke, an attempt to discredit the author or arXiv.—2022-07-25 update: the publication is authentic.However, if that’s neither of the above, that’s not as absurd as it may seem. It’s not describing bubble sort. The paper explores an algorithm, that at a first glance should not work, and explains its operation.(1)Stanley Fung’s DBLP entrycontains this position, but that is merely an automatic indexer.

author: KaneTW
author_rank: Frequent Contributor
timestamp: July 23, 2022, 12:32:58 am
content: Why shouldn't it work on first glance? The invariants are really obvious.

author: xrunner
author_rank: Super Contributor
timestamp: July 23, 2022, 12:38:37 am
content: Well if you've never seen it before it's new ... to you.

author: ledtester
author_rank: Super Contributor
timestamp: July 23, 2022, 03:34:50 am
content: Quote from: ataradov on July 22, 2022, 06:39:47 amQuote from: magic on July 22, 2022, 07:32:48 amQuote from: KaneTW on July 23, 2022, 12:32:58 amConsider if A is already non-decreasing, i.e. A < A < ... < A.The first thing the algorithm does is swap A with A. Yet in the end it fixes this mistake.You can play with it here (tutorialspoint.com's online python environment):http://tpcg.io/_VG4MZM

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 23, 2022, 04:34:28 am
content: Ledtester hit the nail on the head.Quote from: ataradov on July 22, 2022, 06:39:47 amNo, because the condition of when to swap isreversedto what one would expect from the description and results.I, too, missed that on the first read.

author: TheCalligrapher
author_rank: Regular Contributor
timestamp: July 23, 2022, 05:25:52 am
content: It is indeed an interesting algorithm.At the first sight it appears that all it does is find the largest element of the entire array and put into i-th postion after each iteration of the outer cycle.However, the non-obvious part is that it leaves a sorted array in its wake (to the left of the current i-th position).The article is essentially dedicated to proving the latter.

author: brucehoult
author_rank: Super Contributor
timestamp: July 23, 2022, 05:34:28 am
content: Quote from: gamalot on July 22, 2022, 09:39:41 pmNo.

author: brucehoult
author_rank: Super Contributor
timestamp: July 23, 2022, 05:48:44 am
content: Quote from: TheCalligrapher on July 23, 2022, 05:25:52 amI saw it the other way around.In each inner loop, while j < i it inserts element i in the correct place in the already-sorted part of the array. This is standard insertion sort. While j > i it puts the largest remaining at position i -- essentially a selection sort in reverse order.After each outer loop the invariant is:< i: sorted= i: largest unsorted element> i: almost original order, but largest elements permuted, stays untouched if original data is in descending order.

author: brucehoult
author_rank: Super Contributor
timestamp: July 23, 2022, 05:57:35 am
content: Quote from: ledtester on July 23, 2022, 03:34:50 amIt's more illuminating if you print the array after each outer loop:Code:import randomdef ICantBelieveItCanSort(a):n = len(a)for i in range(n):print(a)for j in range(n):if a < a:a, a = a, aa = list(range(100,120))random.shuffle(a)ICantBelieveItCanSort(a)print(a)

author: Mechatrommer
author_rank: Super Contributor
timestamp: July 23, 2022, 06:02:12 am
content: Quote from: gamalot on July 22, 2022, 09:39:41 pmno, it is a joke... but if you have no other option, at least you can change...Code:for i = 1 to n dofor j = 1 to n dotoCode:for i = 1 to n dofor j = i to n do

author: brucehoult
author_rank: Super Contributor
timestamp: July 23, 2022, 06:50:10 am
content: Quote from: Mechatrommer on July 23, 2022, 06:02:12 amThat will sort in the opposite order."for j = 1 to i" will sort in the same order.

author: AndyBeez
author_rank: Frequent Contributor
timestamp: July 23, 2022, 09:11:34 am
content: In olden days when Cobol and Fortran were coding monarchy, learning the pros and cons of each sort algorithm was computer science 101. Today, few programmers understand why or even how a sort works, because that's in the voodoo the compiler does.But... if you're interested, and have a few hours study time, the sorting algorithms are described here:https://www.geeksforgeeks.org/sorting-algorithms/My favourite is the "Gnome Sort"

author: Mechatrommer
author_rank: Super Contributor
timestamp: July 23, 2022, 09:25:22 am
content: Quote from: brucehoult on July 23, 2022, 06:50:10 amfrom quick look, op is an inefficient sort in decreasing order, so by the end of first run i=1, the biggest number is already in A (1), so no need to check index 1 in 2nd run. Same thing happened when sort in increasing order by switching the comparison sign check. But no, the op is indeed a joke because it will move back the biggest number to the end, after it went to the first during 1st run.. a waste of pure O(n^2) complexity instead of a somewhat better O(n(n+1)/2).

author: gamalot
author_rank: Super Contributor
timestamp: July 23, 2022, 09:30:42 am
content: Quote from: Mechatrommer on July 23, 2022, 06:02:12 amMy bad, I should have looked more closely.

author: magic
author_rank: Super Contributor
timestamp: July 23, 2022, 09:32:08 am
content: Quote from: golden_labels on July 23, 2022, 12:10:56 amQuote from: TheCalligrapher on July 23, 2022, 05:25:52 amFirst of all, to all the Bubble Sort fanboys, yours is not the only trivial O(n²) sorting algorithm known to man. Learn the others, and you may even recognize them when you see them.The idiocy "invented" by that guy is an inefficient implementation of Insertion Sort, andInsertion Sort is actually the best sorting algorithm in the world(except when doing large arrays with efficiency) and it should be the go-to choice for everyone's trivial sorting needs and taught at every beginner programming course instead of the BS nonsense.This is your usual (ascending) insertion sort. You take each element, and shift it towards the beginning until it fits. Everything to the left of i is now sorted and when i reaches the end, you're done. Two for loops, four lines of code. Fast on already-sorted arrays and cache-friendly.Code:for i = 2 to n dofor j = i down to 2 doif A < A[j-1] thenswap A and A[j-1]A speed-optimized implementation will addCode:elsebreak out of the inner loop and take next ibecause all further comparisons are pointless.A slightly less efficient implementation below. Here, we scan from the left, find the right place for A(i) and then shift all displaced elements to the right, using the now-emptied i array slot as temporary storage. Note that after the first swap, the if condition will always be true and there is no opportunity for eliminating some iterations of the inner loop.Code:for i = 2 to n dofor j = 1 to i-1 doif A < A thenswap A and AAnd here's what the guy "invented".Code:for i = 1 to 1 do// do useless work before the sorting even beganfor i = 2 to n dofor j = 1 to i-1 doif A < A thenswap A and Afor j = i to n do// do useless work on not-yet-sorted part of the arrayAnd finally, 100% equivalent to the above, but obfuscated implementation, which is clearly above the head of your average computer scientist and software developerCode:for i = 1 to n dofor j = 1 to n doif A < A thenswap A and A

author: Picuino
author_rank: Super Contributor
timestamp: July 23, 2022, 05:49:41 pm
content: I have post in another thread a program to compare different sorting algorithms:https://www.eevblog.com/forum/programming/comparison-of-sorting-algorithms/msg4317196/#msg4317196I'm going to add this 'new' algorithm to comparison.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 23, 2022, 06:34:42 pm
content: When comparing it with bubble or insertion sort, you need to consider the order of the loop indices, which will give you a hint.The article explains why it is not obvious at first sight, so for those wondering, just read it.While in the end, this "algorithm" is completely useless per se, for people studying (or brushing up on) how to prove algorithm correctness, this can be a nice simple exercise, so that's where I would put the value of this article.Being able to prove/disprove algorithm correctness is a very valuable skill.

author: AndyBeez
author_rank: Frequent Contributor
timestamp: July 24, 2022, 09:28:50 am
content: An issue with a sorting algo is just how random or discrete the input data is. Sorting 'assumes' the probability that a range of values are randomly distributed. Thus the chance of a range reading BDACE is the same as EDCBA and even ABCDE. The standard deviation is 0.5 (There is no 'entropy' to the randomness).But real world, data is 'clumpy'. Consider a sort algo for US states. We have clustering around states starting A M and N, and no states starting E J and Y. Thus, an efficient high speed algo would/could/should consider the data's underlying distribution(entropy); by weighting the existence or absence of value ranges. This is far beyond my school maths

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 24, 2022, 10:11:03 am
content: Quote from: AndyBeez on July 24, 2022, 09:28:50 amIt's not nearly as difficult to quantify as one would believe;algorithm analysisisn'thardper se, it's one of those things where the hurdle is to understand the concepts first, and then the mathy part is almost always very easy.A first approximation is to examine thebest case cost,amortized average cost, and theworst-case cost, and estimate how often do each of them occur.You can trivially instrument your sort function to count the number of comparisons and swaps (or whatever primitives it uses), and then examine how they vary for different inputs.One interesting and practically useful way to examine the statistical distribution of the complexity of a sort operation –– that is, how it behaves for different sortednesses of input –– is to start with perfectly ordered data (one case is preferred order, and the other is inverse order), and then increasinglyshuffleit (using a known good pseudorandom shuffle; this is very important), while counting the number of operations when sorting the shuffled data. You do this a few times in parallel, and you get an excellent statistical picture of how the sort behaves overall.(Note that if you haveNelements in the array, you only need a comparable amount, say 7N, of shuffle operations (insertions or swaps) to "completely randomize it". So this is also a very practical way of characterising a sort operation in terms of its primitives.)In general, for a good sort function with bad worst case behaviour (like say Quicksort), you want the number of operations descend very quickly from the worst case towards the minimum, with minimum obtained for most inputs, as the amount of shuffle/"randomness" in the original data increases.As to benchmarking actual sorting code, the key is to always use real-world data. Current computers are so complex wrt. timing that microbenchmarks just don't cut it.When you have large enough arrays, the cache access pattern of the data becomes a bottleneck, unless your data structures are not amenable to sorting anyway. (When sorting say floating-point numbers, itcanbe done in linear time, since there is a fixed number of possible keys, using a radix sort. Because of its cache behaviour, it just is slower than asymptotically worse sort algorithms (those with O(N log N) time complexity in particular) until N becomes unreasonably large, something on the order of 10⁹ or larger. And even then, it usually turns out that you can do the sorting "for free" while doing other stuff to the data, due to I/O being bottleneck (so the "cost" of doing the sort then is just a bit more CPU work, but wall clock time taken is not affected.)Then again, if you are doing sorting on the background, and you don't care how long it takes as you want to minimize the total CPU and I/O load needed to complete the sort, you need a completely different algorithm and approach compared to when there is a human waiting for the sort to complete (in which case you want to minimize thelatencycaused by sorting; i.e. wall clock time taken, before the human can continue doing whatever it is they are doing).Which means that there is no "best" sorting algorithm at all, because the criteria for "goodness" depends on the use case.To find out, all you need is time and effort. However, today's world seems to be hell bent on just getting it done as fast as possible, so throwing a library or sort algorithm that everybody else is using on such a problem is much more commercially viable approach. Nobody appreciates much efforts trying to compare different sort algorithms, because they've already made up their mind as to which one is superior.

author: brucehoult
author_rank: Super Contributor
timestamp: July 24, 2022, 10:13:03 am
content: Quote from: SiliconWizard on July 23, 2022, 06:34:42 pmI don't distinguish between "proving correct" and "getting how it works".

author: KaneTW
author_rank: Frequent Contributor
timestamp: July 24, 2022, 10:00:26 pm
content: Quote from: brucehoult on July 24, 2022, 10:13:03 amYou do a formal proof on every algorithm that you learn?

author: golden_labels
author_rank: Super Contributor
timestamp: July 24, 2022, 10:40:13 pm
content: First and foremost: I just confirmed that the publication is authentic, written by that author. And that it indeed is often misinterpreted the way it did happen in this thread.magic:Some other people above have realized their mistake, did read the article carefully and understood its key idea. Perhaps it would be wise to rethink the position if such a strong warning signal is present?brucehoult:Understanding an algorithm means you grasp the idea behind its operation. That doesn’t automatically mean it actually achieves the goal. For that a proof is needed. Otherwise everything would be always valid, because anyone proposing an algorithm understands it: obviously that is not true.

author: brucehoult
author_rank: Super Contributor
timestamp: July 25, 2022, 12:06:39 am
content: Quote from: KaneTW on July 24, 2022, 10:00:26 pmI don't write it down, but "getting how it works" means figuring out what the invariants and induction schemes for any loops or recursions are, which means I *could* write down a proof, yes.

author: brucehoult
author_rank: Super Contributor
timestamp: July 25, 2022, 12:13:19 am
content: Quote from: golden_labels on July 24, 2022, 10:40:13 pmIf you propose an algorithm but it doesn't work then you don't understand it at all!Do they not teach preconditions, postconditions, invariants, and weakest preconditions these days?You don't need to type up a formal proof in LaTeX, you only have to figure out the invariants and how they are maintained. If you haven't done that then you DON'T "grasp the idea behind its operation", you only have a wet finger in the air.

author: golden_labels
author_rank: Super Contributor
timestamp: July 25, 2022, 01:30:22 am
content: Perhaps the difference in interpreting word “understand”?I’m not a native English speaker and, at least according to their flags, the same is true for KaneTW. That may affect to what concepts the word maps. However, multiple things contradict that explanation and support our perception of “understand”:English doesn’t treat it as a binary property, but as one with multiple levels: “deeper understanding”, “shallow understanding” &c. SeeGoogle Ngram Viewer for examples. Your interpretation makes it binary.The English Wikipedia article onunderstandingcontains a fragment, written bya native English speaker Greenrd:“A teenager may understand that multiplication is repeated addition, but not understand the broader implications of this.”That wouldn’t be possible in your interpretation. The tone of the entire article is also giving the same impression.I can’t easily recall, from my own experience, a piece in English that would use “understand” in your interpretation. At the same time any use I find(1)is either one I can’t classify or matching our version. That includes those in the top search results for “.edu”, like“the analysis of an algorithm can help us understand it better”(taken from a course materials at Princeton) or“if a grader cannot understand your solution, they cannot give you any credit for it.”(fromMIT 6.006 syllabus).I have trouble accepting your interpretation from philosophical point of view. It has completeness of knowledge as a prerequisite for understanding.From my perspective “understand” used in this context is limited to having a valid model. It does not extend to drawing conclusions from that model, but that’s what making a formal proof is.I believe we may need a clarification, what each of us meant.(1)And is relevant here. “Understand his feelings” is clearly a different meaning.

author: magic
author_rank: Super Contributor
timestamp: July 25, 2022, 05:44:45 am
content: Quote from: brucehoult on July 25, 2022, 12:13:19 amYes, at those places that used to teach it 50 years ago.For each reputable university, you now have ten "higher schools of web development, data science and cooking on a gas stove".And for each of the above, you have ten YouTube channels and Medium tutorials of the "small current controls large current" variety.This puts things into perspective

author: magic
author_rank: Super Contributor
timestamp: July 25, 2022, 05:47:43 am
content: Quote from: golden_labels on July 24, 2022, 10:40:13 pmI genuinely don't understand what you are even trying to imply here.If you think I have made a mistake, what it is supposed to be?I continue to maintain that the algorithm is trivial, and a trivial variant of a well-known one at that. I outlined how it works, Bruce posted a useful invariant if you wanted to write a formal proof. If you think we are wrong, go ahead and post a rebuttal instead of stating the obvious that "the author is getting that sort of response" all the time, as if it meant anything.Now, there may be people who don't see it, but for those people that sort of algorithms and proofs belong in introductory programming books. I would be mildly uncomfortable writing such an article and utterly embarrassed to put my IRL name under it.Also, different people have differentstandardsof what it means to understand something, particularly when it comes to maths and related fields. You don't need to write a tl;dr wall of text and speculate about imaginary language barriers, just read and accept what the guy told you.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 25, 2022, 08:34:17 pm
content: Quote from: magic on July 25, 2022, 05:44:45 amIt does. In some universities, you can add "how not to write offensive code" courses too. Then there are only so many hours in a week, so it gets difficult to find time for teaching those old CS concepts.

author: magic
author_rank: Super Contributor
timestamp: July 25, 2022, 09:00:54 pm
content: I didn't have that option. But we had to take 1h/week or thereabouts of a chosen non-technical course (many options from all over the university) and I recall gender theory being one of the options, kinda regret not trying to get in there, it could have been amusing and unlikely to be hard to pass

author: brucehoult
author_rank: Super Contributor
timestamp: July 25, 2022, 11:59:34 pm
content: Quote from: magic on July 25, 2022, 09:00:54 pmI did a paper in the Humanities department, a 1st year Philosophy course "Basic Logic". A lot of it duplicated things also covered in computer science, such as AND/OR/XOR, De Mogan's theorem. They used F and T instead of 0 and 1 and wrote their truth tables backwards, from T T T to F F F. They did add some names for others of the 16 truth tables e.g. "implication" for "!A | B" and forms of argument such as Modus Ponens and Modus Tollens, so it wasn't a total waste of time. Also, there were a lot of hotties.

author: Mechatrommer
author_rank: Super Contributor
timestamp: July 26, 2022, 04:09:45 am
content: i can only look from far without having a clue what they are up to, comp sc had more female than we do, i think even now. i mean how many of them interested in mechanic of materials and messing their hand with fiber glass for prototype modelling? so then i had to self develop gender theory and preconditioning during the night by intuition. i dont think i got them correctly until now

author: westfw
author_rank: Super Contributor
timestamp: July 26, 2022, 05:32:48 am
content: QuoteI think "analysis of algorithms" is generally an MS-level class. Undergrads are lucky to get "check it out - some sort algorithms perform better than others. Tomorrow we do trees, and next week is regular expressions!"

author: brucehoult
author_rank: Super Contributor
timestamp: July 26, 2022, 06:27:49 am
content: Quote from: westfw on July 26, 2022, 05:32:48 amSeriously?How are you supposed to design even the simplest loop  without knowing what your base case, invariant, and inductive step are?I mean ... proof by induction was high school, so when I got to programming at university they could assume that as background. And I went to the 5th best out of 7 universities in NZ at the time. I just did a quick search and found these lecture notes at a university near here (Australia, not NZ, but close enough), so this stuff was taught in 2nd year as recently as 2016:https://comp.anu.edu.au/courses/comp2600/Lectures/19wp1.pdf ok, except maybe "for x in set/range ..." quite deliberately, as 1) it was in a smallish pleasant city, and more importantly 2) they were too small to get one of the Burroughs 6700 mainframe computers the four bigger universities had, and had an infinitely nicer PDP-11/70 instead, with a VAX on the way by the time I got there.I only learned decades later that they got the PDP-11/70 via a swindle which displeased the Ministry of Education considerably. The Ministry was not prepared to provide capital funding for a computer, saying that Waikato university should use a terminal/punched card reader/printer connected to the University of Auckland mainframe 100 miles away. The computing department arranged to take delivery of a brand new 11/70 for $548,000 (academic pricing, with no import duties or sales tax) at 11:00 one morning in 1976 with "absolutely no ability to pay for it". At 11:01 they sold it to a friendly commercial bank, and at 11:02 signed a deal for lease-to-buy.

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 26, 2022, 08:37:10 am
content: Quote from: brucehoult on July 25, 2022, 11:59:34 pmReminds me of a Uni "party" decades ago, when a Philosophy student presented theirtruthinesstruthfulness theory. (That in itself was odd, us physics students were used to parties being where you drink and meet people and have fun.)The theory itself was: Let \$T_k\$ represent the truthfulness of sub-statement \$k\$, \$0 \le T_k \le 1\$ \$\forall k\$. Then, we can calculate the overall truthfulness \$T\$ of the combined statement via$$T = \prod_k T_k$$and they spent forty minutes describing it.The cute chicks were really in awe of the babble, though.

author: westfw
author_rank: Super Contributor
timestamp: July 26, 2022, 10:03:42 am
content: QuoteWell, comp2600 is not in the current "requirements" for "Bachelor of Advanced Computing (Research and Development) (Honours)", much less any of the lesser degrees...https://programsandcourses.anu.edu.au/program/AACRD#program-requirements

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 26, 2022, 07:50:17 pm
content: Quote from: brucehoult on July 26, 2022, 06:27:49 amTrue.Welcome to the 21st century.

author: Mechatrommer
author_rank: Super Contributor
timestamp: July 26, 2022, 07:58:46 pm
content: make me wonder why i can still make some useful programs even though i cant prove them formally?... when reading turing's paper on his general purpose machine, i thought whats the big deal? we all know binary numbers!.. its amazing the knowledge that was once only in the great thinkers mind now is like a childborn built-in knowledge

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 26, 2022, 08:27:20 pm
content: Quote from: Mechatrommer on July 26, 2022, 07:58:46 pmBecause you apply rules that either someone else has worked out and taught you, or you yourself have found via practical experimentation. You do not know the domain where those rules are reliable, you just write the program according to the rules you know.The problem is, you do not know when your program no longer produces useful results. You only know "it works for me". It is usually a surprise to you that the program fails in certain cases. To those that understand the implementation formally, usually immediately grasp where the problem lies when the input and the error or problem is described to them.(This assumes that by "prove them formally", we mean that you have a complete understanding of the implementation, not that you know how toconveysuch understanding in standard form. Being able to convey the understanding, somehow, is important though, because us humans often believe we completely understand something until we actually try to convey that understanding, even if to a rubber duck.)I self-taught myself to program before I had had any higher math or formal logic classes. I am by nature analytical, so I had a huge relief and excitement when I found the formal math used to describe these things; it waslikefinding a language that can express the things I had been trying to grasp, and then apply the tools hundreds of mathematicians and logicians had developed, to solve more and more complex problems.(I myself am "bad" at writing formal proofs. For some reason, I seem to see and think a bit differently about certain things, so those that do formal proofs often can usually simplify them into much simpler and easier to understand expressions. But that is not the same thing as my proofs beinginvalidorwrongorincomplete, just, uh, "artless".)While those formal proof things canseema waste of time, they do actually come packaged with extremely powerful tools in algorithm analysis and development, which will allow you to cut some problems into trivial bits, and do so with simple code that you probably wouldn't understand without those tools.Recursion and loop analysis, algorithm time and space complexity, and logic and graph theory based approaches to certain problems come to mind.Here is a practical example:Consider a large chessboard-like grid. You have different colored pebbles on the grid. Whenever two pebbles of the same color are in adjacent cells, they belong in the same group. The question is, how do you count the number of groups on the grid?The solution is a simple abstract data type calleddisjoint-set, preferably with path compression. When you start with an all-singleton set with each pebble described in the set, then apply Union to each pair of adjacent pebbles, you end up with a set where each group is distinct. Flatten the disjoint-set data structure, and you have a group identifier for each pebble. To count the number of groups using this approach, you need two numbers (between 0 and the total number of pebbles, inclusive) per pebble, of space. Time complexity is less than you'd expect, but is a pretty complex topic.You can use this data structure without understanding why it works, but unless you know its limitations and requirements, you won't know if or when it fails.It will be almost impossible to say (without it being a pure guess) whether it can be used to solve some problem more efficiently/faster than some other method. With algorithm analysis, you can at least easily compareasymptoticbehaviour.

author: brucehoult
author_rank: Super Contributor
timestamp: July 26, 2022, 11:39:01 pm
content: Quote from: westfw on July 26, 2022, 10:03:42 amA sufficient reason for it not to be a required course is they're not teaching comp2600 at all currently.However if seems much the same material is being taught in a FIRST year class, comp1600, which is on that required course list:https://comp.anu.edu.au/courses/comp1600/lectures/There are even a bunch of videos on youtube:https://www.youtube.com/playlist?list=PLA72M-qSGPm2WxSxXthNiYx2u4KBZlXCCThe first video is less than 3 minutes long:2nd comment on youtube: "this is where the good stuff starts."

author: Mechatrommer
author_rank: Super Contributor
timestamp: July 26, 2022, 11:59:37 pm
content: thats explained why some papers/courses look gibberish to me, i've been having difficulty in understanding some engineering/paper/technical reading esp when it comes to SETS, recently i tried to dig whats the high level math is all about and i start to seeing things and notions that i've not seen before, being in engineering study i know we are using a subset of math (balance of left and right side or solving values, calculus etc), but this is not what i've imagined, it started to look like poetrya list of procedures/steps in proving things. i guess this kind of things have passed me, i cant start all over there are too much to study and time needed than what i think i currently have, so i have to move on... thanks for clarification about this subject...https://www.springerprofessional.de/en/springer-undergraduate-mathematics-series/1020322

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 27, 2022, 07:13:09 am
content: Quote from: Mechatrommer on July 26, 2022, 11:59:37 pmDon't worry;knowingwhat you don't yet know, but can reach for when you have the time, is a very big and Good thing.Just like you said, those programs you writeareuseful; you just do not yet have the expertise toproveor 'formally quantify or qualify their behaviour'. If you need that, you can always reach for others to help. More importantly, you now know to say "I don't know, but I know how we can find out", instead of guessing. This isimportant, and core part ofrational behaviour.As an example, I myself have lots of experience in numerical simulations, (pseudo)random number generators, and software development in general, and formal education in that. I even have some formal education in electronics, although it is theoretical only. What little practical experience I have, is wiring modules (sensors) to single board computers, implementing suggested application circuits from datasheet, and so on. So, when it comes to real-world circuits, especially designing a new circuit to do a real-world task, I'm a complete beginner!And that is okay. Just go take a look at the threads I've started at the Beginners forum, and you can see how much I appreciate the help and learn from it.There isabsolutely nothingwrong in not knowing stuff yet, as long as one acknowledges it.

author: westfw
author_rank: Super Contributor
timestamp: July 28, 2022, 04:06:35 am
content: QuoteWell, I never had any classes that attached mathematical formalism or terminology to that sort of stuff. But then, I was an EE major and carefully trying to fit "interesting" CS classes into a schedule that already had a limited number of "technical" electives I was allowed to take (that was back in ~1980 when no one was admitting that an EE might need to know how to program.) (that's back when Stanford didn't even have a CS degree, BTW. They just considered it a subset of the Math major...)Stanford has an interesting online classIntroduction to Mathematical Thinkingthat posits "if you came up through a normal HS, or have taken science classes like physics, you probably think of math as a way of getting results." Yeah, that's me. I've tried taking some of the more mathematical online classes, and ... they're really tough. It seems I need to go back a very long way just to learn (or re-learn) the vocabulary...

author: DiTBho
author_rank: Super Contributor
timestamp: July 28, 2022, 06:32:48 am
content: Quote from: westfw on July 26, 2022, 05:32:48 amone week

author: brucehoult
author_rank: Super Contributor
timestamp: July 28, 2022, 07:05:48 am
content: Quote from: westfw on July 28, 2022, 04:06:35 amI started university in 1981. I hard a hard time deciding whether to do Computer Science at the small (3000 students) Waikato University in Hamilton which had PDP-11s and a VAX on the way, or Electrical Engineering at the big Auckland university in the big city. I'd looked through both places. A friend started at Waikato a year before me and I went with him to one of his programming labs. The first year students were doing FORTRAN on a PDP-11/34, but I was told they were switching to Pascal next year. Auckland had an open day and I got my grandmother's brother (who passed away five years ago at 98) to take me. The electrical engineering department had some interesting HP lab computers and some microprocessor SBCs controlling various things. So it could have been interesting.You don't have to get into scary mathematical notation (and it *is* scary if you try to read it too fast) to reason about your loops. Just think about what ASSERTs you can put before, after, and in the middle of your loop. And how you can make one identical ASSERT that will work in all three places.e.g.Code:ASSERT(is_sorted(a, 0, 0));for (int i=0; i<n; ++i){...ASSERT(is_sorted(a, 0, i));}ASSERT(is_sorted(a, 0, n-1));

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 28, 2022, 08:02:11 am
content: Quote from: westfw on July 28, 2022, 04:06:35 amMe, too, most definitely. I mean, I can read (and understand) pretty complex stuff, and I can write down the things that show something is true, but being someone who onlyappliesmath, I have big difficulties in "thinking in math", the way mathematicians do. But that's okay, too, because I know just enough to be able to describe the things in sufficient form to a friendly mathematician, so they can help.And knowing how to efficiently ask for help is an important, useful skill, in all areas of life, I've found.Quote from: brucehoult on July 28, 2022, 07:05:48 amWell put. The notation is just a formal language to describe things efficiently and precisely. It is an effective, powerful tool, but it is notrequiredto reason about things using the same approach. If you do take the time to learn the notation, it makes it easier to follow interesting notes and lectures online, though.

author: DiTBho
author_rank: Super Contributor
timestamp: July 28, 2022, 09:05:04 am
content: Quote from: Nominal Animal on July 28, 2022, 08:02:11 amAt some point, the little girl with a sad and sulky look made a move with her finger, pointing the old man in front of her, who replied something really wird for a little girl -“do not worry about your difficulties in Mathematics. I can assure you mine are still greater”- Nobody knows what she was talking about, probably some primary school homework and what that sentence really meant, but the empathic communication went straight to the point of making her change her sulky face with a hint of a smile - "what's your name?" - she then asked, and the man replied - "Albert, Albert Einstein" -

author: DiTBho
author_rank: Super Contributor
timestamp: July 28, 2022, 09:26:31 am
content: Some of Albert Einstein's papers were quite mathematically sophisticated - "since the mathematicians have invaded the theory of relativity, I do not understand it myself anymore" - he said, involving advanced subjects such as stochastic differential equations and tensor calculus.... "I do not understand it myself anymore" that's why modern stuff needs brainstorming