answersLogoWhite

0

What is a node id?

Updated: 12/23/2022
User Avatar

Wiki User

13y ago

Best Answer

It is the value of the attribute id of a node. It is used when manipulating the DOM and can be accessed by using the function getElementById() of the document object in JavaScript

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a node id?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

With the help of a program explain the depth first traversal of a tree?

Refer to the following code and example output below. #include<iostream> #include<time.h> #include<queue> #include<stack> class tree { private: struct node { static unsigned s_id; // static id unsigned id; // instance id unsigned data; // instance data unsigned depth; // depth of node node* left; // pointer to left node (may be NULL) node* right; // pointer to right node (may be NULL) node (unsigned num, unsigned depth): data (num), left (NULL), right (NULL), id (s_id++), depth (depth) {} ~node () { delete (left); delete (right); } void insert (unsigned num) { if (num < data) { if (!left) left = new node (num, depth+1); else left->insert (num); } else { if (!right) right = new node (num, depth+1); else right->insert (num); } } void print () { std::cout<<"ID: "<<id<<" Depth: "<<depth<<" Data: "<<data<<std::endl; } void print_sorted () { if (left) left->print_sorted (); print(); if (right) right->print_sorted (); } }; node* m_root; public: tree (): m_root (NULL) {} ~tree (){ delete (m_root); } void insert (unsigned num) { if (!m_root) m_root = new node (num, 0); else m_root->insert (num); } void print_sorted () { std::cout<<"Sorted-order traversal\n"<<std::endl; if (m_root) { m_root->print_sorted (); std::cout<<std::endl; } } void print_breadth_first () { std::cout<<"Breadth-first traversal\n"<<std::endl; std::queue<node*> q; if (m_root) { // enque the root q.push (m_root); // repeat while the queue is not empty while (!q.empty ()) { // dequeue the first node node* n = q.front (); q.pop (); // report the node n->print (); // enqueue left and right nodes if (n->left) q.push (n->left); if (n->right) q.push (n->right); } std::cout<<std::endl; } else std::cout<<"The tree is empty!\n"<<std::endl; } void print_depth_first () { std::cout<<"Depth-first traversal\n"<<std::endl; std::stack<node*> s; if (m_root) { // stack the root s.push (m_root); // repeat while the stack is not empty while (!s.empty()) { // unstack the top node node* n = s.top (); s.pop (); // report the node n->print (); // stack left and right nodes if (n->right) s.push (n->right); if (n->left) s.push (n->left); } std::cout<<std::endl; } else std::cout<<"The tree is empty!\n"<<std::endl; } }; // initialise static data unsigned tree::node::s_id = 0; int main() { srand((unsigned) time(NULL)); // create tree with 10 random numbers tree t; for(unsigned i=0; i<10; ++i) t.insert (rand ()); t.print_sorted (); t.print_breadth_first (); t.print_depth_first (); } Example output: Sorted-order traversal ID: 6 Depth: 2 Data: 334 ID: 4 Depth: 1 Data: 2335 ID: 0 Depth: 0 Data: 12490 ID: 5 Depth: 4 Data: 15590 ID: 9 Depth: 5 Data: 18484 ID: 3 Depth: 3 Data: 23160 ID: 2 Depth: 2 Data: 23786 ID: 8 Depth: 3 Data: 24171 ID: 1 Depth: 1 Data: 24598 ID: 7 Depth: 2 Data: 30731 Breadth-first traversal ID: 0 Depth: 0 Data: 12490 ID: 4 Depth: 1 Data: 2335 ID: 1 Depth: 1 Data: 24598 ID: 6 Depth: 2 Data: 334 ID: 2 Depth: 2 Data: 23786 ID: 7 Depth: 2 Data: 30731 ID: 3 Depth: 3 Data: 23160 ID: 8 Depth: 3 Data: 24171 ID: 5 Depth: 4 Data: 15590 ID: 9 Depth: 5 Data: 18484 Depth-first traversal ID: 0 Depth: 0 Data: 12490 ID: 4 Depth: 1 Data: 2335 ID: 6 Depth: 2 Data: 334 ID: 1 Depth: 1 Data: 24598 ID: 2 Depth: 2 Data: 23786 ID: 3 Depth: 3 Data: 23160 ID: 5 Depth: 4 Data: 15590 ID: 9 Depth: 5 Data: 18484 ID: 8 Depth: 3 Data: 24171 ID: 7 Depth: 2 Data: 30731 Each node reports its ID, depth and data. The ID tells us the sequence the nodes were created, where the node with ID 0 is always the root. The depth tells us the level within the tree where the node exists, such that the root is on level 0. With this information it is possible to draw a graph of the tree and thus better understand the order in which nodes are processed. The first listing shows the nodes in ascending order by data. With binary search trees this is the normal method of traversal. The second listing shows a breadth-first traversal, where each level is processed in turn, from left to right. The final listing shows a depth-first traversal where we follow left nodes before right nodes. You will notice that the implementation of breadth-first and depth-first are fairly similar, the only real difference being that breadth-first employs a queue while depth-first employs a stack. The nature of a stack also means we must push right nodes before left nodes to ensure left nodes are processed before right nodes. At first glance there doesn't appear to be much merit in either breadth-first or depth-first traversal. However, the example merely serves to show the difference between all the methods of traversal. When considering more complex graphs or maps, it may be advantageous to search through all the vertices that form an edge with a particular vertex (breadth-first) or to examine all the edges between one vertex and another vertex, where several routes might be available (depth-first). Both depth-first and breadth-first have practical applications in network routing and satellite navigation, where maps and charts must be graphed and traversed in a more logical manner than would otherwise be possible with sorted-order traversal.


