More General Flashcards

1
Q

What is a closure (Python)

A
Occur when there is a nested funciton present, the nested function references a value in the enclosing scope only, the outer function returns the nested function. Allows avoidance of global variables and hides data
def make_multiplier_of(n):
    def multiplier(x):
        return x * n
    return multiplier
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Check for balanced parenthesis using Stack, Queue

A

https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-python/

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

Convert list to string in python

A
list1 = ['1', '2', '3']
str1 = ''.join(list1)
list1 = [1, 2, 3]
str1 = ''.join(str(e) for e in list1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How much time does it take to retrieve an element in a Hashmap, Binary Tree, and a LinkedList

A

HashMap: O(1), Binary Tree: O(logn), LinkedList: O(n)

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

What is the difference between Overridding and Overloading?

A

Overriding is resolved at runtime and Overloading at compile time

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

What is the difference between forking a process and spawning a thread?

A

When forking a process the code is duplicated and run in

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

What is polymorphism

A

Using the same interface for objects of different forms, data, functions, classes

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