DSA Unit I 2 Marks
DSA Unit I 2 Marks
DSA Unit I 2 Marks
1) What is OOPS?
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism
3) What is a class?
4) What is an Object?
An object is an instance of a class. It has its own state, behavior, and identity.
5) What is Encapsulation?
6) What is Polymorphism?
1
Polymorphism is nothing but assigning behavior or value in a subclass to
something that was already declared in the main class. Simply, polymorphism
takes more than one form.
7) What is Inheritance?
Inheritance is a concept where one class shares the structure and behavior
defined in another class. If Inheritance applied to one class is called Single
Inheritance, and if it depends on multiple classes, then it is called multiple
Inheritance.
Manipulators are the functions which can be used in conjunction with the
insertion (<<) and extraction (>>) operators on an object. Examples are endl and
setw.
2
12) What is a virtual function?
Example
void add(int& a, int& b);
Finalize method helps to perform cleanup operations on the resources which are
not currently used. Finalize method is protected, and it is accessible only through
this class or by a derived class.
Call by Value – Value passed will get modified only inside the function, and
it returns the same value whatever it is passed into the function.
Call by Reference – Value passed will get modified in both inside and
outside the functions and it returns the same or different value.
The super keyword is used to invoke the overridden method, which overrides one
of its superclass methods. This keyword allows to access overridden methods and
also to access hidden members of the superclass.
4
It also forwards a call from a constructor, to a constructor in the superclass.
5
Overriding is the same method names with the same arguments and return types
associated with the class and its child class.
Abstraction is a useful feature of OOPS, and it shows only the necessary details to
the client of an object. Meaning, it shows only required details for an object, not
the inner constructors, of an object. Example – When you want to switch on the
television, it is not necessary to know the inner circuitry/mechanism needed to
switch on the TV. Whatever is required to switch on TV will be shown by using an
abstract class.
Access modifiers determine the scope of the method or variables that can be
accessed from other various objects or classes. There are five types of access
modifiers, and they are as follows:
Private
Protected
Public
Friend
Protected Friend
6
Sealed modifiers are the access modifiers where the methods can not inherit it.
Sealed modifiers can also be applied to properties, events, and methods. This
modifier cannot be used to static members.
30) How can we call the base method without creating an instance?
Yes, it is possible to call the base method without creating an instance. And that
method should be “Static method.”
Doing Inheritance from that class.-Use Base Keyword from a derived class.
The new modifier instructs the compiler to use the new implementation instead
of the base class function. Whereas, Override modifier helps to override the base
class function.
Early binding refers to the assignment of values to variables during design time,
whereas late Binding refers to the assignment of values to variables during run
time.
7
34) What is ‘this’ pointer?
THIS pointer refers to the current object of a class. THIS keyword is used as a
pointer which differentiates between the current object with the global object. It
refers to the current object.
Primary data structures are the basic data structures that directly operate upon
the machine instructions. All the basic constants (integers, floating-point
numbers, character constants, string constants) and pointers are considered as
primary data structures
The List ADT is a sequential storage structure. General list takes the form a1, a2,
a3… an and the size of the list is ‘n’. Any element in the list at the position I is
defined to be ai, ai+1 is the successor of ai and ai-1 is the predecessor of ai.
8
39)What are the fundamental steps involved in algorithmic problem solving?
The fundamental steps are
Understanding the problem
Decision making
(i) Capabilities of computational devices
(ii)Either exact or approximate algorithm
(iii)Data structures
(iv)Algorithm strategies
Methods for specifying the algorithm
Proving an algorithms correctness
Analyzing an algorithm
Coding an algorithm
40)Define time and space complexity.
Time Complexity indicates how fast an algorithm runs. (i.e) The amount of time taken by an
algorithm to run to complete.
T(P)=Compile Time+ Run Time .(Tp)
Where Tp is no of add, sub, mul...
Space Complexity indicates how much extra memory the algorithm needs for execution.
Basically it has three components. They are instruction space, data space and environment
space.
Using the step count method analyze the time complexity when two m x n
matrices are added.
for(i<-0; i<m; i++)
{ for(j<-0; j<n; j++)
{ C[i][j]=A[i][j]+B[i][j]
} }
3mn+4m+2
Total
9
41)What are the various types of time complexity of an algorithm?
Big Oh (O)
Big Omega (Ω)
Big Theta (Θ )
Little Oh (o )
Little Omega (ω )
42)Define asymptotic notation.
Asymptotic notations are mathematical tools to represent time complexity of algorithm
for asymptotic analysis.
Standard asymptotic notations are
a) Big Oh(O)
b) Big Omega(Ω)
c) Big Theta(Θ )
10
16 Marks
1. Explain about various asymptotic notations with an example and list the properties of
Big-Oh (O) notation.
2. Explain in detail about the process of solving recurrence relations with suitable
examples
3. Discuss briefly the sequence of steps in designing and analyzing an algorithm.
4. Write the recursive algorithm for computing Fibonacci numbers and solve its
recurrence relation.
5. What are the important problem types focused by the researchers? Explain in detail.
7. Prove that for any two functions f(n) and g(n), we have f(n)= Θ(g(n)), if and only if
f(n)=O(g(n))= Ω(g(n)).
8. Write an algorithm to find mean and variance of an array perform best, worst and
average case complexity, defining the notations used for each type of analysis.
9. Explain the basic efficiency classes with suitable examples.
11