Linden Garcia

Greenhorn
+ Follow
since May 30, 2021
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
7
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Linden Garcia

Campbell Ritchie wrote:If you mean they calculate the timings with an² + bn + c, then a b c are “constants” and n the number of elements in question. When you are dealign with large numbers, say 1,000,000 or 2,000,000, if you square them you get 1.0×10¹² or 4.0×10¹² and that increase will overwhelm the change from n = 1,000,000 to n = 2,000,000. So the time complexity reduces to its worst (=highest exponent) term. Beware if you have the misfortune to get eⁿ (or xⁿ) complexity (=exponential complexity) where doubling the size of the task can cause its duration to square itself. You will find a naïve recursive approach to calculating Fibonacci numbers in many beginning books; that runs in exponential complexity, but its base is small: it uses (approx) 1.618‟ complexity.



So If a, b and c are constants, what are they holding? What does an hold that’s different to bn or c. I guess I’m just not getting how the process of adding up the times for each line of code have been surmised into an squared + bn + c for the worst case, or similarly an + b for the best case.

As you say n relates to the number of elements in question and the squared part represents the growth, but what is the point/function of the constants?
2 years ago

Campbell Ritchie wrote:I haven't got the time to watch those videos. But I looked at Wikipedia, which says that insertion sort is one of the more efficient types of sorting in quadratic time (n²). The bit about quadratic time means that the time taken is proportional to the square of the number of elements; it should take 4× as long to sort a 2,000,000‑element list as a 1,000,000‑element list. Note that is the worst case behaviour; you will occasionally be lucky and find lists requiring little sorting, and the process runs much faster.



Thanks, I’d sort of heard about that but your explanation makes more sense now.

Do you know anything about how the an + b or an squared + bn + c means? As you say it relates to quadratic time, but I have no idea how.
2 years ago
Hi.

I’m currently trying to get my head around algorithms, specifically time complexity, and failing miserably. I’ve been following a multipart tutorial on algorithms in general, and managed to follow along until it got to discussing time complexity (not Big-O notation yet, simply the concept in more rudimentary terms.

Two of the videos in this series covered the topic in relation to an insertion sort algorithm which sorted an array of 8 numbers. This was the first video:


He explained how long each line — excluding the while loop which would be discussed in the next video — would take to execute. He labelled the time for each line as c1, c2 ... to c8. The first line which starts the loop would take c1 * n, and lines 2, 3, 4 and 8 would run c * n-1.

The confusion for me came in the second video:


This video began to explain the while loop and explore best and worst case time scenarios. Calculating minimum time seemed simple enough: you simply add up each line as it was calculated in the first video. Calculating the worst case was a little more involved but I still understood it: the worst case was dependent on the maximum time the while loop might have to run, so the rest of the equations stayed the same apart from lines 5, 6 and 7, where the equation is c * n * n-1/2.

I followed it right up until the end when I described how you would write the best and worst cases. The best case is apparently an + b, but I have no idea why. He said that n is the size of the array, so that’s the thing that changes (which I understand) but from what I gather, both a and b contain the sum of each line (c1 + c2...etc). I sort of understand why the a would be there, sort of as a container for all each line as it relates to n, but what relevance is b? Do both a and b contain the same thing? And what are we adding together if a is already summing up each line anyway?

The worst case is similarly confusing. a and b are there again, but this time, but this time b is also referencing n and an is squared. I see why it’s squared as that relates to what’s going on with the while loop, but the relevance of the two constants and how they work I don’t understand. The there’s also a c constant, which he didn’t really explain the relevance of at all. The way he wrote the worst case is an squared + bn + c.

Can anyone help me out?

Many thanks!
2 years ago
Thanks for the replies everybody! I’ve been working through it the last few days and finally cracked it, your comments were really helpful; I think I’m getting to grips with it now.
2 years ago

Paul Clapham wrote:I moved the thread to the JavaFX forum in the hope that people who knew something about JavaFX would see it.

I'm not one of those people but I'm sure that having your Application implement EventHandler is the wrong thing to do. It's been the wrong thing to do in Swing for over 15 years now and JavaFX isn't that different. So I tracked down a tutorial about how to use an EventHandler for a JavaFX Button:

Using JavaFX UI Controls

There's "back" and "forward" buttons there which I expect go to pages which deal with other kinds of control.



Ah, I didn't notice the JavaFX board or I would've posted it in there - thanks!
And thanks for the link, I'll read through; hopefully it will add some more context.
2 years ago

Campbell Ritchie wrote:Welcome to the Ranch

Please post your code here; people are often reluctant to go to distant websites.

Linden Garcia wrote:. . . related to action events and possibly action listener . . .

No, it isn't. Action events and action listeners are used in AWT/Swing, not FX. You have obviously had the misfortune to find the wrong sort of tutorial. I hardly know any FX, but you usually pass a λ to a setOnXXX() method. Let's see your code please.





This is the GUI so far:

2 years ago

Hi,

I'm trying to create a small program that displays shapes on screen. The user types in both the shape they want and the colour, and then the program will display the shape in the centre of the screen.

I understand that it's related to action events and possibly action listener, but I'm getting really bogged down with how to actually implement it and can't see the wood for the trees, so to speak. I was running through it in my head and thought maybe an if statement related to the event handler might be the way to go? So if the user types in say, Rectangle and Blue, display the given shape on the screen.

Here is the code I have so far: Pastebin  I've followed some tutorials online so far as getting the class set up for event handling, but I don't even really understand what I did. The more I read the more I realise I don't know!

Here's what my GUI currently looks like when it runs: imgur

Can anyone give me any pointers on where to start?

Thanks!
2 years ago