progweek4 Flashcards

1
Q

A tree can be defined as :

A

a non-linear
data structure, in which the
information is ordered hierarchically
and interconnected.
It consists of a collection of nodes
(vertices) (storing the value(s))
connected by edges (connections)

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

Path:

A

a group of sequential edges; let p and c be two nodes such
that there is an edge from p to c. Then we say that p is a parent of
c and that c is one of the children of p.

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

Root:

A

the only node with no parent.

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

Leaf:

A

a node with no children.

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

Height (of a node):

A

number of edges between the root and the
farthest leaf. The height of a tree is the length of the longest path to
a leaf.

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

Depth:

A

the number of edges from a node to the root.

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

a tree we see daily:

A

Unix file system

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

we focus on: _ trees.

A

binary

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

Why are binary trees (BTs) so important?

A
  1. Efficient searching and sorting:

BTs allow for fast searching, insertions and deletion of items.

  1. Hierarchical data representation:

they are used to represent structures were hierarchical order is crucial. For example in file systems, HTML, etc.

3.Elegant algorithm design:

many algorithms are based or use BTs as part of their implementation.

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

Why and when are trees useful?

A

Computer Science:
Often used to give a hierarchical structure to data, e.g., file systems,

Modelling:
Hierarchical clustering of data (Statistics! Machine Learning!)

Linguistics:
To represent the syntactic structure of sentences in a language

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

full BT:

A

Every node has either
0 or two children.

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

perfect BT

A

All the nodes have
two children, and leafs
are at the same level.

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

complete BT

A

All the levels (expect
the last one) should
be full.

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

Degenerate BT

A

Every node has only one
child, either in the left or
right.

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

balanced BT

A

Heights of the left subtree
and right subtree defer by
zero or, at most, one.

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

In a binary search tree (BST), all the
elements from the nodes are ordered following a specific order.
The left node must be _ than
its parent node, and the value in the
right node must be _ than the
parent node.

A

smaller

greater

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

Some key operations on BSTs are:

A

Searching.
Insertion.
Deletion.
Traversal.

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

The idea of Object Oriented Programming is

A

that data is what should
guide software development and that the language should support data
abstraction.

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

Classes:

A

Provide a description of a type of object (essentially
improved ADTs).

20
Q

Objects:

A

Are instances of classes.

21
Q

Class attributes:

A

attributed shared by all instances of the class, e.g.,
the number of students currently in the system.

22
Q

Instance attributes:

A

attributes that are proper of the instances of
the class, e.g., the name and ID of a student.

23
Q

Class (static) Methods:

A

functionalities that belong to the class,
e.g., a method that prints the number of students currently in the
system

24
Q

Instance Methods:

A

functionalities that belong to the instance, e.g.,
a method that allows to change the name of a specific student.

25
Q

Constructor:

A

Is a method that allows to create an object of the class. Space is created and attributes initialized. Most OOP programming languages require that classes have a constructor.

26
Q

Destructor:

A

Is a method that destroys (frees) the object. In
particular it frees the memory allocated for the object.

27
Q

python’s Paradigm:

A

Object Oriented imperative

28
Q

python’s Type system:

A

Untyped (aka dynamically typed) this removes the
distinction between declaration and initialization, variables are
declared when they are initialized

29
Q

python’s Parameter passing:

A

Officially called “pass-by-assignment”, but it’s
essentially call-by-value. Objects are references (pointers) so can in principle be changed (see below Immutability).

30
Q

python’s Scoping:

A

the scoping rule is static (non-local names are searched where the function was declared). Blocks are as in C with the exception that body of if/while/for are not blocks (variable declared inside a while exist after). Moreover nested function declaration is allowed.

31
Q

Memory:

A

Managed by runtime support (object are deallocated
automatically). Still techniques can be used to make programs more efficient.

32
Q

Mutable type:

A

The operations can directly change the values of the type, e.g., when adding an element to the list you actually modify the list.

33
Q

Immutable type:

A

The operations cannot modify the values of the type and have to return a new structure with the correct value.

34
Q

immutable in python:

A

Integers
Float
Strings
Boolean
Tuples

35
Q

Mutable in python:

A

Lists
Dictionaries
Sets

36
Q

In Python everything is _ and variables are actually _.

A

an object

references to that object

37
Q

if the type of the parameter is mutable:

A

then the function will
actually be able to change the value of the parameter (same as
passing an array in C).

38
Q

if the type of the parameter is immutable:

A

then the function will
not be able to change the value of the parameter (same as passing an
integer in C).

Note though that if an immutable type contains a value
of a mutable type then the function can change that value, e.g.,
consider passing a pair of lists p = ([0], [1]) and performing
p[0][0] = 32.

39
Q

You can use the dot notation to _

A

invoke methods

40
Q

Encapsulation, i.e.,

A

the process of hiding information from the user, is a key feature of OOP.

41
Q

Private names (names that can only be accessed within the class) can be
declared using _

A

a double underscore

42
Q

Another characteristic features of OOP is that classes can often be
organised _

A

in a hierarchy.

43
Q

The idea is that classes that are higher in the hierarchy are more _
than those that appear in the the lower levels.

A

abstract

44
Q

In Python, every class is automatically a _

A

subclass of the class object.

45
Q

When a method is overridden, _

A

the version in the subclass will be used instead of the one in the superclass, even when the method is called on an instance of the subclass.

This is useful when the subclass needs to perform a specific behavior different from the superclass, but still wants to use the same method name for consistency and readability.

46
Q

Abstract Iteration :

A

(Specification on Iteration): Iterators and
Generators

47
Q

Polymorphism (give small def): (via what)

A

parametrization on types

Via names overloading
Via sub-typing
Via generics/templates
Via variables of type type (universal poly.)