Question

11.) Suppose you have a linked list of Node objects from the Textbook Collections Framework and...

11.)

Suppose you have a linked list of Node objects from the Textbook Collections Framework and currentNode has been initialized to refer to the head node in the list. Which of these statements needs to appear in a loop that goes through the list's items one-by-one?

Select one:

a. currentNode++

b. currentNode = currentNode.next

c. currentNode = previous()

d. currentNode += 1

e. currentNode = next()

12.) A singly linked node contains which of these fields?

Select one:

a. data item, link to next node, and link to previous node

b. link to next node only

c. an empty link

d. data item only

e. data item and link to next node

13.) Which of these describes how an item in a linked data structure is accessed?

Select one:

a. immediately accessed via a base address and offset

b. accessed by starting at one end and following the links until the item is reached

c. immediately accessed via an index

d. accessed by hashing its value

e. accessed via a binary search

15.) Which of these is done to insert an item into an array that grows?

Select one:

a. all of these

b. shift the items from the target index position to the logical end of the array one slot towards the physical end of the array

c. increment the logical size of the array by 1

d. assign the new item to the target index position

e. check for available space before attempting an insertion and increase the physical size of the array if necessary

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Linked List questions

Introduction for better understanding:

Linked List is a linear data structure where its elements are linked using pointers.

Each record of a linked list is known as an element/node.
Each node in a list has at least two parts:

1) data/value/cargo/payload etc.
2) Pointer/link/reference to the next node

Linked list is represented using a pointer to the first node of the list (called the head of the list). Whereas, the remaining part of the list after the head or the last node is called “tail”.


In C, we represent a node using structures. In Java or C#, we represent LinkedList Node as separate classes.

class LinkedList

{

Node head; // head of the list

  

        class Node {

        int data;

        Node next;

  

        // create a new node

Node (int d)

{

data = d;

}

}

}

Question number 11 in the given set of questions:

11) Suppose you have a linked list of Node objects from the Textbook Collections Framework and currentNode has been initialized to refer to the head node in the list. Which of these statements needs to appear in a loop that goes through the list's items one-by-one?

Select one:

a. currentNode++

b. currentNode = currentNode.next

c. currentNode = previous()

d. currentNode += 1

e. currentNode = next()

Solution:

Option b is the correct answer.

Explanation:

To search in element in a Linked list or to print the elements in the list, we do traversing from one-by-one in the list starting from head node to remaining nodes. This can be achieved by assigning current node in the list to next link reference(starting from head).

As given in the question, Current node is initialized to the head. We can proceed further through list using “currentNode = currentNode.next “assignment statement in a loop.

Other Options are wrong because:

a) currentNode++ --only for incrementing current node by 1. It does not allow you to traverse through the list

c) currentNode = previous()—This is not how we traverse through the list in a loop. It is syntactically wrong.

d) currentNode += 1-- only for incrementing current node by 1. It does not allow you to traverse through the list

e) currentNode = next()--This is not how we traverse through the list in a loop. It is syntactically incorrect.

Question number 12 in the given set of questions:

12) A singly linked node contains which of these fields?

Select one:

a. data item, link to next node, and link to previous node

b. link to next node only

c. an empty link

d. data item only

e. data item and link to next node

Solution:

Option e is the correct answer.

Explanation:

Singly linked list contains elements or nodes which have a data items as well as next pointer, which links to the next node in list of nodes of a linked list.

Other Options are wrong because:

As given in the introduction of a linked list, remaining options are not applicable for the question.

Question number 13 in the given set of questions:

13) Which of these describes how an item in a linked data structure is accessed?

Select one:

a. immediately accessed via a base address and offset

b. accessed by starting at one end and following the links until the item is reached

c. immediately accessed via an index

d. accessed by hashing its value

e. accessed via a binary search

Solution:

Option b is the correct answer.

Explanation:

Here, option b is the right answer, which is a major drawback of Linked list. In linked list, random access is not possible. An element can be accessed only by traversing sequentially starting from the first node (head).

Other Options are wrong because:

As memory allocation for the linked list is dynamic and non-contiguous it makes it difficult to find an element using other techniques such as binary search. So we cannot efficiently access an element using the specified techniques. Also they are not applicable.

Question number 13 in the given set of questions:

15) Which of these is done to insert an item into an array that grows?

Select one:

a. all of these

b. shift the items from the target index position to the logical end of the array one slot towards the physical end of the array

c. increment the logical size of the array by 1

d. assign the new item to the target index position

e. check for available space before attempting an insertion and increase the physical size of the array if necessary

Solution:

Option a is the correct answer.

Explanation:

A Dynamic array grows if we want to insert an item and there is no more space left for the new item.

So a simple dynamic array can be created with size larger than the number of elements required immediately. The elements of the dynamic array are stored contiguously at the start of the underlying array where remaining positions are reserved for future use or unused. Therefore, elements can be added at the end of a dynamic array by using these unused positions, until they are consumed.

But, when all positions are consumed, and if we want to add one more element, the underlying array size is increased.

Also, If we want to insert an item element to the array, you can use any of the approaches given below.

  • Using a new array larger than the original.
  • Using ArrayList as an intermediate structure.
  • Shifting the elements to accommodate the new element.

For instance, If the array size is n, you can create a new array with size n+1 for future use, if we want to add one element. Then , copy the original array of n elements into the new array. Insert new item at n+1 location.

So, all the options are correct for this question. So answer is “all of these”

Add a comment
Know the answer?
Add Answer to:
11.) Suppose you have a linked list of Node objects from the Textbook Collections Framework and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part I: Create a doubly linked circular list class named LinkedItemList that implements the following interface:...

    Part I: Create a doubly linked circular list class named LinkedItemList that implements the following interface: /** * An ordered list of items. */ public interface ItemList<E> {      /**       * Append an item to the end of the list       *       * @param item – item to be appended       */ public void append(E item);      /**       * Insert an item at a specified index position       *       * @param item – item to be...

  • Given a singly-linked list interface and linked list node class, implement the singly-linked list which has...

    Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...

  • Problem Statement This problem provides you with a linked list composed of node objects chained together...

    Problem Statement This problem provides you with a linked list composed of node objects chained together via node pointers. Each node has a next pointer which points to the next node in the chain. The last node is identified by having a NULL (or nullptr) next pointer. The linked lists for this problem store string data. Your task: identify the longest string stored in the linked list. If two strings are of the same length, return the string that occurred...

  • Answer all questions 1- in circular singly linked list, previous pointer of the first node points...

    Answer all questions 1- in circular singly linked list, previous pointer of the first node points to which node A. First node B. Itself C. null D. Last node 2- Which of the following is NOT an applications of linked lists? A. Implementation of stacks and queues B. Dynamic memory allocation C. Manipulation of polynomials D. Keeping people at home during epidemics like corona virus 3- In a circular singly linked list? A. Components are all linked together in some...

  • Problem 3 (List Implementation) (35 points): Write a method in the DoublyLList class that deletes the...

    Problem 3 (List Implementation) (35 points): Write a method in the DoublyLList class that deletes the first item containing a given value from a doubly linked list. The header of the method is as follows: public boolean removeValue(T aValue) where T is the general type of the objects in the list and the methods returns true if such an item is found and deleted. Include testing of the method in a main method of the DoublyLList class. ------------------------------------------------------------------------------------- /** A...

  • 1. Create a class MLL, a singly linked, non-circular list where each node only has one...

    1. Create a class MLL, a singly linked, non-circular list where each node only has one link next and the list has a head and a tail link (think about implementation of node). The MLL class also implements the Iterable interface. The following should be implemented as well: 2. Add the methods to the MLL class: a. iterator() to implement the Iterable interface. This method returns an instance of MLLI initialized appropriately. b. addFirst( value) that adds a value to...

  • C programming A linked list is a linear data structure that allows us to add and remove items fro...

    c programming A linked list is a linear data structure that allows us to add and remove items from the list very quickly, by simply changing a few pointers. There are many different variations of linked lists. We have studied the doubly-linked, circular, with a dummy-header-node version of a linked list. In the class notes we studied several functions to manipulate a Linked List. For this assignment you must write the code for the following additional linked list functions: addFirst,...

  • I need help implemeting the remove_repetitions() Here is a brief outline of an algorithm: A node...

    I need help implemeting the remove_repetitions() Here is a brief outline of an algorithm: A node pointer p steps through the bag For each Item, define a new pointer q equal to p While the q is not the last Item in the bag If the next Item has data equal to the data in p, remove the next Item Otherwise move q to the next Item in the bag. I also need help creating a test program _____________________________________________________________________________________________________________________________________________________ #ifndef...

  • You are given a binary tree of the form: Each node in the tree has a...

    You are given a binary tree of the form: Each node in the tree has a left child and a right child. Each of the children will be extended as a linked list. Every node has the following attributes: key, left node, right node, and next node. The next node allows a node, that is a part of the tree, to be extended as a linked list. The diamonds represent the next nodes, which are part of the linked list...

  • class Node(object): def __init__(self, data, next=None): self.data = data self.next = next class List(object):    def...

    class Node(object): def __init__(self, data, next=None): self.data = data self.next = next class List(object):    def __init__(self): self.head = None self.tail = None Implement the following functions for Linked List in Python and use the constructors above : Copy(lList) Builds and returns a copy of list ItemAt(List,i) Returns the data item at position i in list Pop(List,i=0) Remove item at position i in list. If i is not specified, it removes the first item in list Count(List,x) Returns the number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT