W18 Flashcards

1
Q

The most two important computational resources are:

A
1- Time
2- Space (memory)
Also, we can measure:
- number of operations performed
- order of growth (big O notation)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Terminology for describing performance:

What is best case, worst case and average case?

A

best case: is the minimum running time overall possible inputs of a given size

worst case: is the maximum running time over all possible inputs of a given size

average case: is the average running time over all possible inputs

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

Order of growth ( big O notation) describes what?

A

the running time in relation to input size (usually the worst case scenario)

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

ways of sorting:

A

1- bubble sort
2- selection sort
3- merge sort

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

ways of searching:

A

1- linear search

2- bisection search

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

linear search

A

1- list does not have to be sorted

2- brute force search???

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

bisection search

A

1- list must be sorted

2- divide and conquer approach

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

A template that describes a set of objects with the same behaviours ??

A

A class

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

What is Encapsulation?

A

1- hiding the implementation details

2- enables changes in the implementation without affecting users of a class

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

An instance(نموذج) of a class?

A

An object

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

object reference?

A

The memory location of the object

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

How to check if two objects are aliases (point to the same memory location)?

A

using (is)
if obj1 is obj2:
print(“Aliases”)

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

How to check if two objects contain same data?

A

using ( ==)
if obj1 == obj2:
print(“objects contain same data”)

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

How to check if an object is not empty before using it?

A

using (is)
if obj is None:
…..

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

function vs methos

A
A method is defined as part of class definition
so, it always has, at least, one parameter which is (self)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is (self reference)?

A

(self) stores the object reference on which the method was invoked

17
Q

Accessor and Mutator methods:

A

get

set

18
Q

1- how to use the instance variable inside its class?

2- how to call a method inside a method in the same class?

A

using (self)
1- self.instanceVariable
2- def x(self,num):
self.addOne(num)

19
Q

should instance variable be encapsulated?

A

Yes

using accessor and mutator methods

20
Q

static(class) vs instance variables

A
  • both are declared inside a class.
  • however, instance variables are declared inside the constructor
  • other classes can call the static variable using the class name: class.variable
21
Q

What does a constructor do?

A

initialize instance variables of an object (creates an object and its instance variables)

22
Q

how to define a constructor?

A

def __init__(self):

23
Q

All variables are created at the run time?

True or False

A

True

24
Q

what is a default argument?

A

def __init__(self, age, name, color = white):

self. age= age
self. name= name
self. color= color

  • if the user did not enter a color, then by default the color is white.
  • this can be used in any method
25
Q

the special method (__repr__)

A

Like toString in Jave.

def \_\_repr\_\_(self):
   return self.age+" " + self.color
26
Q

I need more reading on the SPECIAL METHODS

A

to use the standard operators with an object, define the corresponding special methods