23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Write a recursive <strong>Java</strong> program that will output all the subsets of a set of n<br />

elements (without repeat<strong>in</strong>g any subsets).<br />

C-3.15<br />

Write a short recursive <strong>Java</strong> method that f<strong>in</strong>ds the m<strong>in</strong>imum <strong>and</strong> maximum<br />

values <strong>in</strong> an array of <strong>in</strong>t values without us<strong>in</strong>g any loops.<br />

C-3.16<br />

Describe a recursive algorithm that will check if an array A of <strong>in</strong>tegers conta<strong>in</strong>s<br />

an <strong>in</strong>teger A[i] that is the sum of two <strong>in</strong>tegers that appear earlier <strong>in</strong> A, that is,<br />

such that A[i] = A[j] +A[k] for j,k > i.<br />

C-3.17<br />

Write a short recursive <strong>Java</strong> method that will rearrange an array of <strong>in</strong>t values<br />

so that all the even values appear before all the odd values.<br />

C-3.18<br />

Write a short recursive <strong>Java</strong> method that takes a character str<strong>in</strong>g s <strong>and</strong> outputs<br />

its reverse. So for example, the reverse of "pots&pans" would be<br />

"snap&stop".<br />

C-3.19<br />

Write a short recursive <strong>Java</strong> method that determ<strong>in</strong>es if a str<strong>in</strong>g s is a pal<strong>in</strong>drome,<br />

that is, it is equal to its reverse. For example, "racecar" <strong>and</strong><br />

"gohangasalamiimalasagnahog" are pal<strong>in</strong>dromes.<br />

C-3.20<br />

Use recursion to write a <strong>Java</strong> method for determ<strong>in</strong><strong>in</strong>g if a str<strong>in</strong>g s has more<br />

vowels than consonants.<br />

C-3.21<br />

Suppose you are given two circularly l<strong>in</strong>ked lists, L <strong>and</strong> M, that is, two lists of<br />

nodes such that each node has a nonnull next node. Describe a fast algorithm for<br />

tell<strong>in</strong>g if L <strong>and</strong> M are really the same list of nodes, but with different (cursor)<br />

start<strong>in</strong>g po<strong>in</strong>ts.<br />

C-3.22<br />

Given a circularly l<strong>in</strong>ked list L conta<strong>in</strong><strong>in</strong>g an even number of nodes, describe<br />

how to split L <strong>in</strong>to two circularly l<strong>in</strong>ked lists of half the size.<br />

209

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

Saved successfully!

Ooh no, something went wrong!