R
R
R-7.2 Describe a good algorithm for concatenating two singly linked lists L and
M, given only references to the first node of each list, into a single list L ?
R-7.3 Describe a recursive algorithm that counts the number of nodes in a singly
linked list.
R-7.4 Describe in detail how to swap two nodes x and y (and not just their con-
this exercise for the case when L is a doubly linked list. Which algorithm
C-7.24 Give a complete implementation of the stack ADT using a singly linked
C-7.25 Give a complete implementation of the queue ADT using a singly linked
takes all elements of LinkedQueue Q2 and appends them to the end of the
original queue. The operation should run in O(1) time and should result
C-7.27 Give a recursive implementation of a singly linked list class, such that an
instance of a nonempty list stores its first element and a reference to a list
of remaining elements.
C-7.28 Describe a fast recursive algorithm for reversing a singly linked list.
C-7.29 Describe in detail an algorithm for reversing a singly linked list L using
only a constant amount of additional space and not using any recursion.
Reinforcement
R-4.1 Describe a recursive algorithm for finding the maximum element in a se-
R-4.2 Draw the recursion trace for the computation of power(2,5), using the
R-4.3 Draw the recursion trace for the computation of power(2,18), using the
R-4.4 Draw the recursion trace for the execution of function reverse(S, 0, 5)
Hn
=∑
i=1 1/i.
R-4.7 Describe a recursive function for converting a string of digits into the in-
n integers, where nis a power of two. She creates a new sequence B of half
Creativity
C-4.9 Write a short recursive Python function that finds the minimum and max-
C-4.10 Describe a recursive algorithm to compute the integer part of the base-two
C-4.11 Describe an efficient recursive function for solving the element unique-
ness problem, which runs in time that is at most O(n 2 ) in the worst case
C-4.13 In Section 4.2 we prove by induction that the number of lines printed by
many dashes are printed during that process. Prove by induction that the
C-4.14 In the Towers of Hanoi puzzle, we are given a platform with three pegs, a,
b, and c, sticking out of it. On peg a is a stack of n disks, each larger than
the next, so that the smallest is on the top and the largest is on the bottom.
The puzzle is to move all the disks from peg a to peg c, moving one disk
algorithm for solving the Towers of Hanoi puzzle for arbitrary n. (Hint:
Consider first the subproblem of moving all but the n th disk from peg a to
C-4.16 Write a short recursive Python function that takes a character string s and
snap&stop .
palindrome, that is, it is equal to its reverse. For example, racecar and
C-4.18 Use recursion to write a Python function for determining if a string s has
C-4.19 Write a short recursive Python function that rearranges a sequence of in-
teger values so that all the even values appear before all the odd values.
less than or equal to k come before any elements larger than k. What is
C-4.21 Suppose you are given an n-element sequence, S, containing distinct in-