CS 272 Chapter 4 Quiz

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Identify the statement that is true of the linked list traversal. A) A doubly-linked list does not support list traversal. b) A doubly linked list's reverse traversal starts with the list's tail node. c) A singly-linked list supports reverse traversal. d) A list traversal algorithm starts with the list's next node

.A doubly linked list's reverse traversal starts with the list's tail node

Given the doubly-linked list { 40, 42, 45, 46, 47 }, identify the commands for the following operations. 1. Remove 45 2. Confirm that 45 is removed A) Remove(list, 45) Search(list, 45) B) Remove(list, 45) IsEmpty(list, 45) C) Remove(list, 45) Sort(list, 45) D) Delete(list, 45) Search(list, 45)

A) Remove(list, 45) Search(list, 45)

In the ListInsertAfter function for singly-linked lists, the curNode parameter points to _____ node. A) an existing node B) the middle node C) the head D) the tail

A) an existing node

In the ListInsertAfter function for singly-linked lists, the curNode parameter is ignored when ______. A) the newNode argument is also null B) the list has more than 2 items C) the list's head pointer is null D) the list's head and tail pointers point to different node

C) The list's head pointer is null

For an empty, singly-linked list with one dummy node, the list's _____. A) head and tail point to different nodes B) tail is null C) head and tail point to the same node D) head is null

C) head and tail point to the same node

This question refers to the Java implementation of SinglyLinkedList from the Chapter 4 PowerPoint presentation. Which code segment will fill in XXX so that the method will insert a new node into a singly-linked list? public void insertAfter( IntNode curNode, IntNode newNode) { if (head == null) { head = newNode; tail = newNode; } else if (curNode == tail) { tail.setNext(newNode); tail = newNode; } else { XXX } } A) newNode.setNext(curNode.getNext()); curNode.setNext(newNode); B) newNode.setNext(null); curNode.setNext(tail.getNext()); C) newNode.getNext( ) = curNode.getNext( ); curNode.setNext(null); D) newNode.setNext(curNode.getNext()); curNode = newNode;

A) newNode.setNext(curNode.getNext()); curNode.setNext(newNode);

Given the doubly-linked list { 75, 76, 68 }, identify the commands for the following operations. 1. Insert item 80 at the end of the list 2. Remove item 68 3. Insert item 82 at the beginning of the list A) Append(list, 80) Append(list, 82) Remove(list, 68) B) Append(list, 80) Remove(list, 68) Prepend(list, 82) C) Append(list, 80) Append(list, 82) Remove(list, 68) D) Append(list, 80, 82) Remove(list, 68)

B) Append(list, 80) Remove(list, 68) Prepend(list, 82)

Given the singly-linked list {18, 20, 27 28, 30}, which is the first node searched by ListSearch(list, 27)? A) Node 20 B) Node 18 C) Node 27 D) Node 28

B) Node 18

Which is NOT true of a circular linked list? A) The head pointer is null. B) The tail's next pointer is null. C) The head's prev pointer points to the tail of the list. D) The tail's next pointer points to the head of the list

B) The tail's next pointer is null.

In a doubly-linked list with 2 dummy nodes, the list's _____. A) head pointer may be null B) head and tail pointer may point to the same node C) head node's next pointer may point to the list's tail node D) tail pointer may be null

C) head node's next pointer may point to the list's tail node

Identify the correct way to add 10 to the start of the singly-linked list: {11, 12, 13, 14} A) ListAppend(list, 10) B) ListAppend (list, 0, 10) C) ListInsertBefore(list, 10) D) ListPrepend(list, 10)

D) ListPrepend(list, 10)

Identify the error in the following algorithm for traversing a linked list. ListTraverse(list) { curNode = list⇢head while (curNode is not null) { Print curNode's data curNode = list⇢head⇢next } } A) The statement curNode = list⇢head should be curNode = list⇢tail. B) The statement while (curNode is not null) should be while (list⇢tail is not null). C) The statement while (curNode is not null) should be while (curNode is null). D) The statement curNode = list⇢head⇢next should be curNode = curNode⇢next.

D) The statement curNode = list⇢head⇢next should be curNode = curNode⇢next.

The head of the circular linked list is often called the _____ node. A) circular B) first C) tail D) start

D) start

Which representation is correct for a doubly linked list with 2 nodes?(see back for diagrams) Diagram A Diagram B Diagram C Diagram D

Diagram B

Given a doubly-linked list {2, 3, 4, 5, 6, 7} node2's _________ is null. a. prev b. head c. next d. data

a. prev

Which of the following is an example of a linked list traversal operation? a) Removing a node from the middle of the list b) Printing the list c) Appending a node at the end of the list d) Inserting a node at the beginning of the list

b) Printing the list

Given the singly-linked list {80, 81, 82, 83} what is returned from ListSearch(list, 84)? A) null B) false C) Node 80 D) true

null

This question refers to the Java implementation of SinglyLinkedList from the Chapter 4 powerpoint presentation. Which code segment will fill in XXX so that the method will remove a node from the singly linked list? public void removeAfter(IntNode curNode) { IntNode sucNode; if (curNode == null && head != null) { sucNode = head.getNext(); head = sucNode; if (sucNode == null) { XXX } } else if (curNode.getNext( ) != null) { sucNode = curNode.getNext().getNext(); curNode.setNext(sucNode); if (sucNode == null) { tail = curNode; } } } A) tail = null; B) head = sucNode; C) sucNode = head.getNext( ); D) tail = curNode;

A) tail = null;

ListTraverseReverse must traverse a doubly-linked list in reverse order. ListTraverseReverse(list) { XXX } ListTraverseReverseRecursive(node) { if (node is not null) { Visit node ListTraverseRecursive(node⇢prev) } } Which statement will fill in XXX ? A) ListTraverseReverseRecursive(list⇢head) B) ListTraverseReverseRecursive(list⇢head⇢next) C) ListTraverseReverseRecursive(list⇢tail) D) ListTraverseReverseRecursive(list)

C) ListTraverseReverseRecursive(list⇢tail)


Set pelajaran terkait

End of Chapter Questions (CH 8,9,10,12)

View Set

Joey's handy dandy econ final study guide part 5, Ch. 20-21

View Set

OAE 015 - Educational Leadership

View Set

Indoor Environmental Quality (IEQ)

View Set

Homeostasis & Endocrine - Week 5

View Set