11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

140 Chap. 4 Lists, Stacks, <strong>and</strong> Queues(a) Modify the code of Figure 4.8 to implement circular singly linked lists.(b) Modify the code of Figure 4.15 to implement circular doubly linkedlists.4.9 Section 4.1.3 st<strong>at</strong>es “the space required by the array-based list implement<strong>at</strong>ionis Ω(n), but can be gre<strong>at</strong>er.” Explain why this is so.4.10 Section 4.1.3 presents an equ<strong>at</strong>ion for determining the break-even point forthe space requirements of two implement<strong>at</strong>ions of lists. The variables are D,E, P , <strong>and</strong> n. Wh<strong>at</strong> are the dimensional units for each variable? Show th<strong>at</strong>both sides of the equ<strong>at</strong>ion balance in terms of their dimensional units.4.11 Use the space equ<strong>at</strong>ion of Section 4.1.3 to determine the break-even point foran array-based list <strong>and</strong> linked list implement<strong>at</strong>ion for lists when the sizes forthe d<strong>at</strong>a field, a pointer, <strong>and</strong> the array-based list’s array are as specified. St<strong>at</strong>ewhen the linked list needs less space than the array.(a) The d<strong>at</strong>a field is eight bytes, a pointer is four bytes, <strong>and</strong> the array holdstwenty elements.(b) The d<strong>at</strong>a field is two bytes, a pointer is four bytes, <strong>and</strong> the array holdsthirty elements.(c) The d<strong>at</strong>a field is one byte, a pointer is four bytes, <strong>and</strong> the array holdsthirty elements.(d) The d<strong>at</strong>a field is 32 bytes, a pointer is four bytes, <strong>and</strong> the array holdsforty elements.4.12 Determine the size of an int variable, a double variable, <strong>and</strong> a pointer onyour computer.(a) Calcul<strong>at</strong>e the break-even point, as a function of n, beyond which thearray-based list is more space efficient than the linked list for listswhose elements are of type int.(b) Calcul<strong>at</strong>e the break-even point, as a function of n, beyond which thearray-based list is more space efficient than the linked list for listswhose elements are of type double.4.13 Modify the code of Figure 4.19 to implement two stacks sharing the samearray, as shown in Figure 4.21.4.14 Modify the array-based queue definition of Figure 4.27 to use a separ<strong>at</strong>eBoolean member to keep track of whether the queue is empty, r<strong>at</strong>her thanrequire th<strong>at</strong> one array position remain empty.4.15 A palindrome is a string th<strong>at</strong> reads the same forwards as backwards. Usingonly a fixed number of stacks <strong>and</strong> queues, the stack <strong>and</strong> queue ADT functions,<strong>and</strong> a fixed number of int <strong>and</strong> char variables, write an algorithm todetermine if a string is a palindrome. Assume th<strong>at</strong> the string is read fromst<strong>and</strong>ard input one character <strong>at</strong> a time. The algorithm should output true orfalse as appropri<strong>at</strong>e.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!