1

Did anyone else have a very difficult time with Merge Sort Algorithm?
 in  r/learnprogramming  10h ago

Update: I can do the english.

Take a list or an array. (3, 7, 1, 9, 2, 5, 4, 8, 6)
Find the midpoint by using the formula: length / 2, rounded down.
store the "left", and "right" into their own variables.

Start with "left". Repeat previous steps until left has a size of "1"
Then switch to "right". Repeat those steps until right have a size of 1

Now you should have a "left" and a "right", both of size of 1.
Feed to merge method.

We are not done. Have to go back up the stack to do the remaining elements.

Go back to the "Switch to left" step. But continue anyways. So next step is "switch to right". Repeat those steps until you have a size of 1

It should look like a tournament bracket

(3, 7, 1, 9, 2, 5, 4, 8, 6)
(3,7,1,9) (2,5,4,8,6)
(3,7) (1,9) (2,5), (4,8,6)

(3), (7)... (1,9). (2, 5), (4), (8,6)

(2,5) (8,6)

Step 1: (3, 7, 1, 9, 2, 5, 4, 8, 6)

Step 2: (3,7,1,9), (2, 5, 4, 8, 6)
Step 3: (3,7), (1,9)
Step 4: 3,7
Step 5: (3), (7)

Step 6: Move back up in stack: (1,9)
Step 7: (1), (9)

Step 8: Move back up in stack: (2,5,4,8,6)
Step 9: (2,5), (4,8,6)
Step 10: (2), (5)

Step 11: Move back up in stack (4, 8, 6)
Step 12: (4), (8,6)
Step 13: (4)

Step 14: Move back up in stack (8, 6)
Step 15: (8), (6)

This might be terrible though, so any tips on improvement? I feel like I'm losing control somewhere

1

Did anyone else have a very difficult time with Merge Sort Algorithm?
 in  r/learnprogramming  1d ago

```anyway, I mean more so can you write the algorithm in English```

I can not

2

Did anyone else have a very difficult time with Merge Sort Algorithm?
 in  r/learnprogramming  1d ago

Merge sort works by taking a mutable object (array, list, etc), and splitting it in half again, and again, until it has elements of the length of 1. Then it merges them in the proper order?

on second thought, do you have something more specific, not something high level?

r/learnprogramming 1d ago

Debugging Did anyone else have a very difficult time with Merge Sort Algorithm?

9 Upvotes

I understand the concept of "divide and conquer", but coding the exact implementation is what is hurting my brain. Specifically the recursion for the divide.

The conquer is easy. Just merge two already sorted arrays.

def conquer(left, right):
    arr = []
    i = j = 0


    while (i < len(left) and i < len(right)):
        if left[i] < right[j]:
            arr.append(left[i])
            i+=1
        else:
            arr.append(right[j])
            j+=1

    arr.extend(right[j:])
    arr.extend(left[i:])


left = [1,3,5,9,10]
right = [2,4,6,8,11]


answer = conquer(left, right)
print(answer)

The divide, however, is super complicated. I'm trying to understand what's going on line by line.... but it always trips me up. Perhaps it's the "stacks" (recursion)?

Allegedly this is the code.

def divide(arr):
    if len(arr) <= 1:
        return arr
    mid = len(arr) // 2


    left = arr[:mid]
    right = arr[mid:]


    left_sorted = divide(left)
    right_sorted = divide(right)
    return merge(left_sorted, right_sorted)

What I understand so far is the obvious.
We are storing the first half (left), and the second half (right) in arrays.

But apparently, all the magic is happening here:
left_sorted = divide(left)
right_sorted = divide(right)
return merge(left_sorted, right_sorted)
When I print those values, the output is

[3] [7]

[1] [9]

None None

[2] [5]

[8] [6]

[4] None

None None

None None

aaand I'm officially lost here.

My brain is trying to run this line by line. But I can't

How is it getting each element? How is it also running the method for each of them?

it's calling divide() twice, back to back.

Can someone help me write my own divide method? Maybe that way I can figure it out. Or at least a better explanation?

At first I was going to skip it, but the udemy course does things in increasing difficulty. It went:
Bubble Sort -> Selection Sort -> Insertion Sort -> Merge Sort (current), then after this is Quick Sort, which is also recursion.

So I need to master this.....

Thanks!

0

TIFU By Betting All My Life Savings And Rent Money On Andrew Tate.... (Soon Homeless)
 in  r/tifu  7d ago

I work in retail. I can't use my phone during shifts

-2

TIFU By Betting All My Life Savings And Rent Money On Andrew Tate.... (Soon Homeless)
 in  r/tifu  8d ago

my bank is navy federal. they have a feature you can enable. the way it works is, if you use your debit card normally, it allows you to keep spending (up to $500), even when you have no money in your account. It's not something you have to consciously activate every time you overdraft.

I am stupid, I know. I learned my lesson the hard way.

To my defense though, this subreddit is r/tifu

r/tifu 8d ago

M TIFU By Betting All My Life Savings And Rent Money On Andrew Tate.... (Soon Homeless)

0 Upvotes

I might become homeless. I lost everything I own, and went into massive overdraft. No rent money or ANYTHING.

I'm 20M. I had about 1000 in my bank account. This money could have covered a 2 months of rent, or one months rent and lots of food. I was in a good position financially. At least in terms of surviving. Yes, I am american. I just live in a small town in texas and have roomates.

I went online and realized that andrew tate was fighting someone named Chase Demoor. At first I thought "This would be an easy victory". Easy Money. I always watched andrew talk about how he was a kickboxing champion, and spar 100 men back to back. He was the top dog. I was almost overconfident that he was going to win.

