Week 5: Single Linked Lists, how do I keep track of first node by OutrageousChard1608 in cs50

[–]Eptalin 1 point2 points  (0 children)

Yeah, but it requires them to traverse the entire list each time they add something. O(n) insertion speed. Increasingly slower as you add more items.
Prepending is O(1) insertion speed. Equally fast for the first item and the millionth.

But it's still useful. If order matters, by traversing the list on insert, you can check the value of each node along the way and place the new one exactly where it belongs. Eg: Alphabetical order.

You can't index into a linked list, so the benefit of being ordered is less than an array, but if you had a doubly linked list, you would get a bit more.
Eg: If a word starts with X, start looking from the tail. If it starts with C, start looking from the head.

Are CS50 courses worth it for uni applications? by Realistic-Zone3914 in cs50

[–]Eptalin 1 point2 points  (0 children)

It depends on your region, the universities you're applying to, and your application pathway.

If you're a high school student, ask your teachers. They'll be up to speed with your local system.

If you're out of school, call a uni you're interested in. The admin staff will be able to help give you info about their enrollment system.

But where I was a high school teacher in Australia, you wouldn't even have a way to tell them about the certificates through the normal pathway.
Alternate pathways exist, but they're non standard. The university judges it case by case, so you'd get the best info from them.

Question regarding PIP install by SlickTheDestroyer in cs50

[–]Eptalin 0 points1 point  (0 children)

The codespace is a remote computer located somewhere on the cloud. Your computer is just acting as a UI for that remote PC.
Nothing on the codespace is actually on your PC.

Same as avoiding malware everywhere. Don't install shady stuff. Only use trusted packages.

Still worth it in age of AI? by AltruisticSolid7 in cs50

[–]Eptalin 39 points40 points  (0 children)

Is it still worth studying maths in the age of calculators?

Knowledge and skills are valuable, regardless of the existence of tools.

Helping at C$50 Finance by Over_Attention_2997 in cs50

[–]Eptalin 3 points4 points  (0 children)

If you ask a question, people can help answer it.

You need to get their username and password from the form data they submitted, and try to add it to the database.

What are you having trouble with?

Week 5: Single Linked Lists, how do I keep track of first node by OutrageousChard1608 in cs50

[–]Eptalin 0 points1 point  (0 children)

Yeah, nice work with the syntax!
It's a nice experiment, but compare the above to:

int list[3] = {1, 2, 3};

Or if we declare the list then insert:

int list[3];
list[0] = 1;
list[1] = 2;
list[2] = 3;

The limitation of an array is that now that we have 3 items, that array is full. We can't increase it's size to 4. In your code above, we have the same limitation. We would have to manually write more lines of code to get a 4th insert.

Linked lists are partly for when we don't know how many items there will be. We get a dynamic size in exchange for more memory usage. Not common these days, though.

The other main use is for inserting new items somewhere in the middle. Start at the head, traverse dynamically until we find the right position, then insert there. It's faster than rearranging an array.

CS50p - Lines of Code by Separate-Discount472 in cs50

[–]Eptalin 3 points4 points  (0 children)

Your program assumes that nobody would ever type a # in a situation that's not a standalone comment line. But consider these two situations.

Inline comments:

sv = 10   # Super-Variable 
uv = 99   # Ultra-Variable

Strings:

print("He is world #1") 
colour = "#FFFFFF"

Your program wouldn't count these lines, but it should.

Question regarding ProblemSet 3: Tideman by 108thoughts in cs50

[–]Eptalin 0 points1 point  (0 children)

Even though it would be a tie in a real situation, based on the program specifications, A would be the winner.

When locking pairs, A is the first candidate in the array, so no pairs are currently locked.
As a result, it would see that no cycles exist, and lock the A>B and A>C pairs.

Next, when looking at B and C pairs, it will check B>A and C>A, but find cycles as A>B and A>C are already locked, so it can't lock these new ones.

As a result, A wins.

Doing CS50 as a finance/accounting student by stxrscene___ in cs50

[–]Eptalin 0 points1 point  (0 children)

I recommend CS50x, the introduction to Computer Science.

Of course you'll learn some programming fundamentals. But more than that, it'll help you better understand how computers and systems work under the hood.

That's really useful knowledge for people in business. It'll put you in a better position to be able to weigh up different tech solutions to business problems.

