Data Structures

So in this week he will go over vectors, queues, and stacks, which I am vaguely familiar with.

He also goes over the Birthday Party problem part 2, which is given a set number of thing a and thing b, with a person each having a sibling, what is the most number of quests invited such that all toys and sweets are distributed equally.

So the way that i assume we do this is we first count up the total number of people, aka the sum of the array and the array size added. This gives us the total people count. We then see if this value is a even divisor for the both of the two items given, and if so then we can assume this number of people can be divided, if it is not, then we subtract one from the total number of invites and check again.

Pasted image 20261023174804.png

Okay so I understand now, basically he meant that each of the given people MUST come with their sibling, meaning that you have to try and prioritize the people with the least siblings to then the people with the most siblings, the above pseudocode does so by brute force with a 3 level deep nested for loop, not efficient at all, but it does work.


Vectors

A vector is basically a dynamic array, but he calls it as an abstract data structure that collects data where each piece of data comes after another piece of data, and they can be constructed in a line.

A vector is finite, and has a non-negative amount of elements, it can be empty so the number of elements it has is zero. It apparently is a fixed size value and so the number of elements inside of it cannot be altered (this is just some bullshit?)

Given that the vector just represents an immutable array, what it actually is is an array, this means that the length of the array is equal to the number of elements that it contains. The elements are stored in a given order as an index and what not.

What operations exist on a vector?:
Pasted image 20261023175627.png

Inside of pseudocode, these are the main operations that exist on a vector, they are similar to what you would find on a given array inside of a programming language, given that an array is immutable, you cannot change it’s size, but you can change the elements at a given index. To do this of course you also have to be able to select the elements, and know their indexes via something like the length.

This means that functions like delete![k] or add![o] would not be possible on this vector that they speak of, this is because once again it is:

Pasted image 20261023180301.png

See people called them out on their bullshit, you only see the term vector used in C++ and NOWHERE ELSE, and in C++ it is called a vector and represents a dynamic array, people call these things arrays, and then the dynamic version is called a list, this is the most retarded thing I have ever heard.

Okay back to the lesson, he says if you want to expand a vector you can allocate more memory to a new vector and then copy over the elements from the original vector into this new vector. This is generally just done with a for loop.


Queues

A queue is like a real life queue pretty much, you need to have a wait, and so the longer that you have been waiting, the sooner your going to be called on. Basically, queues are like lines, whenever you add in an element, the last element gets popped out. So it follows a “first in, first out” kind of a philosophy, where the first item in the queue will be the first to leave.

Queues:
Pasted image 20261023181038.png

So give this queue as it exists right, you basically have this vector of sequential elements, and you end up with two different parts that you can access at a given time. You have the head of the queue, which is the element that gets removed from the queue, and then you have the tail of the queue, which is the element that you are able to add to, and this new element becomes the new tail.

Given that you only have access to the head and to the tail of a queue, this means you cannot read out every single value from the queue like you can with a vector. In order to access an arbitrary element in the queue, you first need to remove all of the elements in front of it, so the element you want to access becomes the new head.

Operators for a Queue:

Pasted image 20261023181317.png

So you have these operations, head returns the element at the head of the queue and does not remove it. Dequeue then returns the head of the queue and removes that head so the element after becomes the new each.

enqueue this adds an element to the tail of the queue with the actual contents of that exact o value that you wanted to pass in. empty then checks to see if there are any values inside of the queue or not, it returns true or false.