Operations on Data Structures Flashcards
(13 cards)
How do you create a 1D array in OCR pseudocode?
Use arrayName ← [ ] or declare with initial size, e.g., arrayName ← new array[5].
How do you add an item to a 2D array in pseudocode?
Use two indices, e.g., array[x][y] ← value.
How do you remove an item from a 3D array?
Set the element at the specific 3D index to null or default, e.g., array[x][y][z] ← 0.
How do you add a node to a linked list?
Create a new node and adjust pointers to insert it at the desired position.
How do you remove a node from a linked list?
Redirect the pointer of the previous node to the node after the one being removed.
How do you add an element to a stack?
Push the item to the top using stack.push(value) or add at top ← top + 1.
How do you remove an element from a stack?
Pop the top element and update the top pointer.
How do you add an item to a queue?
Insert the item at the rear and update the rear pointer.
How do you remove an item from a queue?
Remove the item from the front and update the front pointer.
How is data added to a binary search tree (BST)?
Compare to the root; go left if smaller, right if larger; insert in correct null position.
How is data removed from a binary search tree (BST)?
Find the node; if it has: No child: remove directly, One child: link parent to child, Two children: replace with inorder successor/predecessor.
How is data added to a hash table?
Use a hash function to compute the index and insert at that position or handle collision.
What does traversing a data structure mean?
Visiting each element in a specific order to read or modify its data.