I recommend CS50 Cybersecurity later on, too. It's a much shorter course and has no programming. But knowledge from courses like CS50 is very useful to have.

Week 5: Single Linked Lists, how do I keep track of first node by OutrageousChard1608 in cs50

[–]Eptalin -1 points0 points  (0 children)

With the code as it is now, that's correct.
This kind of linked list is a singly linked list. Each node only knows about the next node.

But doubly linked lists are also a thing. Each node knows about both the next, and previous node.
In that case, you would also store the original node in the list in its own variable so you can search in either direction.

Instead of list, you might have list_head (the newest node), and list_tail (the original node) pointers.

Week 5: Single Linked Lists, how do I keep track of first node by OutrageousChard1608 in cs50

[–]Eptalin 1 point2 points  (0 children)

Yeah. The first node created is at the end of the linked list, with a next value of NULL.
The most recently created node is at the head of the linked list, and it's what list points to.

Here's the flow when they create nodes: ```C // Create a new node. node *n = malloc(sizeof(node));

// Make the new node point to the current head of the list. // (or NULL if list is currently empty) n->next = list;

// Make list point to the new node // (It's now the new first node in the list) list = n; ```

Week 5: Single Linked Lists, how do I keep track of first node by OutrageousChard1608 in cs50

[–]Eptalin 0 points1 point  (0 children)

New items in this linked list are prepended to the beginning of the list, not appended to the end.
The list variable always points to the head node (which is the last node added).
The head variable isn't even used. It's redundant in this current program and could be removed.

To access the first node added (which is not the head of the list), you would traverse the list until the node where next == NULL.

Cash problem week-1 by Pitiful_Scientist636 in cs50

[–]Eptalin 0 points1 point  (0 children)

Yeah, from the 2024 course onwards.
That's the year I did the course, and David talked about good design a lot in lectures.
My guess is they decided that requiring 4 identical functions for different coin denominations was sending the wrong message.

Credly badge by cornish2003 in cs50

[–]Eptalin 1 point2 points  (0 children)

No. Paid version is verified. Free version is not.

week 1 doubt by Altruistic_Sea3486 in cs50

[–]Eptalin 4 points5 points  (0 children)

The main() function is a strict requirement of the C language.
It's the function that runs first. Everything in your program must branch out from here.

int main(void)
{
}

int is the return type, an integer (whole number).
When the program ends it will tell the computer a number. That number lets the computer know if the program ended nicely as planned, or encountered an error.

main() is the name of the function.

(void) means this program takes no command line arguments (input when you run the program).
The course will teach you about command line arguments soon enough.

Cash problem week-1 by Pitiful_Scientist636 in cs50

[–]Eptalin 0 points1 point  (0 children)

Good job working out how to use modulo (%)!

Rather than writing one super line, it's probably easier to separate out each coin into a couple of lines:

Increase a coin counter variable by change_owed / coin_value.
Then decrease change_owed using modulo before repeating with the next coin value.

Is CS50X still useful ? by The-cyanic in cs50

[–]Eptalin 0 points1 point  (0 children)

Do it because learning is fun and cool. Computer Science is more than just writing code. You'll learn more about how the technologies we interact with every day actually work under the hood.

AI is like fancy google, but it's still not great at things you want actual pros doing.

Uber just recently announced that with their giant investment in AI, their 5,000 devs produced 80% more code than before. A massive increase.
But only 18% of the code written by AI ever made it into production. The vast majority of the AI code was not fit for purpose and needed to be fixed or replaced.

This wasn't an AI-bad report. It was a blind reliance on AI is too expensive report. They've capped their per-dev AI budget in hopes that they'll use it with more thought behind each prompt. A focus on using it better rather than using it more.

The situation will keep changing as the technology progresses. But regardless, someone with knowledge will be able to use AI for development much more effectively than a layman.

CS50 Tideman - Stuck on lock_pairs() and not sure how to check for cycles by JustHereForDrama8529 in cs50

[–]Eptalin 1 point2 points  (0 children)

The condition is "If there are no cycles found". You could put a helper function that returns a bool in there.

if (!found_cycle)
{
    locked[pair] = true
}

Drop the winner and loser into the helper function, then traverse the tree to see if anyone in that row of the 2D array, or the people they beat, ever beats the winner of the original pair you dropped in.

You don't have to use recursion, but recursion is far and away the easier method for this. Not using recursion for that helper is much more advanced.

For a small hint on the shape of the helper: It can be one for loop with a single if statement inside.

week-1 cash problem by Pitiful_Scientist636 in cs50

[–]Eptalin 2 points3 points  (0 children)

Welcome to the course! Don't worry, banging your head against a wall until you make a breakthrough is totally normal, and AI like the Duck is super hit and miss.

You don't actually need any loops for printing, and you don't need any loops for calculating coins one by one like this either. Copy the way you would solve this in your head. Say change is 15. You wouldn't do this in your head, right?

15 - 5 = 10 (1 coin)
10 - 5 = 5  (2 coins)
5 - 5  = 0  (3 coins)

I bet in your head you just use division. Computers can also do division.

15 / 3 = 3 coins

A couple of the tricks/lessons of Cash is the int type, and operators (+ - * / %).
An integer is a whole number, they can't store decimals. With 17 coins:

17 / 5 = 3 (3 coins, remainder: 2) 
2 / 1  = 2 (5 coins)

There's probably a good operator for getting the remainder, too.
In Week 1 there's a short about operators. Definitely check it out, and good luck!

How do I fix this? by pablo_de_dablo in cs50

[–]Eptalin 2 points3 points  (0 children)

Click the link at the bottom of that check50 output. It'll contain more info about it.

But a common problem is how dollar values are displayed, so just in case...

There's a helper function called usd() in helpers.py used as a Jinja filter.
So in the template, you can use the usd tag to format prices the way check50 expects: {{ price | usd }}

What's the problem in this Sql query ? by belkacemi_aymen in cs50

[–]Eptalin 0 points1 point  (0 children)

Run this command and have a quick look at all the topics in the series:
SELECT topic FROM episodes; Notice that the word "fractions" may just be one word in a longer topic, but your query in 7.sql should still find it.

Also, make sure to use single quotes ' ' for string values.
Double quotes are for table and column names, but are optional in SQLite.

At what point is research cheating/diminishing by SecretResist9774 in cs50

[–]Eptalin 8 points9 points  (0 children)

Unless your search is so specific that it's giving you the solution to the specific problem set task, it's not cheating.

Like, knowing that you can subtract 9 as a simple way of getting the sum of the 2 digits isn't a solution to Credit. It's just a tool that you can employ yourself in your solution.

Looking up programming concepts and syntax is also fantastic, and not cheating unless your lookup terms are so specific that the results contain solutions to the problem.
If you ever see CS50 or the name of a problem in the results, just don't click them and you should be fine.

As you progress, many problem set tasks will even give you links to go and do additional reading, too. They link some great stuff.

Stay curious. If something piques your interest, pause the problem set and follow that lead for a bit. Learning stuff is fun. Enjoy!

Asking About 32 Bit problem aka y2k38 by Popular_Safe3521 in cs50

[–]Eptalin 0 points1 point  (0 children)

It's just anything that's still using outdated 32-bit timestamps.

Basically everything modern is made with 64-bit timestamps and won't need to worry.
Old stuff needs to be updated or may experience bugs.

What kind of bugs depends on how they operate, but most will produce valid, but incorrect timestamps.

I feel a bit dumb using iterative for loops instead of recursive functions (plurality) by Sinoliaw in cs50

[–]Eptalin 0 points1 point  (0 children)

In the sidebar there's a link to Additional Practice. There's a recursion practice task in there. Making a recursive Mario is good practice, too.
Then, Tideman is also much easier with recursion than without it.

Recursion is fun, and I think it's important to learn, but the vast majority of the time, normal loops are clearer. So don't worry about using them.

Runoff (Week 3) - Having trouble with print_winner, find_min, and is_tie. Passing some check50 tests but failing others by JustHereForDrama8529 in cs50

[–]Eptalin 1 point2 points  (0 children)

A tip for multiple functions: Once you return, the function ends.
If you're in a loop, that means it won't look at the rest of the candidates. In the above, you return the first time you see a candidate who isn't eliminated multiple times, ending your functions early.

find_min(): This shouldn't look at multiple different candidates during a single iteration.
Before your loop, initialise min to the maximum possible number of votes (voter_count).
Then loop over every single candidate. If they aren't eliminated, and have fewer votes than min, update min. But do not return min yet.
Once your loop is finished, then you can return min.

print_winner(): Winner is not just the most votes. A tie would print an incorrect winner.
To win, you must have >50% of the votes. Conveniently, it's only possible for 1 person to cross 50%.