SD Flashcards

1
Q

What is a delegate in C#?

A

A delegate is a type that represents references to methods with a specific parameter list and return type.

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

How can you declare a delegate in C#?

A

You can declare a delegate using the delegate keyword followed by the return type and parameters of the method it will reference.

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

Can a delegate reference static methods?

A

Yes, a delegate can reference both instance methods and static methods.

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

What is a multicast delegate in C#?

A

A multicast delegate is a delegate that holds references to multiple methods.

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

How can you add methods to a multicast delegate in C#?

A

You can add methods to a multicast delegate using the += operator.

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

What is the purpose of the Invoke method in C# delegates?

A

The Invoke method is used to call the methods that the delegate references.

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

What is the difference between delegates and interfaces in C#?

A

Delegates are similar to interfaces but are used to create references to methods rather than defining a contract for classes.

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

Can delegates be used for event handling in C#?

A

Yes, delegates are commonly used for event handling in C#.

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

What is a callback in C#?

A

A callback is a method that is passed as an argument to another method and is called when a certain event occurs.

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

How can you define a delegate with a custom signature in C#?

A

You can define a delegate with a custom signature by specifying the return type and parameters that the delegate will reference.

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

Can delegates be used for asynchronous programming in C#?

A

Yes, delegates can be used for asynchronous programming in C# by using the BeginInvoke and EndInvoke methods.

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

What is covariance in relation to delegates in C#?

A

Covariance allows you to assign a method that returns a more derived type to a delegate that returns a less derived type.

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

What is contravariance in relation to delegates in C#?

A

Contravariance allows you to assign a method that accepts a less derived type as a parameter to a delegate that expects a more derived type.

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

How can you check if a delegate is null in C#?

A

You can check if a delegate is null by comparing it to null or using the Equality operator.

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

What is the difference between synchronous and asynchronous delegates in C#?

A

Synchronous delegates execute the methods immediately, while asynchronous delegates allow the methods to execute on a separate thread.

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

How can you remove a method from a multicast delegate in C#?

A

You can remove a method from a multicast delegate using the -= operator.

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

What is the purpose of the GetInvocationList method in C# delegates?

A

The GetInvocationList method returns an array of delegates that represent the methods currently referenced by a multicast delegate.

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

Can delegates be used with lambda expressions in C#?

A

Yes, delegates can be used with lambda expressions to create inline methods.

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

What is the difference between a delegate and an event in C#?

A

An event is a special type of delegate that can only be invoked from within the class that defines it.

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

How can you create a generic delegate in C#?

A

You can create a generic delegate by using the generic type parameters when declaring the delegate.

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

What is the purpose of the DynamicInvoke method in C# delegates?

A

The DynamicInvoke method is used to invoke the methods that the delegate references with parameters passed as an object array.

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

Can delegates be used with anonymous methods in C#?

A

Yes, delegates can be used with anonymous methods to define inline methods without a separate method declaration.

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

What is the difference between a delegate and a function pointer?

A

Function pointers are a feature of C and C++, while delegates are a type-safe object-oriented way to refer to methods in C#.

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

How can you pass a delegate as a parameter in C#?

A

You can pass a delegate as a parameter by declaring the parameter as the delegate type that the method expects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What are the built-in types available in Python?
Common immutable types: * numbers: int(), float(), complex() * immutable sequences: str(), tuple(), frozenset(), bytes() Common mutable types: * mutable sequences: list(), bytearray() * set type: set() * mapping type: dict() * classes, class instances * etc.
26
What is a characteristic of Python regarding variable types?
Python is dynamically typed, meaning you don't need to state the types of variables when declaring them.
27
What does it mean that functions are first-class objects in Python?
Functions can be assigned to variables, returned from other functions, and passed into functions.
28
How do you modify a string in Python?
You can't modify a string directly because they are immutable. Instead, construct a new string from parts.
29
What are some benefits of using Python?
Benefits include: * Dynamic typing * Support for object-oriented programming * Functions as first-class objects * Quick development * Versatile usage in various fields
30
What is a Lambda Function in Python?
A small anonymous function that can take any number of arguments but has only one expression.
31
When would you use a tuple instead of a list in Python?
Use a tuple to store a sequence of items that will not change.
32
What is a negative index in Python?
Negative indices count from the right, with list[-1] referring to the last element.
33
Define global variables in Python.
Variables declared outside a function or in global space that can be accessed by any function.
34
Define local variables in Python.
Variables declared inside a function that are only accessible within that function.
35
What is the rule regarding local and global variables in Python?
In Python, variables are local unless explicitly declared as global.
36
Does Python have a switch-case statement?
No, before Python 3.10, Python did not have a switch-case statement; it can be simulated using if-elif-else.
37
How can you convert a string to a number in Python?
Use built-in functions like int() and float(). For example: int('1') == 1.
38
What are descriptors in Python?
Descriptors allow adding managed attributes to objects through methods __get__, __set__, and __delete__.
39
What is Linear (Sequential) Search?
A method that checks each element in an array for a match, with a time complexity of O(n).
40
When would you use Linear Search?
When the array is small, you cannot rearrange elements, or when you have no idea what you're searching for.
41
What is the purpose of the pass statement in Python?
To create empty code blocks where Python requires a statement.
42
What is the difference between lists and tuples?
Tuples are immutable, meaning their values cannot change, while lists are mutable.
43
Is it possible to have static methods in Python?
Yes, using the @staticmethod decorator.
44
How does Python memory management work?
Python uses garbage collection to manage memory, automatically freeing objects no longer referenced.
45
What is the difference between the list methods append() and extend()?
append() adds an element as a single item, while extend() concatenates another iterable to the list.
46
What is a Jump (or Block) Search?
47
What does the 'extend' method do in Python?
Concatenates the first list with another list (or another iterable, not necessarily a list).
48
What is Jump Search?
An algorithm used to search for the position of a target element on a sorted data collection or structure.
49
How does Jump Search improve over Linear Search?
By skipping some fixed number of elements in every iteration.
50
In Jump Search, what is the role of the variable 'm'?
It represents the size of the block that can be skipped in every iteration.
51
What is the time complexity of Jump Search?
O(√n)
52
What is the space complexity of Jump Search?
O(1)
53
What is the key advantage of Jump Search compared to Binary Search?
It does not rely on the division operator (/).
54
True or False: Jump Search performs a linear search after identifying the block that may contain the target element.
True
55
What is Interpolation Search?
An algorithm similar to Binary Search that improves search efficiency for uniformly distributed values in a sorted array.
56
How does Interpolation Search differ from Binary Search?
It calculates the estimated position of the target value based on the values of the array.
57
What is the formula used in Interpolation Search to find the position?
pos = low + [(x - arr[low]) * (hi - low) / (arr[hi] - arr[low])]
58
What is the average case time complexity of Interpolation Search?
O(log log n)
59
What is the worst-case time complexity of Interpolation Search?
O(n)
60
Fill in the blank: Jump Search maintains a worst and average case efficiency of O(_______) complexity.
√n
61
What is the optimal block size for Jump Search?
√n
62
True or False: Interpolation Search is more efficient than Binary Search when values are uniformly distributed.
True