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
  • 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...

  • 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...

  • 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...

  • Question: SWAPPING NODES IN A SINGULARLY LINKED LIST: I am attempting to create a program that...

    Question: SWAPPING NODES IN A SINGULARLY LINKED LIST: I am attempting to create a program that swaps 2 nodes (no matter where they are in the list) and am having some difficulty. I can't seem to figure out why this swap method is throwing an error. Code: (SWAPPING METHOD AND TEST LINE BOLDED) package linkedlists; public class SinglyLinkedList<E> implements Cloneable { //---------------- nested Node class ---------------- /** * Node of a singly linked list, which stores a reference to its...

  • 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...

  • Suppose you want to remove an item from a singly linked list at "index". Which of...

    Suppose you want to remove an item from a singly linked list at "index". Which of the following will NOT accomplish this? Group of answer choices 1. Node<E> before = getNode(index); Node<E> toRemove = before.next; toReturn = toRemove.item; before.next = toRemove.next; 2. Node<E> before = getNode(index - 1); toReturn = before.next.item; before.next = before.next.next; 3. Node<E> before = getNode(index - 1); Node<E> toRemove = before.next; toReturn = toRemove.item; before.next = toRemove.next;

  • 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,...

  • Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that...

    Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that holds ints instead of strings. In your main, insert 25 to 75 random integers with range (0 to 100) into a linked list of your nodes. Use a random to determine how many to make. Write a function int sum(NodePointer current) that returns the sum of the integers in the list by looping through the linked list. Write a function int count(NodePointer current) that...

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