Functional Programming and Data Structures Review

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/23

flashcard set

Earn XP

Description and Tags

Vocabulary flashcards covering Haskell functional programming, algebraic data types, tail recursion, runtime complexities, fold functions, and tree operations in C and Haskell.

Last updated 7:11 AM on 10/11/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

24 Terms

1
New cards

Worst-case runtime for Access (Arrays vs. Lists)

o(1)o(1) for arrays and o(n)o(n) for lists.

2
New cards

Worst-case runtime for Insert/Delete (Arrays vs. Lists)

o(n)o(n) for arrays and o(1)o(1) for lists.

3
New cards

Accumulating parameter

A programming technique used to transform a standard recursive function definition into an equivalent tail recursive definition.

4
New cards

Pattern matching

A Haskell mechanism demonstrated in function definitions over lists, such as Product [] = 1 and Product (x:xs) = x * product xs.

5
New cards

Haskell Fold evaluations

Results of fold expressions: Foldr (+) 0 (1, 2, 3) = 6, Foldr (-) 0 (1, 2, 3) = 2, Foldl (-) 0 (1, 2, 3) = -6, Foldr (+) 5 [1, 2, 3] = 11, and Foldl (-) 5 [1, 2, 3] = -1.

6
New cards

List concatenation operator (++)

A Haskell function with type (++) :: [a] -> [a] -> [a], defined by (++) [] ys = ys and (++) (x:xs) ys = x : (xs ++ ys).

7
New cards

Foldr (++) []

A Haskell expression that flattens a list of lists into a single list.

8
New cards

Syntactic sugar for lists in Haskell

The notation [1, 2, 3], which desugars to 1:2:3:[] and is equivalent to 1:(2:(3:[])).

9
New cards

Foldl vs. Foldr (Tail Recursiveness)

Foldl is tail recursive, whereas foldr is not tail recursive.

10
New cards

Type of foldr

Foldr :: (a -> b -> b) -> b -> [a] -> b

11
New cards

Type of foldl

Foldl :: (b -> a -> b) -> b -> [a] -> b

12
New cards

Product algebraic data type

A category of algebraic data types that pairs components, exemplified by pairs (a, b), tuples, and records.

13
New cards

Projections

Functions that extract elements from a product type, specifically fst (x, ) = x and snd (, y) = y.

14
New cards

Sum / Co-product algebraic data type

An algebraic data type representing disjoint alternatives, exemplified by enumerated types, tagged unions, and definitions like data Shape = circle float | rectangle float float.

15
New cards

Recursive data type

A data type that refers to itself in its definition, such as data Tree a = Node a (Tree a) (Tree a) | Tip.

16
New cards

Maybe data type evaluations

Evaluations over the type data maybe = nothing | just a: sum Nothing = 0, product (Just 2) = 2, length (Just "abc") = 1, and length Nothing = 0.

17
New cards

Functional programming paradigm snippets

Snippets characterized by immutable values and pure returns, such as Const int x = 5; and Int f(int x) { return 2*x+1; }.

18
New cards

Imperative programming paradigm snippets

Snippets characterized by mutable state and explicit mutation, such as x += 5; and Void swap (int *a, int *b) { Int h = *a; *a = *b; *b = h; }.

19
New cards

Quicksort element comparison counts

A call to standard filter-based qsort compares each element twice, whereas qsort implemented with sortp compares each element once.

20
New cards

Tail recursiveness of qsort vs. sortp

sortp is tail recursive, but qsort is not tail recursive.

21
New cards

Merge function

A Haskell list function defined as Merge [] ys = ys, Merge xs [] = xs, and Merge (x:xs) (y:ys) = if x <= y then x : merge xs (y:ys) else y : merge (x:xs) ys.

22
New cards

Linked list printList function (C)

A C traversal that iterates through nodes via current = current->next until NULL, producing the output 1, 2, 3 for chained nodes n3 -> n2 -> n1.

23
New cards

leaves (Haskell tree function)

A function on data Tree a = Tip | Branch (Tree a) a (Tree a) defined by leaves Tip = [], leaves (Branch Tip x Tip) = [x], and leaves (Branch l _ r) = leaves l ++ leaves r.

24
New cards

count_leaves (C tree function)

A C recursive function that returns 0 if p == NULL, 1 if both p->left == NULL and p->right == NULL, and count_leaves(p->left) + count_leaves(p->right) otherwise.