Docsity

Recursion and Lists: Understanding the Basics, Slides of Data Structures and Algorithms

Partial preview of the text

Download Recursion and Lists: Understanding the Basics and more Slides Data Structures and Algorithms in PDF only on Docsity!

7/8/

1

Recursion

ctd

Lists and Recursion

7/8/

7/8/

4

List Operations

•^

Prepend^ – prepend(a,L) = {a} if L=

Ф

  • prepend(a,L) = {a, prepend(first(L), tail(L))} -^

Append recursively^ – Append(L, a) = {a} if L=

Ф

  • Append(L, a) = prepend(first(L),Append(tail(L), a))

7/8/

5

Length of a list recursively

•^

Length(L) = 0 if L =

Ф

•^

Otherwise^ – Length(L) = 1 + length(tail(L))