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
Q

What are the built-in types available in Python?

A

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
Q

What is a characteristic of Python regarding variable types?

A

Python is dynamically typed, meaning you don’t need to state the types of variables when declaring them.

27
Q

What does it mean that functions are first-class objects in Python?

A

Functions can be assigned to variables, returned from other functions, and passed into functions.

28
Q

How do you modify a string in Python?

A

You can’t modify a string directly because they are immutable. Instead, construct a new string from parts.

29
Q

What are some benefits of using Python?

A

Benefits include:
* Dynamic typing
* Support for object-oriented programming
* Functions as first-class objects
* Quick development
* Versatile usage in various fields

30
Q

What is a Lambda Function in Python?

A

A small anonymous function that can take any number of arguments but has only one expression.

31
Q

When would you use a tuple instead of a list in Python?

A

Use a tuple to store a sequence of items that will not change.

32
Q

What is a negative index in Python?

A

Negative indices count from the right, with list[-1] referring to the last element.

33
Q

Define global variables in Python.

A

Variables declared outside a function or in global space that can be accessed by any function.

34
Q

Define local variables in Python.

A

Variables declared inside a function that are only accessible within that function.

35
Q

What is the rule regarding local and global variables in Python?

A

In Python, variables are local unless explicitly declared as global.

36
Q

Does Python have a switch-case statement?

A

No, before Python 3.10, Python did not have a switch-case statement; it can be simulated using if-elif-else.

37
Q

How can you convert a string to a number in Python?

A

Use built-in functions like int() and float(). For example: int(‘1’) == 1.

38
Q

What are descriptors in Python?

A

Descriptors allow adding managed attributes to objects through methods __get__, __set__, and __delete__.

39
Q

What is Linear (Sequential) Search?

A

A method that checks each element in an array for a match, with a time complexity of O(n).

40
Q

When would you use Linear Search?

A

When the array is small, you cannot rearrange elements, or when you have no idea what you’re searching for.

41
Q

What is the purpose of the pass statement in Python?

A

To create empty code blocks where Python requires a statement.

42
Q

What is the difference between lists and tuples?

A

Tuples are immutable, meaning their values cannot change, while lists are mutable.

43
Q

Is it possible to have static methods in Python?

A

Yes, using the @staticmethod decorator.

44
Q

How does Python memory management work?

A

Python uses garbage collection to manage memory, automatically freeing objects no longer referenced.

45
Q

What is the difference between the list methods append() and extend()?

A

append() adds an element as a single item, while extend() concatenates another iterable to the list.

46
Q

What is a Jump (or Block) Search?

A
47
Q

What does the ‘extend’ method do in Python?

A

Concatenates the first list with another list (or another iterable, not necessarily a list).

48
Q

What is Jump Search?

A

An algorithm used to search for the position of a target element on a sorted data collection or structure.

49
Q

How does Jump Search improve over Linear Search?

A

By skipping some fixed number of elements in every iteration.

50
Q

In Jump Search, what is the role of the variable ‘m’?

A

It represents the size of the block that can be skipped in every iteration.

51
Q

What is the time complexity of Jump Search?

A

O(√n)

52
Q

What is the space complexity of Jump Search?

A

O(1)

53
Q

What is the key advantage of Jump Search compared to Binary Search?

A

It does not rely on the division operator (/).

54
Q

True or False: Jump Search performs a linear search after identifying the block that may contain the target element.

A

True

55
Q

What is Interpolation Search?

A

An algorithm similar to Binary Search that improves search efficiency for uniformly distributed values in a sorted array.

56
Q

How does Interpolation Search differ from Binary Search?

A

It calculates the estimated position of the target value based on the values of the array.

57
Q

What is the formula used in Interpolation Search to find the position?

A

pos = low + [(x - arr[low]) * (hi - low) / (arr[hi] - arr[low])]

58
Q

What is the average case time complexity of Interpolation Search?

A

O(log log n)

59
Q

What is the worst-case time complexity of Interpolation Search?

A

O(n)

60
Q

Fill in the blank: Jump Search maintains a worst and average case efficiency of O(_______) complexity.

A

√n

61
Q

What is the optimal block size for Jump Search?

A

√n

62
Q

True or False: Interpolation Search is more efficient than Binary Search when values are uniformly distributed.

A

True