Write an iterative function to search an element in a binary search tree?

_node* search (_node* head, _key key) { _node* node; for (node=head; node != NULL;;) { if (key == node->key) return node; else if (key < node.>key) node = node->left; else node = node->right; } return node; }


Algoritm for deleting the last element from a list?

Given a list and a node to delete, use the following algorithm: // Are we deleting the head node? if (node == list.head) { // Yes -- assign its next node as the new head list.head = node.next } else // The node is not the head node { // Point to the head node prev = list.head // Traverse the list to locate the node that comes immediately before the one we want to delete while (prev.next != node) { prev = prev.next; } end while // Assign the node's next node to the previous node's next node prev.next = node.next; } end if // Before deleting the node, reset its next node node.next = null; // Now delete the node. delete node;


Is null node equal to leaf node?

No. A leaf node is a node that has no child nodes. A null node is a node pointer that points to the null address (address zero). Since a leaf node has no children, its child nodes are null nodes.


How many pointers will have to be changed if a node is deleted from a linear linked list?

For a singly-linked list, only one pointer must be changed. If the node about to be deleted (let's call it node for the sake of argument) is the head of the list, then the head node pointer must be changed to node->next. Otherwise, the node that comes before the deleted node must change its next pointer to node->next. Note that given a singly-linked node has no knowledge of its previous node, we must traverse the list from the head in order to locate that particular node, unless the node is the head of the list: void remove (List* list, Node* node) { if (!list !node) return; // sanity check!if (list->head == node) {list->head = node->next;} else {Node* prev = list->head;while (prev->next != node) prev = prev->next; // locate the node's previous nodeprev->next = node->next;}} Note that the remove function only removes the node from the list, it does not delete it. This allows us to restore the node to its original position, because the node itself was never modified (and thus still refers to its next node in the list). So long as we restore all removed nodes in the reverse order they were removed, we can easily restore the list. In order to delete a node completely, we simply remove it and then free it:void delete (List* list, Node* node) {if (!list !node) return; // sanity check!remove (list, node);free (node);} For a doubly-linked list, either two or four pointers must be changed. If the node about to be deleted is the head node, then the head node pointer must be changed to n->next and n->next->prev must be changed to NULL, otherwise, n->prev->next becomes n->next. In addition, if the node about to be deleted is the tail node, then the tail node pointer must be changed to n->prev and n->prev->next must be changed to NULL, otherwise, n->next->prev becomes n->prev. Deletion from a doubly-linked list is generally quicker than deletion from a singly linked list because a node in a doubly-linked list knows both its previous node and its next node, so there's no need to traverse the list to locate the previous node to the one being deleted. void remove (List* list, Node* node) {if (!list !node) return; // sanity check!if (list->head == node) {list->head = node->next;node->next->prev = NULL;} else {node->prev->next = node->next; }if (list->tail == node) {list->tail = node->prev;node->prev->next = NULL;} else {node->next->prev = node->prev; }} Again, to physically delete the node we simply remove and then free the node:void delete (List* list, Node* node) {if (!list !node) return; // sanity check!remove (list, node); free (node); }

Related questions

What are limp nodes?

I think you mean lymph node and id im correct a lymph node is a small oval-shaped organ of the immune system which is why they can become swollen. They are found all through the body, and act as filters.


With the help of a program explain the depth first traversal of a tree?

Refer to the following code and example output below. #include<iostream> #include<time.h> #include<queue> #include<stack> class tree { private: struct node { static unsigned s_id; // static id unsigned id; // instance id unsigned data; // instance data unsigned depth; // depth of node node* left; // pointer to left node (may be NULL) node* right; // pointer to right node (may be NULL) node (unsigned num, unsigned depth): data (num), left (NULL), right (NULL), id (s_id++), depth (depth) {} ~node () { delete (left); delete (right); } void insert (unsigned num) { if (num < data) { if (!left) left = new node (num, depth+1); else left->insert (num); } else { if (!right) right = new node (num, depth+1); else right->insert (num); } } void print () { std::cout<<"ID: "<<id<<" Depth: "<<depth<<" Data: "<<data<<std::endl; } void print_sorted () { if (left) left->print_sorted (); print(); if (right) right->print_sorted (); } }; node* m_root; public: tree (): m_root (NULL) {} ~tree (){ delete (m_root); } void insert (unsigned num) { if (!m_root) m_root = new node (num, 0); else m_root->insert (num); } void print_sorted () { std::cout<<"Sorted-order traversal\n"<<std::endl; if (m_root) { m_root->print_sorted (); std::cout<<std::endl; } } void print_breadth_first () { std::cout<<"Breadth-first traversal\n"<<std::endl; std::queue<node*> q; if (m_root) { // enque the root q.push (m_root); // repeat while the queue is not empty while (!q.empty ()) { // dequeue the first node node* n = q.front (); q.pop (); // report the node n->print (); // enqueue left and right nodes if (n->left) q.push (n->left); if (n->right) q.push (n->right); } std::cout<<std::endl; } else std::cout<<"The tree is empty!\n"<<std::endl; } void print_depth_first () { std::cout<<"Depth-first traversal\n"<<std::endl; std::stack<node*> s; if (m_root) { // stack the root s.push (m_root); // repeat while the stack is not empty while (!s.empty()) { // unstack the top node node* n = s.top (); s.pop (); // report the node n->print (); // stack left and right nodes if (n->right) s.push (n->right); if (n->left) s.push (n->left); } std::cout<<std::endl; } else std::cout<<"The tree is empty!\n"<<std::endl; } }; // initialise static data unsigned tree::node::s_id = 0; int main() { srand((unsigned) time(NULL)); // create tree with 10 random numbers tree t; for(unsigned i=0; i<10; ++i) t.insert (rand ()); t.print_sorted (); t.print_breadth_first (); t.print_depth_first (); } Example output: Sorted-order traversal ID: 6 Depth: 2 Data: 334 ID: 4 Depth: 1 Data: 2335 ID: 0 Depth: 0 Data: 12490 ID: 5 Depth: 4 Data: 15590 ID: 9 Depth: 5 Data: 18484 ID: 3 Depth: 3 Data: 23160 ID: 2 Depth: 2 Data: 23786 ID: 8 Depth: 3 Data: 24171 ID: 1 Depth: 1 Data: 24598 ID: 7 Depth: 2 Data: 30731 Breadth-first traversal ID: 0 Depth: 0 Data: 12490 ID: 4 Depth: 1 Data: 2335 ID: 1 Depth: 1 Data: 24598 ID: 6 Depth: 2 Data: 334 ID: 2 Depth: 2 Data: 23786 ID: 7 Depth: 2 Data: 30731 ID: 3 Depth: 3 Data: 23160 ID: 8 Depth: 3 Data: 24171 ID: 5 Depth: 4 Data: 15590 ID: 9 Depth: 5 Data: 18484 Depth-first traversal ID: 0 Depth: 0 Data: 12490 ID: 4 Depth: 1 Data: 2335 ID: 6 Depth: 2 Data: 334 ID: 1 Depth: 1 Data: 24598 ID: 2 Depth: 2 Data: 23786 ID: 3 Depth: 3 Data: 23160 ID: 5 Depth: 4 Data: 15590 ID: 9 Depth: 5 Data: 18484 ID: 8 Depth: 3 Data: 24171 ID: 7 Depth: 2 Data: 30731 Each node reports its ID, depth and data. The ID tells us the sequence the nodes were created, where the node with ID 0 is always the root. The depth tells us the level within the tree where the node exists, such that the root is on level 0. With this information it is possible to draw a graph of the tree and thus better understand the order in which nodes are processed. The first listing shows the nodes in ascending order by data. With binary search trees this is the normal method of traversal. The second listing shows a breadth-first traversal, where each level is processed in turn, from left to right. The final listing shows a depth-first traversal where we follow left nodes before right nodes. You will notice that the implementation of breadth-first and depth-first are fairly similar, the only real difference being that breadth-first employs a queue while depth-first employs a stack. The nature of a stack also means we must push right nodes before left nodes to ensure left nodes are processed before right nodes. At first glance there doesn't appear to be much merit in either breadth-first or depth-first traversal. However, the example merely serves to show the difference between all the methods of traversal. When considering more complex graphs or maps, it may be advantageous to search through all the vertices that form an edge with a particular vertex (breadth-first) or to examine all the edges between one vertex and another vertex, where several routes might be available (depth-first). Both depth-first and breadth-first have practical applications in network routing and satellite navigation, where maps and charts must be graphed and traversed in a more logical manner than would otherwise be possible with sorted-order traversal.


What is a gateway ID?

A gateway is a node (a router) on a TCP/IP Network that serves as an access point to another network.A default gateway is the node on the computer network that is chosen when the IP address does not match any other routes in the routing table.


Write an iterative function to search an element in a binary search tree?

_node* search (_node* head, _key key) { _node* node; for (node=head; node != NULL;;) { if (key == node->key) return node; else if (key < node.>key) node = node->left; else node = node->right; } return node; }


How to Print data of all nodes of linked list?

for (node=head; node!=null; node=node->next) printnode(node);


How to find the mirror image of a binary tree?

Refer to http://cslibrary.stanford.edu/110/BinaryTrees.html void mirror(struct node* node) { if (node==NULL) { return; } else { struct node* temp; // do the subtrees mirror(node->left); mirror(node->right); // swap the pointers in this node temp = node->left; node->left = node->right; node->right = temp; } }


Can we use doubly linked list as a circular linked list?

Yes. The tail node's next node is the head node, while the head node's previous node is the tail node.


Algoritm for deleting the last element from a list?

Given a list and a node to delete, use the following algorithm: // Are we deleting the head node? if (node == list.head) { // Yes -- assign its next node as the new head list.head = node.next } else // The node is not the head node { // Point to the head node prev = list.head // Traverse the list to locate the node that comes immediately before the one we want to delete while (prev.next != node) { prev = prev.next; } end while // Assign the node's next node to the previous node's next node prev.next = node.next; } end if // Before deleting the node, reset its next node node.next = null; // Now delete the node. delete node;


Is null node equal to leaf node?

No. A leaf node is a node that has no child nodes. A null node is a node pointer that points to the null address (address zero). Since a leaf node has no children, its child nodes are null nodes.


What is an intrathoracic node?

An intrathoracic node is a node within the chest cavity.


How many pointers will have to be changed if a node is deleted from a linear linked list?

For a singly-linked list, only one pointer must be changed. If the node about to be deleted (let's call it node for the sake of argument) is the head of the list, then the head node pointer must be changed to node->next. Otherwise, the node that comes before the deleted node must change its next pointer to node->next. Note that given a singly-linked node has no knowledge of its previous node, we must traverse the list from the head in order to locate that particular node, unless the node is the head of the list: void remove (List* list, Node* node) { if (!list !node) return; // sanity check!if (list->head == node) {list->head = node->next;} else {Node* prev = list->head;while (prev->next != node) prev = prev->next; // locate the node's previous nodeprev->next = node->next;}} Note that the remove function only removes the node from the list, it does not delete it. This allows us to restore the node to its original position, because the node itself was never modified (and thus still refers to its next node in the list). So long as we restore all removed nodes in the reverse order they were removed, we can easily restore the list. In order to delete a node completely, we simply remove it and then free it:void delete (List* list, Node* node) {if (!list !node) return; // sanity check!remove (list, node);free (node);} For a doubly-linked list, either two or four pointers must be changed. If the node about to be deleted is the head node, then the head node pointer must be changed to n->next and n->next->prev must be changed to NULL, otherwise, n->prev->next becomes n->next. In addition, if the node about to be deleted is the tail node, then the tail node pointer must be changed to n->prev and n->prev->next must be changed to NULL, otherwise, n->next->prev becomes n->prev. Deletion from a doubly-linked list is generally quicker than deletion from a singly linked list because a node in a doubly-linked list knows both its previous node and its next node, so there's no need to traverse the list to locate the previous node to the one being deleted. void remove (List* list, Node* node) {if (!list !node) return; // sanity check!if (list->head == node) {list->head = node->next;node->next->prev = NULL;} else {node->prev->next = node->next; }if (list->tail == node) {list->tail = node->prev;node->prev->next = NULL;} else {node->next->prev = node->prev; }} Again, to physically delete the node we simply remove and then free the node:void delete (List* list, Node* node) {if (!list !node) return; // sanity check!remove (list, node); free (node); }


What is Cardiopulmonary node?

cardiopulmonary node