Ap Final Viva

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 7

Q.) What is an array?

--> An array is a data structure that stores a collection of elements, such as


numbers or characters, in contiguous memory locations.

Q.) What is stack?


--> A stack is a data structure that is used to represent the state of an
application at a particular point in time. It follows the Last In, First Out (LIFO)
principle. It is a collection of elements with two main operations: push, which
adds an element to the top, and pop, which removes the top element. This structure
is commonly used for managing function calls in algorithms.

There are two main types of stacks:

Fixed-size stack:
Has a predetermined maximum capacity.
Once the stack is full, no more elements can be pushed onto it.
Simpler implementation but can lead to overflow errors if not managed carefully.

Dynamic-size stack:
Adjusts its size dynamically based on the number of elements.
Allows for flexibility in handling varying amounts of data.
May involve more complex memory management to resize and allocate space as needed.

Q.) What is queue?


--> A queue is a linear data structure that allows users to store items in a list
in a systematic manner. It follows the First-In-First-Out (FIFO) principle. In
other words, the first element added to the queue is the first one to be removed.

There are two main types of queues:


Linear Queue:
Follows the First In, First Out (FIFO) principle.
Elements are added at the rear (enqueue) and removed from the front (dequeue).
Has a fixed size or may dynamically resize.

Circular Queue:
Also follows the FIFO principle.
Implemented as a circular data structure to efficiently use space.
After reaching the end of the queue, new elements are inserted at the beginning if
space is available.
Uses modular arithmetic to navigate within the circular structure.

Q.) Explain linked list?


-->
**Linked List:** A linear data structure where elements are stored in nodes, and
each node points to the next one in the sequence. It allows for efficient insertion
and deletion of elements. There are various types, including singly linked lists
(each node points to the next) and doubly linked lists (each node points to both
the next and previous nodes).
A circular linked list is a linked list data structure in which the last node
points back to the first node, forming a closed loop or circle. This structure
allows for traversal in both forward and backward directions, and operations like
insertion and deletion can be efficiently performed at any point in the list.
A circular doubly linked list is a linked list in which each node contains a data
element and two pointers, one pointing to the next node and another pointing to the
previous node. In addition to being circular, it allows for traversal in both
forward and backward directions, making it easy to perform operations like
insertion and deletion at any point in the list with efficient pointer adjustments.

Q.) What is searching and sorting?


--> Searching and sorting are fundamental operations in computer science and data
processing. They are used to organize and retrieve information efficiently from
datasets.

1. **Searching:**
Searching is the process of finding a specific item or element in a collection
of data. The collection could be an array, list, database, or any other data
structure. The goal of searching is to determine whether a particular element
exists in the dataset and, if it does, to locate its position or retrieve it.

Common searching algorithms include:


- **Linear Search:** Involves checking each element in the dataset one by one
until the target element is found or the end of the dataset is reached.
- **Binary Search:** Applicable to sorted datasets and involves repeatedly
dividing the search space in half until the target element is found.
- **Hashing:** Uses a hash function to map keys to indices in an array,
providing fast access to elements.

2. **Sorting:**
Sorting is the process of arranging the elements in a dataset in a particular
order, usually in ascending or descending order. Sorting is crucial for various
applications, including data analysis, and efficient data retrieval.

Common sorting algorithms include:


- **Bubble Sort:** Iteratively compares and swaps adjacent elements until the
entire dataset is sorted.
- **Selection Sort:** Finds the minimum (or maximum) element and swaps it with
the first (or last) element, then repeats for the remaining unsorted portion.
- **Insertion Sort:** Builds a sorted sequence one element at a time by
iteratively taking elements from the unsorted portion and inserting them into their
correct position in the sorted portion.
- **Merge Sort:** Divides the dataset into two halves, sorts each half, and then
merges them to produce a sorted result.
- **Quick Sort:** Chooses a pivot element and partitions the dataset into two
sub-arrays such that elements less than the pivot are on the left, and elements
greater than the pivot are on the right. The process is then applied recursively.

Efficient searching and sorting algorithms are crucial for optimizing the
performance of computer programs and systems when dealing with large datasets. The
choice of algorithm depends on factors such as the size of the dataset, whether it
is already partially sorted, and the desired time and space complexities.

Q.) What are graphs?


-->
In computer science and mathematics, a graph is a data structure that consists of a
set of nodes (or vertices) and a set of edges connecting pairs of nodes. Graphs can
be categorized into various types based on different properties and
characteristics. Here are some common types of graphs:

1. **Directed Graph (DiGraph):**


