Question

C++ questions QUESTION 1 What kind of linked list begins with a pointer to the first...

C++ questions

QUESTION 1

What kind of linked list begins with a pointer to the first node, and each node contains a pointer to the next node, and the pointer in the last node points back to the first node?

A.

Circular, singly-linked list.

B.

Circular, doubly-linked list.

C.

Singly-linked list.

D.

Doubly-linked list.

E.

None of the above.

  

QUESTION 2

_________ is not an advantage of linked lists when compared to arrays.

A.

Dynamic memory allocation.

B.

Efficient insertion and deletion.

C.

Direct access to any list element.

D.

No need to allocate extra space, just in case.

E.

None of the above.

  

QUESTION 3

When a new node is inserted to the head of a linked list, will the head pointer and the tail pointer be changed?

A.

If the list is empty before the insertion, both head and tail will change.

B.

If the list is not empty before the insertion, head will change.

C.

Head will always change, but tail will never change.

D.

Both head and tail will change.

E.

None of the above.

QUESTION 4

In general, linked lists allow:

A.

Insertions and removals anywhere.

B.

Insertions and removals only at one end.

C.

Insertions at the back and removals from the front.

D.

None of the above.

QUESTION 5

Suppose list1 is a vector and list2 is a LinkedList. Both contain 1 million double values. Analyze the following code:

for (int i = 0; i < list1.size(); i++)

sum += list1[i];

for (int i = 0; i < list2.getSize(); i++)

sum += list2.get(i);

A.

Code fragment A is more efficient than code fragment B.

B.

Code fragment B is more efficient than code fragment A.

C.

Code fragment A is as efficient as code fragment B.

D.

None of the above.

Homework Answers

Answer #1

Question 1:-

linked list that begins with a pointer to the first node, and each node contains a pointer to the next node, and the pointer in the last node points back to the first node is circular,singly-linked list because each an every node is pointed by one pointer which makes it singly linked list and the last node points to the first node which makes it circular linked list.(option A)

Question 2:-

Direct access to any list element,is not an advantage of linked lists when compared to arrays,because we have to access elements sequentially starting from the first node(option C)

Question 3:-

When a new node is inserted to the head of a linked list,Head will always change, but tail will never change because tail pointer always points to null incase of singly-linked list(option C)

Question 4:-

In general, linked lists allow Insertions and removals anywhere,because there is no need to allocate extra space in linked lists.(option A)

Question 5:-

Suppose list1 is a vector and list2 is a LinkedList. Both contain 1 million double values. Analyze the following code:

code fragment A:-

for (int i = 0; i < list1.size(); i++)

sum += list1[i];

code fragment B:-

for (int i = 0; i< list2.getSize(); i++)

sum += list2.get(i);

Code fragment A is more efficient than code fragment B because extra space is required for the pointers for each node in linked list and Indexing into a linked list is slow because you have to traverse the list to get to the given index, while a vector is contiguous in memory and you can get there using pointer and to find the sum we have to traverse all the elements in vector as well as linked list(option A)

Know the answer?
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
Similar Questions
def array_to_list(data): ''' Converts an array to linked list with the same order as in array...
def array_to_list(data): ''' Converts an array to linked list with the same order as in array returns None if array is empty ''' head = None # for each value in array for val in data: # if list is empty then create a new head node if head is None: head = list_node.ListNode(val) temp = head # else create a new node and add it to the list else: temp.next = list_node.ListNode(val) temp = temp.next return head def pair(list1,...
public class DoublyLinkedList { Node Head; // head of Doubly Linked List //Doubly Linked list Node...
public class DoublyLinkedList { Node Head; // head of Doubly Linked List //Doubly Linked list Node class Node { int value; Node prev; Node next; // Constructor to create a new node Node(int d) { value = d; } } // Inserting a node at the front of the list public void add(int newData) { // allocate node and put in the data Node newNode = new Node(newData); // Make the next of new node as head // and previous...
C++ Assumption and Terminology: Forward Linked List FLL has "head" Doubly Linked List DLL has "head"...
C++ Assumption and Terminology: Forward Linked List FLL has "head" Doubly Linked List DLL has "head" and "tail" Each node in FLL has "next" Each node in DLL has "next" and "prev" Q1: Complete the following constructor code for FLL FLL::FLL() { Q2: Complete the FLL insert-front code (which insert node new at the front of FLL) FLL::insert-front( node * new) { Q3: Complete the DLL insert-after code (which insert node new after node p) DLL::insert-after(node *p, node *new) {
C++ Goals  Build single linked lists using pointers  Learn how to manipulate linked lists...
C++ Goals  Build single linked lists using pointers  Learn how to manipulate linked lists In this lab, you will create simple single linked structures consisting of Node objects. Each node will have a pointer to the next node. You will use a head pointer to keep track of the first node in the linked list, and a tail pointer to keep track of the last node in the linked list. Set both head and tail to NULL when...
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
Q1; Write a method in class SLL called public SLL reverse() that produces a new linked...
Q1; Write a method in class SLL called public SLL reverse() that produces a new linked list with the contents of the original list reversed. Make sure not to use any methods like addToHead() or addToTail(). In addition, consider any special cases that might arise. What is the big-O complexity of your method in terms of the list size n Supplementary Exercise for Programming (Coding) [Singly Linked Lists] Download and unpack (unzip) the file SinglyLinkedList.rar. Compile and execute the class...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void search_node(struct linked_list* list, int find_node_ value) (The function to make) This function finds the node from the list that value is same with find_node_value and count the order of the node. This function should print message “The order of (node_value) is (order).” and error message “Function search_node : There is no such node to search.”....
In this code, I build a single-linked list using a node class that has been created....
In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
Write a C++ recursive function that counts the number of nodes in a singly linked list....
Write a C++ recursive function that counts the number of nodes in a singly linked list. (a) Test your function using different singly linked lists. Include your code. (b) Write a recurrence relation that represents your algorithm. (c) Solve the recurrence relation using the iterating or recursive tree method to obtain the running time of the algorithm in Big-O notation.
1. An array has an index of [5] at the starting address of 200. It has...
1. An array has an index of [5] at the starting address of 200. It has 3 words per memory cell, determine loc[3],loc[4] and NE. (3 Marks: 1 mark for each) 2. A 2-D array defined as A[10 , 5] requires 4 words of storage space for each element. Calculate the address of A[4,3] given the base address as 250 • If the array is stored in Row-major form • If the array is stored in Column-major form 3. Write...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT