#adt bags

1 messages · Page 1 of 1 (latest)

astral musk
#

Genuinely stressed for my exam I feel like I cannot get past adt bags at all it feels impossible to do, making me give up .

pine parrotBOT
#

<@&987246399047479336> please have a look, thanks.

merry wasp
#

how can we help you

pine parrotBOT
#

adt bags

#

Changed the title to adt bags.

astral musk
#

I still since yesterday posted and your advice was great but it’s hard for me to grasp it I need advice on how to achieve it I have a few weeks till the exam like 3.5 weeks I don’t know if that’s enough time

merry wasp
#

okay but whats ur question

#

how can we help you today

astral musk
#

The bag concept is confusing the different types, array and linked. Array stack , linked stack and vector stack. How do I understand these methods better?

merry wasp
#

thats a very broad question and the answer to that would be the same as yesterday

#

if you just ask the same thing, you get the same response

astral musk
#

Yeah but the drawing diagrams part confused me

merry wasp
#

can you be a bit more concrete please

astral musk
#

You said draw diagrams do you mean draw diagrams of the process of how the bag works ?

#

What happens in the node etc

merry wasp
#

yes. if u give me a concrete case i can also give you a concrete example

#

but if u remain so broad ull only get broad responses

#

u know, when u google a data structure u immediately get these kind of animation/images/illustrations/visualizations

#

and thats the kind of stuff u need to be able to draw

#

so if someone tells u for example

#

"given a linked list currently containing [1, 5, 3, 8]" - draw the diagram

#

and if they then say "lets now add the value 4 after the value 3". draw the diagram how it looks afterwards

astral musk
#

Yeah I understand that because I was mainly trying to find advice for it. But I will give you a concrete example. My exam will contain methods we need to fill in it won’t contain all methods only some and these methods can be any bag or linked . I’m studying what will be on my exam, never have been told to draw. I have methods I need to know and fill it in.

merry wasp
#

if they say "we now remove the node 5", draw the diagram

#

the diagram stuff is what u first need to nail

#

cause thats what makes it so u actually understand the datastructures and algorithms in ur brain

#

if u cant draw the diagrams for arbitrary situations, ur lost

astral musk
#

I understand that, do you have any questions that can help me do this? Or where to find

merry wasp
#

i just gave u a concrete example that u can work with

#

u can pull these out ur nose, its super easy

astral musk
#

Alright alright

merry wasp
#

linked list example for what i said above

#

now lets say the 3 is removed

#

u need to be able to draw it like this for example:

#

cause this exactly visualizes the step u also have to do in ur code then

#

namely changing the pointer of the node 5 to point to node 8 instead of 3

#

or adding node 4 in between 5 and 3:

#

this is how u learn a linkedlist and all its operations

#

u just draw

astral musk
#

So you said before after 3 add 4 is this because it gets removed I can add it between 5 and 3

merry wasp
#

it doesnt matter

#

u should be able to understand and handle any situation

#

"given this list. we now remove this and that node. now we add a node here, maybe another here. now we change the value of this node, now we do this, now that, ..."

#

it really doesnt matter

#

thats why im saying its so easy to pull these examples out of ur nose

#

if u truly understood the data structure, u also know how to change the pointers on the diagram to do any operation

#

u dont need code to understand a data structure. thats the second step

#

data structures and algorithms are learned via pen and paper first

#

and only after u fully got it in ur head, then u should look at how to put these steps into code

#

and that part is then usually easy bc u already have a super clear plan of the steps

#

and the coding is assisted by constantly evaluating with ur example

#

dont just write code and then hope it works

#

write one step, execute&test, write another step, execute&test

#

code is written incrementally

#

when u for example make ur own linkedlist class, one of the first things to add is a method that prints out the current state of the list

#

this method is needed before u make a method that adds something

#

or one that removes something

#

bc u need this printer thing to evaluate that ur add/remove methods are correct while ur coding them

#

and if u for example look at this for adding node 4 between 5 and 3:

#

u know exactly what the steps for adding a node somewhere are:

#
  1. locate the node after which to add it (node 5 in this case)
  2. create the new node to add (node 4)
  3. ensure node 4 next points to the node after node 5 (node 3 in this case)
  4. change node 5 next to point to the new node (node 4)
#

so with these steps down, writing the code is trivial

astral musk
#

And so after this those steps basically match the code in what you’re saying

merry wasp
#
void insertAfter(int valueToAdd, int valueToInsertAfter) {
  // Step 1: Find node with value
  Node node = head;
  while (node.next != null) {
    if (node.value == valueToInsertAfter) {
      // Great, found it
      break;
    }
    node = node.next;
  }

  // Step 2: Create new node
  Node nodeToAdd = new Node(valueToAdd);
  
  // Step 3: change new nodes next
  nodeToAdd.next = node.next;

  // Step 4: change previous nodes next
  node.next = nodeToAdd
}
#

see how easy it is. bc i understood the data structure i can just write the code for this arbitrary method within 5 minutes

#

bc we figured out the steps before on a picture

astral musk
#

Yeah I see

#

Thank you I appreciate sorry for taking ur time this is just hard for me

#

But I understand your way of learning I will do that

merry wasp