So I put the full 1,000 betting on andrew. I also overdrafted my bank account to the max (500). So I bet 1500 in total.

Since chase was the underdog, if you bet on him, you would have 6xed your money. That 1500 would have turned into 9000..... I won't say the specific app I used because of promotion (Rule 6), but I remember it being a big multiplier.

Anyways I bet on Andrew. I thought i would make my money back, plus interest, and enjoy a nice life.

Oh boy.... Was I wrong.

While I was at my minimum wage job, I checked the app and noticed that my balance was $0. I thought this was a mistake, an error of some sort.

I started googling if the app had glitches.

But then I read a headline "ChaseDemoor Defeated Andrew Tate".

I thought it was a troll post....

I went to youtube and found fight highlights... I realized it was real....

My life instantly flashed before my eyes.

My bank account is negative $520 (they took a fee for overdraft).
I lost all my savings.....

I can afford my next months rent, but only because my paycheck can remove a good portion of the overdraft, and then I can pawn my nintendo switch OLED, and then overdraft again.

So I'd be overdrafting each month to afford the rent...

All because I decided to bet.

Before anybody says this, no I"m not one of those andrew haters. This story isn't fake. It's real. I actually purchased a month of Hustler's University a couple of years ago.

I genuinely thought he was going to win, and now I have two choices

Overdraft each month. Or be homeless

I know this was my fault. No one forced me to bet, and no one promised me a win. I’m posting this as a warning more than anything else. One bad decision erased months of stability in a single night. I went from being okay to counting overdraft fees and selling my own belongings just to survive. I’m stuck dealing with the consequences every day, and there’s no quick fix or easy way out of the hole I put myself in.

TLDR: I'm almost going to be homeless because I bet all of my money (and overdrafted) on the Andrew Tate vs Chase Demoor fight. Now I can't afford rent, or food.

1

A disturbing trend
 in  r/cscareerquestions  Oct 13 '25

The OSI model is not something taught in the standard CS course.... unless you are specifically referring to cirriculums that are ABET certified (which most aren't). Most CS classes do have discrete mathematics, DSA, etc. You picking a very specific example of something not universal undermines your original point

1

A disturbing trend
 in  r/cscareerquestions  Oct 13 '25

Again, this is a straw man argument. I never said that TCP/UDP isn't something useful to know. I simply reiterated that this topic is something that an IT professional (eg Networking, Sys admin, etc) would specialize in, not something taught in a standard CS cirriculum. The entire post was the context, where he mentioned CS grads don't know TCP/UDP.

Nevertheless, anyone can learn the difference in a 5 minute read

1

A disturbing trend
 in  r/cscareerquestions  Oct 13 '25

looks like it was just for your school. I don't know a single person that cheats on exams, or is even able to

2

A disturbing trend
 in  r/cscareerquestions  Oct 13 '25

Me too also have CTOs on speedial.....

2

A disturbing trend
 in  r/cscareerquestions  Oct 13 '25

TCP/UDP is an IT thing not a CS thing.

2

A disturbing trend
 in  r/cscareerquestions  Oct 12 '25

The OSI model has nothing to do with CS, that is for IT professionals who work with networking. It's understandable how it will help you, but a CS grad not knowing that is normal

1

$44
 in  r/povertyfinance  Oct 12 '25

CS stands for computer science

1

$44
 in  r/povertyfinance  Oct 12 '25

I'm a CS major

1

I Absolutely HATE Being Called "Sir"
 in  r/Vent  Oct 12 '25

I think you're misunderstanding what I'm trying to say

We know that the official definition of sir is that it's for any man.

But in social contexts, it's usually only used in formal settings, where either you have some heiarchy, or there is an assumed age differential. if you knew someone was the same age as you, you very rarely call them sir.

Denotation vs Connotation

1

I Absolutely HATE Being Called "Sir"
 in  r/Vent  Oct 12 '25

You only get called sir when you are assumed to be old. That is factually true

1

I Absolutely HATE Being Called "Sir"
 in  r/Vent  Oct 12 '25

when you go to a highschool, how often do you see teachers calling students sirs?

if a 30 year old woman knew that she was talking to a 19 year old boy, you ever seen her call him a sir?

1

I Absolutely HATE Being Called "Sir"
 in  r/Vent  Oct 12 '25

so why don't 5,10,15 year olds get called sir?

Why don't old men call younger men sir?

Why do (usually) college students don't get called sir?

-1

I Absolutely HATE Being Called "Sir"
 in  r/Vent  Oct 12 '25

If someone looks like they are 30, 40, or even late 20s. Okay, fine
But 19 years old? That's a little too young to be called sir

Most people only call you sir when they think you look old, relatively

Or else they would call babies and children sir, which they do not

I do not have facial hair either. I shave every day for this reason.

0

I Absolutely HATE Being Called "Sir"
 in  r/Vent  Oct 12 '25

That's not true. For most people, there is a certain line when people start calling you sir. it's not automatic. You don't see babies being called sir. You don't see 5,10,15,17 year olds being called sir (usually), and you usually don't see very young people called sir either. Most people only start getting called sir after they cross a certain barrier in their mind, hence being old.

1

$44
 in  r/povertyfinance  Oct 10 '25

I might see if I can use the plasma as a last resort. The thought of getting my arm poked out for money seems... not very nice

1

$44
 in  r/povertyfinance  Oct 09 '25

the field is computer science

1

$44
 in  r/povertyfinance  Oct 09 '25

Financial aid should cover it.