Check out a free preview of the full Data Structures and Algorithms in JavaScript course:
The "Pseudocoding the Matrix Constructor" Lesson is part of the full, Data Structures and Algorithms in JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Bianca pseudocodes the constructor for a Graph. The main function of the constructor is to initialize the storage matrix.

Get Unlimited Access Now

Transcript from the "Pseudocoding the Matrix Constructor" Lesson

[00:00:00]
>> Bianca Gandolfo: Pseudocode, we're just thinking about representing our graph as a an adjacency matrix. So I guess, in our constructor, we might need to have a matrix in there? Perhaps?
>> Bianca Gandolfo: What might I need to create a matrix? So everyone, does everyone know what a matrix here is, when we talk about matrix in terms of how we represent them in programming?

[00:00:31]
>> Bianca Gandolfo: I'm gonna take that as a no. Which is fine, cuz I can explain it right now. So a matrix is how we represent, like something on a 2D plane, often. Anything that's a game board, chess, whatever, tic-tac-toe. Those are always gonna be, if you've done any of those sort of toy problems, those are gonna be represented as a matrix, or a 2D array.

[00:00:58] There's a lot of like, mathematical stuff around matrices, but doesn't matter for us, but is the same thing.
>> Bianca Gandolfo: What else do I wanna say about matrix? Yeah, so if we were gonna have a like, two by two matrix, it would look like this.
>> Bianca Gandolfo: So that's a two by two matrix, and often, it's an array, right?

[00:01:29] So here's,
>> Bianca Gandolfo: Actually, it's like this, no, I'm confusing myself. I had to do it like this, so I can see it.
>> Bianca Gandolfo: I think I have an extra bracket. Here we go.
>> Bianca Gandolfo: So we see that we have two arrays here, and we can represent by columns and then rows.

[00:01:57] We could put some values in here, etc.
>> Bianca Gandolfo: Cool, so that's our matrix.
>> Bianca Gandolfo: Cool, so we need to like, initialize a matrix with,
>> Bianca Gandolfo: Maybe some, we could start with sort of a default number of empty spaces, or we could just start with one and then add as we go.

[00:02:32] So your specific implementation, I'm not really opinionated about it. But, so just need to create a matrix, so let's just say initialize the matrix.
>> Speaker 2: Is there a minimum to create a matrix? Like, do you have to have one column and one row, or it's not a matrix?

[00:02:50] Or like,
>> Bianca Gandolfo: Yeah, you have to have at least, I don't know what like the actual rule is for the definition, but if you don't have, like an array within an array, then it's just an empty array essentially.
>> Speaker 2: Okay, thank you.
>> Bianca Gandolfo: Mm-hm. Cool, so we initialize our matrix, our adjacency matrix, somehow, and we can decide what makes the most sense for us when we get there.

[00:03:25] What else might we need?
>> Speaker 2: Values? I guess we don't need them.
>> Bianca Gandolfo: Okay, well we can start there, and then move to this method and see if anything comes up.
>> Bianca Gandolfo: Yeah, so do you guys follow my process of creating data structures and algorithms? Basically, my process, and we've been doing this this entire classes.

[00:03:57] Okay, let's think about the thing that we just drew, we saw a picture like, what are the things that stand out, right? What's the first thing that stood out, others than matrix? Maybe we should Google what matrix is, figure out what that is. And then, my next thought would be like, what else might we need in there?

[00:04:16] And then, if I'm like, well, I'm not quite sure, I'm gonna move on to the next thing and then see if something arises where I get stuck, and then I need something extra. And so, I encourage you just to use the same process when you're reasoning through, learning a new data structure or algorithm, cuz there's no way we're gonna memorize all of them, right?

[00:04:36] Like, even if you take this class three times, unless you're teaching the class, it's really, really hard to memorize, and I even forget stuff too, and I teach this class. So it is important to just be able to reason through it, rather than trying to stick to your memory about like, how the specific implementation is and all that, okay?