- In a directed graph, each edge has a direction, indicating a one-way
relationship between nodes.
- The edges are represented by arrows, showing the direction from one node to
another.

2. **Undirected Graph:**
- In an undirected graph, edges have no direction, indicating a two-way
relationship between nodes.
- The relationship is symmetric, meaning that if node A is connected to node B,
then node B is also connected to node A.

3. **Weighted Graph:**
- In a weighted graph, each edge has an associated numerical value or weight.
- The weight typically represents a cost, distance, or some other quantitative
measure of the relationship between nodes.

4. **Unweighted Graph:**
- In contrast to a weighted graph, an unweighted graph has edges with no
associated numerical values.

5. **Cyclic Graph:**
- A cyclic graph contains at least one cycle, which is a closed path that starts
and ends at the same node.

6. **Acyclic Graph:**
- An acyclic graph is one that does not contain any cycles. Directed Acyclic
Graphs (DAGs) are a specific type of acyclic graph.

7. **Connected Graph:**
- A connected graph is one in which there is a path between every pair of nodes.
- Disconnected graphs have two or more components that are not connected to each
other.

8. **Complete Graph:**
- In a complete graph, there is a unique edge between every pair of distinct
nodes.
- The complete graph with n nodes is denoted as Kn.

9. **Sparse Graph:**
- A graph is considered sparse if it has significantly fewer edges than the
maximum possible number of edges.
- Sparse graphs often have a relatively low edge density.

10. **Dense Graph:**


- A graph is considered dense if it has close to the maximum possible number of
edges.
- Dense graphs have a relatively high edge density.

11. **Bipartite Graph:**


- A bipartite graph is one whose nodes can be divided into two disjoint sets,
and all edges go between the sets (not within the sets).
- Bipartite graphs are often used to represent relationships between two
different types of entities.

These are just a few examples of the many types of graphs, each with its own set of
properties and applications. Graph theory provides a rich framework for modeling
and analyzing various relationships and structures in different domains.

Q.) What are trees?


-->
In computer science, a tree is a widely used data structure that represents a
hierarchical structure. A tree consists of nodes connected by edges, where each
node contains data, and the edges define relationships between the nodes.

Types of Trees:

Binary Tree:
In a binary tree, each node has at most two children: a left child and a right
child.
Various types of binary trees include full binary trees, complete binary trees, and
perfect binary trees.

Binary Search Tree (BST):


A binary search tree is a binary tree where the left subtree of a node contains
only nodes with values less than the node's value, and the right subtree contains
only nodes with values greater than the node's value.
This ordering property makes searching, insertion, and deletion operations
efficient.

AVL Tree:
An AVL tree is a self-balancing binary search tree. The heights of the two child
subtrees of any node differ by at most one.

Q.) Explain dynamic programming? Give real life example of dynamic programming?
-->
**Dynamic Programming:** A technique used to solve problems by breaking them down
into smaller overlapping subproblems and solving each subproblem only once, storing
the solutions.

**Real-Life Example:**
- Wireless Communication
- Speech Recognition

Q.) what is backtracking?


--> Backtracking is a problem-solving technique where you attempt to solve a
problem incrementally by trying different options, and if you reach a point where
you cannot proceed further, you backtrack to the previous decision and explore
alternative paths.

Q.) What is Greedy and Branch and Bound?


--> **Greedy:**
Greedy is an algorithmic pattern that makes the locally optimal choice at each
stage with the hope of finding a global optimum. It chooses the best immediate
option without considering the consequences.

**Branch and Bound:**


Branch and Bound is an algorithmic technique for solving optimization problems. It
systematically searches the solution space, dividing it into smaller subproblems
and using bounds to prune branches that cannot lead to an optimal solution.

Q) What is malloc.
--> Malloc is a function which is used to allocate memory dynamically during
program execution. It stands for "memory allocation".

Q) What is calloc.
--> “calloc” or “contiguous allocation” method is used to dynamically allocate the
specified number of blocks of memory of the specified type.

Q) What is free method.


--> free” method is used to dynamically de-allocate the memory.

Q) What is realloc.
--> “realloc” or “re-allocation” method is used to dynamically change the memory
allocation of a previously allocated memory

Q) What is multithreading.
--> Multithreading is a process of executing multiple threads simultaneously.
A thread is a lightweight sub-process, the smallest unit of processing.
Multiprocessing and multithreading, both are used to achieve multitasking.

Q.) What is multitasking.


--> Multitasking is a process of executing multiple tasks simultaneously. We use
multitasking to utilize the CPU. Multitasking can be achieved in two ways:
Process-based Multitasking (Multiprocessing) - Each process has an address in
memory.
Thread-based Multitasking (Multithreading) - Threads share the same address space.

Q) What is virtual function.


--> A virtual function is a member function that is declared within a base class
and is overridden by a derived class.

Q.) What is incline function


--> An inline function is a function that is expanded in line when it is called.

Q.) What is friend function


--> A friend function is defined as a function that can access private, protected,
and public members of a class.

Q.) What is a constructor


--> Constructor is a special method that is used automatically at the time of
object creation. It is used to initialize the data members of new objects
generally.

Q.) What is a copy constructor


--> A copy constructor is a special member function that allows you to create a new
object by copying the values of an existing object of the same class.

Q.) What is typecasting


--> type casting is a method or process that converts a data type into another data
type in both ways manually and automatically.
Converting a lower data type into a higher one is called implicit type casting. It
is done automatically.
Converting a higher data type into a lower one is called explicit type casting. It
is done manually by the programmer.

Q) Diff b/w structure and class


--> A structure is a grouping of variables of various data types referenced by the
same name.
A class is defined as a collection of related variables and functions contained
within a single structure.

Q) What is Memory Allocation?


--> Memory Allocation: Memory allocation is a process by which computer programs
and services are assigned with physical or virtual memory space. The memory
allocation is done either before or at the time of program execution. There are two
types of memory allocations:

Compile-time or Static Memory Allocation


Run-time or Dynamic Memory Allocation
Static Memory Allocation: Static Memory is allocated for declared variables by the
compiler. The memory is allocated during compile time.

Dynamic Memory Allocation: Memory allocation done at the time of execution(run


time) is known as dynamic memory allocation. Functions calloc() and malloc()
support allocating dynamic memory.
Q) What is Recursion?
--> The process in which a function calls itself directly or indirectly is called
recursion and the corresponding function is called a recursive function.
Direct recursion: When a function is called within itself directly it is called
direct recursion. This can be further categorised into four types:
- **Tail Recursion**: In tail recursion, the recursive call is the last operation
in a function. When the recursive call returns, the current function call can
immediately return its result without further computation. This is efficient and
can often be optimized by the compiler.

- **Head Recursion**: In head recursion, the recursive call is the first operation
in a function. The function performs some computation before making the recursive
call. As a result, the recursive calls accumulate on the call stack until the base
case is reached, and then they all start returning.

- **Tree Recursion**: Tree recursion occurs when a function makes multiple


recursive calls in a branching fashion, typically resulting in a recursive call
tree. Each call can lead to multiple new calls. It's common in problems involving
recursive exploration of tree-like data structures.

- **Nested Recursion**: Nested recursion happens when a function calls itself as


part of its arguments. In other words, the recursive call is embedded within
another function call. This can lead to deep levels of recursion and is often used
in mathematical or algorithmic problems.

Each of these recursion types has its own characteristics and use cases in
programming.
Indirect recursion: Indirect recursion occurs when a function calls another
function that eventually calls the original function and it forms a cycle.

Indirect recursion: Indirect recursion occurs when a function calls another


function that eventually calls the original function and it forms a cycle.

Q) What is overloading.
--> If we create two or more members having the same name but different in number
or type of parameter, it is known as overloading.
Types of overloading in C++ are:
Function overloading - Function Overloading is defined as the process of having two
or more function with the same name, but different in parameters is known as
function overloading
Operator overloading - Operator overloading is a compile-time polymorphism in which
the operator is overloaded to provide the special meaning to the user-defined data
type.

Extra-
Array are contiguous memory locations of homogenous data types stored in a fixed
location or size.
Lists are classic individual elements that are linked or connected to each other
with the help of pointers and do not have a fixed size.
While loop is also termed an entry-controlled loop
The do-while loop is termed an exit control loop
It simply means putting the operator before the operand
Block scope in C++ refers to the region of code enclosed within a pair of curly
braces `{}`. Variables declared inside a block are only visible and accessible
within that block, helping manage variable lifetimes and preventing unintended
conflicts with names outside the block.**
Command line arguments in C++ are values provided to a program when it is run from
the command line. They are passed as parameters to the `main` function and allow
external input to influence the behavior of the program.**
In C++, a reference function typically refers to a function that returns a
reference (alias) to a variable. This allows the function to modify the original
variable directly.**

Links-
https://www.edureka.co/blog/interview-questions/python-interview-questions/
https://www.interviewbit.com/cpp-interview-questions/

You might also like