Unit 6 - Trees, Graphs, Recursive Types Flashcards

1
Q

In most cases, in custom types that allow values of arbitrary size, these values are some
kind of

A

trees or graphs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A tree is a

A

hierarchical structure with one root

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A graph is a (in this context)

A

a collection of arbitrary links among a set of nodes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In most PLs, graphs are more difficult to

A

represent and manipulate than trees

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Imperative languages let us treat recursive structures as

A

nodes with explicit links between
them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Abstract languages present the recursive structures as

A

symbolic expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Imperative PLs are characterised by

A
  • more flexibility in organising the structures, in particular they support structures
    with aliasing and cycles;
  • the danger of making hard-to-discover mistakes due to aliasing;
  • the ability to modify and evolve structures that had been built earlier;
  • the need to write much more code when creating and traversing trees;
  • less PL support for checking the correctness of the code.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The main ways in which Java differs from C in treating recursive structures are:

A
  • In Java there is no need to distinguish pointers to records (ie objects) from the re-
    cords themselves because all Java records (ie objects) are on the heap and can be
    referred to only by pointers.
  • There is no easy way to duplicate a whole record (ie object) in Java, whereas in C a
    whole record can be copied by an ordinary assignment to a variable of the record
    type.
  • In Java, new heap memory space is allocated and initialised with a correct record
    value in a single statement (ie a constructor call), whereas in C, space of the right
    size has to be first allocated by a special malloc call and then other statements
    initialise the value stored in that space.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The main differences between Lisp and Haskell in treating symbolic expressions are:

A
  • Constructors in Lisp symbolic expressions do not have to be declared and have
    no interesting intrinsic types, whereas in Haskell it is the opposite: Each record
    constructor symbol has to be explicitly declared and associated with a unique type.
  • Lisp trees can be modified using setf, but it has to be used with care to avoid
    dangerous effects, such as modifying the program code. Haskell symbolic trees
    cannot be modified, only re-created with some changes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly