• Home
  • Textbooks
  • Data Structures and Algorithms in C++
  • LINKED LISTS

Data Structures and Algorithms in C++

Adam Drozdek

Chapter 3

LINKED LISTS - all with Video Answers

Educators


Chapter Questions

02:29

Problem 1

Assume that a circular doubly linked list has been created, as in Figure 3.32. After each of the following assignments, indicate changes made in the list by showing which links have been modified. The second assignment should make changes in the list modified by the first assignment and so on.
$$
\begin{aligned}
& \text { list->next->next->next }= \text { list->prev; } \\
& 1 \text { ist->prev->prev->prev }= \text { list->next->next->next->prev; } \\
& 1 \text { ist->next->next->next->prev }=\text { list->prev->prev->prev; } \\
& 1 \text { ist->next }= \text { list->next->next; } \\
& 1 \text { ist->next->prev->next }= \text {list->next->next->next; }
\end{aligned}
$$

James Kiss
James Kiss
Numerade Educator
03:27

Problem 2

How many nodes does the shortest linked list have? The longest linked list?

Narayan Hari
Narayan Hari
Numerade Educator

Problem 3

The linked list in Figure 3.11 was created in Section 3.2 with three assignments. Create this list with only one assignment.

Check back soon!

Problem 4

Merge two ordered singly linked lists of integers into one ordered list.

Check back soon!

Problem 5

Delete an ith node on a linked list. Be sure that such a node exists.
FIGURE 3.30 (FIGURE CAN'T COPY)
FIGURE 3.31 (FIGURE CAN'T COPY)
FIGURE 3.31 (FIGURE CAN'T COPY)
FIGURE 3.31 (FIGURE CAN'T COPY)
FIGURE 3.31 (FIGURE CAN'T COPY)
FIGURE 3.31 (FIGURE CAN'T COPY)
FIGURE 3.31 (FIGURE CAN'T COPY)
FIGURE 3.31 (FIGURE CAN'T COPY)
FIGURE 3.32 (FIGURE CAN'T COPY)

Check back soon!
01:17

Problem 6

Delete from list $L_1$ nodes whose positions are to be found in an ordered list $L_2$. For instance, if $L_1=(\mathrm{ABCDE})$ and $L_2=(248)$, then the second and the fourth nodes are to be deleted from list $L_1$ (the eighth node does not exist), and after deletion, $L_1=$ (A C E).

James Kiss
James Kiss
Numerade Educator

Problem 7

Delete from list $L_1$ nodes occupying positions indicated in ordered lists $L_2$ and $L_3$. For instance, if $L_1=(\mathrm{A} \mathrm{BCDE}), L_2=(248)$, and $L_3=(25)$, then after deletion, $L_1$ $=(\mathrm{AC})$.

Check back soon!

Problem 8

Delete from an ordered list $L$ nodes occupying positions indicated in list $L$ itself. For instance, if $L=\left(\begin{array}{lll}1 & 3 & 578\end{array}\right)$, then after deletion, $L=(17)$.

Check back soon!

Problem 9

A linked list does not have to be implemented with pointers. Suggest other implementations of linked lists.

Check back soon!

Problem 10

Write a member function to check whether two singly linked lists have the same contents.

Check back soon!

Problem 11

Write a member function to reverse a singly linked list using only one pass through the list.

Check back soon!
01:18

Problem 12

Insert a new node into a singly linked list (a) before and (b) after a node pointed by $\mathrm{p}$ in this list (possibly the first or the last). Do not use a loop in either operation.

Vysakh M
Vysakh M
Numerade Educator

Problem 13

Attach a singly linked list to the end of another singly linked list.

Check back soon!
00:56

Problem 14

Put numbers in a singly linked list in ascending order. Use this operation to find the median in the list of numbers.

Zach Steedman
Zach Steedman
Numerade Educator

Problem 15

How can a singly linked list be implemented so that insertion requires no test for whether head is null?

Check back soon!

Problem 16

Insert a node in the middle of a doubly linked list.

Check back soon!

Problem 17

Write code for class IntCircularSLList for a circular singly linked list that includes equivalents of the member functions listed in Figure 3.2.

Check back soon!

Problem 18

Write code for class IntCircularDLList for a circular doubly linked list that includes equivalents of the member functions listed in Figure 3.2.

Check back soon!
02:10

Problem 19

How likely is the worst case for searching a skip list to occur?

AG
Ankit Gupta
Numerade Educator
01:32

Problem 20

Consider the move-to-front, transpose, count, and ordering methods.
(a) In what case is a list maintained by these methods not changed?
(b) In what case do these methods require an exhaustive search of lists for each search, assuming that only elements in the list are searched for?

James Chok
James Chok
Numerade Educator

Problem 21

In the discussion of self-organizing lists, only the number of comparisons was considered as the measure of different methods' efficiency. This measure can, however, be greatly affected by a particular implementation of the list. Discuss how the efficiency of the move-to-front, transpose, count, and ordering methods are affected in the case when the list is implemented as
(a) an array
(b) a singly linked list
(c) a doubly linked list

Check back soon!
02:29

Problem 22

For doubly linked lists, there are two variants of the move-to-front and transpose methods (Valiveti and Oommen 1993). A move-to-end method moves a node being accessed to the end opposite from which the search started. For instance, if the doubly linked list is a list of items $A B C D$ and the search starts from the left end to access node $C$, then the reorganized list is $A B D C$. If the search for $C$ started from the right end, the resulting list is $C A B D$.
The swapping technique transposes a node with this predecessor also with respect to the end from which the search started. Assuming that only elements of the list are in the data, what is the worst case for a move-to-end doubly linked list when the search is made alternately from the left and from the right? For a swapping list?

James Kiss
James Kiss
Numerade Educator
01:45

Problem 23

What is the maximum number of comparisons for optimal search for the 14 letters shown in Figure 3.19?

Florencia Cuzmar
Florencia Cuzmar
Numerade Educator
04:57

Problem 24

Adapt the binary search to linked lists. How efficient can this search be?

Bryan Lynn
Bryan Lynn
Numerade Educator