[go: up one dir, main page]

0% found this document useful (0 votes)
4 views8 pages

C Imp2Mark

The document provides a series of questions and answers related to data structures and programming concepts, including definitions and explanations of data structures like arrays, linked lists, stacks, and queues. It also covers programming paradigms such as Object-Oriented Programming, concepts like inheritance, constructors, destructors, and sorting algorithms. Additionally, it discusses memory allocation, access specifiers, and the significance of namespaces in C++.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

C Imp2Mark

The document provides a series of questions and answers related to data structures and programming concepts, including definitions and explanations of data structures like arrays, linked lists, stacks, and queues. It also covers programming paradigms such as Object-Oriented Programming, concepts like inheritance, constructors, destructors, and sorting algorithms. Additionally, it discusses memory allocation, access specifiers, and the significance of namespaces in C++.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

End Term Exam 2-Mark Questions and Answers

Q: Define Data Structure and List its Types.

A: A data structure is a way of organizing and storing data so that it can be accessed and modified

efficiently. It is the foundation for creating algorithms and solving computational problems. The types

of data structures are: Primitive Data Structures: These are basic data types such as integers, floating-

point numbers, characters, and booleans, which are directly operated upon by machine-level

instructions. Non-Primitive Data Structures: These are more complex structures made from primitive

data types. They include Linear Data Structures (arrays, linked lists, stacks, and queues) and Non-

Linear Data Structures (trees, graphs, and hash tables).

Q: Differentiate between Object-Oriented Programming and Procedure-Oriented


Programming.

A: Object-Oriented Programming (OOP) and Procedure-Oriented Programming (POP) are two major

programming paradigms. POP focuses on functions or procedures, and data is manipulated by the

functions. It follows a top-down approach, and functions can be reused, but they cannot restrict access

to the data. OOP is based on the concept of objects, which are instances of classes, and it uses the

concepts of encapsulation, inheritance, and polymorphism. It focuses on data security,

reusability, and flexibility.

Q: Explain the concept of Inheritance in Object-Oriented Programming.

A: Inheritance in Object-Oriented Programming (OOP) refers to the mechanism by which one class

can acquire the properties and methods of another class. The class inheriting the features is called

the subclass (or derived class), and the class from which the features are inherited is the superclass

(or base class). This concept promotes code reusability and a hierarchical classification of classes.

There are three main types of inheritance: Single Inheritance, Multiple Inheritance, and Multilevel

Inheritance.

Join my community : https://chat.whatsapp.com/K0fZdK8oYOTBJNulvKlbwU


Important question by MrDnobody
Q: Write the Syntax for Declaring an Array in C++.
A: In C++, an array is a collection of elements of the same data type, stored in contiguous memory

locations. It is a static data structure where the size of the array is fixed. The syntax for declaring an

array is as follows: data_type array_name[array_size]; Example: int arr[5]; // Declares an integer array

with 5 elements. Alternatively, arrays can be initialized during declaration: int arr[5] = {1, 2, 3, 4, 5}; //

Declares and initializes an integer array.

Q: What is a Linked List?

A: A Linked List is a linear data structure where elements, called nodes, are stored in non-contiguous

memory locations. Each node contains two parts: Data, which holds the value, and a Next pointer,

which points to the next node in the sequence. The linked list allows dynamic memory allocation,

meaning the size of the list can grow or shrink at runtime, unlike arrays with a fixed size. Linked lists

can be singly or doubly linked, and operations include insertion, deletion, and traversal.

Q: What is a Stack?

A: A Stack is a linear data structure that follows the Last In First Out (LIFO) principle. The last element

inserted into the stack is the first to be removed. A stack can be visualized as a stack of plates where

the plate on the top is the first one to be taken off. The main operations of a stack include: Push

(adding an element to the stack), Pop (removing the top element from the stack), Peek (viewing the

top element without removing it), and isEmpty (checking if the stack is empty).

Q: What is the difference between Linear Search and Binary Search?

A: Linear Search is a simple search algorithm that checks each element of a list sequentially until the

desired element is found. Its time complexity is O(n), making it inefficient for large lists. Binary Search

is a more efficient algorithm that works on sorted lists. It repeatedly divides the search space into

Join my community : https://chat.whatsapp.com/K0fZdK8oYOTBJNulvKlbwU


Important question by MrDnobody
halves, narrowing down the location of the element, and has a time complexity of O(log n), making it

much faster than Linear Search for large datasets.

Q: Define the concept of Queue.


A: A Queue is a linear data structure that follows the First In First Out (FIFO) principle. The first element

added to the queue is the first one to be removed. A queue can be visualized as a line of customers

waiting for service, where the first customer to arrive is the first one to be served. The main operations

of a queue are: Enqueue (adding an element to the end of the queue), Dequeue (removing an element

from the front of the queue), and Front (viewing the front element without removing it).

Q: What is the significance of Constructors in C++?

A: A Constructor is a special member function in C++ that is automatically called when an object of a

class is created. It initializes the object's data members and sets up the initial state of the object.

Constructors can be default (no parameters) or parameterized (with arguments). They ensure that

objects are initialized with valid data before they are used in a program. Constructors do not return a

value, not even void.

Q: Explain the concept of Postfix Notation.

A: Postfix notation, also known as Reverse Polish Notation (RPN), is a mathematical notation in which

every operator follows all of its operands. This eliminates the need for parentheses to dictate the order

of operations. For example, A + B becomes A B + in postfix. Postfix notation is evaluated using a stack:

when an operator is encountered, operands are popped from the stack, the operation is performed,

and the result is pushed back onto the stack.

Q: What are the operations associated with a Linked List?

A: A Linked List supports several operations for adding, removing, and accessing elements: Insertion

(adding nodes to the beginning, end, or specific positions), Deletion (removing nodes from specific

positions), Traversal (visiting each node to perform an operation like printing values), Searching

Join my community : https://chat.whatsapp.com/K0fZdK8oYOTBJNulvKlbwU


Important question by MrDnobody
(finding specific elements), and Reversal (reversing the order of nodes). These operations allow

efficient dynamic memory usage compared to arrays.

Q: Write the advantages of using a Class in Object-Oriented Programming.


A: Classes in Object-Oriented Programming (OOP) provide several advantages: Encapsulation

bundles data and methods into a single unit, improving data security. Reusability promotes code reuse

by allowing the creation of multiple objects from a single class. Modularity divides complex problems

into manageable parts. Inheritance and Polymorphism allow classes to inherit features from other

classes and behave in multiple ways, respectively.

Q: What is meant by FIFO in a data structure?

A: FIFO stands for First In First Out. It is the principle followed by Queue data structures. In FIFO, the

first element added is the first one to be removed. This principle ensures that data is processed in the

same order as it arrives. Common applications of FIFO include scheduling tasks, managing resource

usage, and buffering data streams in networking and operating systems.

Q: Explain the concept of Linear Arrays.

A: A Linear Array is a data structure where elements are stored in consecutive memory locations. It is

one of the simplest and most efficient ways to store a collection of items, such as numbers or objects,

of the same data type. The size of the array is fixed when it is created. Elements can be accessed

using an index, starting from 0. Arrays are widely used for their simple implementation and ease of

use in operations such as searching, sorting, and iterating over data.

Q: What is the use of Access Specifiers in C++?

A: Access specifiers in C++ determine the visibility and accessibility of class members (variables and

methods). There are three main access specifiers: Public, Private, and Protected. Public members

can be accessed from anywhere. Private members can only be accessed within the class itself,

Join my community : https://chat.whatsapp.com/K0fZdK8oYOTBJNulvKlbwU


Important question by MrDnobody
ensuring data encapsulation. Protected members are accessible within the class and by derived

classes but not from outside the class hierarchy.

Q: What is the role of a Destructor in C++?

A: A Destructor is a special member function in C++ that is called when an object goes out of scope

or is explicitly destroyed. It is used to perform cleanup operations such as releasing resources

(memory, file handles, etc.) that were allocated during the object's lifetime. The destructor has the

same name as the class, but with a tilde (~) prefix. Unlike constructors, destructors do not take

parameters and do not return any values.

Q: List the types of Inheritance in C++.

A: Inheritance in C++ allows a class to inherit properties and methods from another class. There are

several types of inheritance: Single Inheritance (a class inherits from one base class), Multiple

Inheritance (a class inherits from more than one base class), Multilevel Inheritance (a class inherits

from another derived class), Hierarchical Inheritance (multiple classes inherit from a single base

class), and Hybrid Inheritance (a combination of different types).

Q: What is Bubble Sort and how does it work?

A: Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent

elements, and swaps them if they are in the wrong order. The process continues until the list is sorted.

Bubble Sort has a time complexity of O(n^2) in the worst case, which makes it inefficient for large

datasets. Despite its simplicity, it is useful for small datasets or educational purposes.

Q: Write the basic syntax for defining a 2-D array in C++.

A: In C++, a 2-D array is an array of arrays. It is used to store data in a table format, with rows and

columns. The syntax for declaring a 2-D array is: data_type array_name[row_size][column_size];

Join my community : https://chat.whatsapp.com/K0fZdK8oYOTBJNulvKlbwU


Important question by MrDnobody
Example: int arr[3][4]; // Declares a 2-D array with 3 rows and 4 columns. You can also initialize a 2-D

array during declaration: int arr[2][3] = {{1, 2, 3}, {4, 5, 6}}; // Declares and initializes a 2-D array.

Q: What is a Circular Queue?

A: A Circular Queue is a variation of the standard queue, where the last element is connected to the

first element, forming a circle. This design helps efficiently utilize the memory space in a queue by

ensuring that when the rear pointer reaches the end of the array, it can wrap around to the beginning,

provided there is space. Circular queues are often implemented using arrays and are useful in

situations where the queue is implemented in a fixed-size buffer, such as scheduling or resource

management.

Q: Explain the concept of a Stack in terms of its LIFO principle.

A: A Stack is a linear data structure that follows the Last In First Out (LIFO) principle. This means that

the last element added to the stack is the first to be removed. It is often visualized as a stack of plates

where the plate on the top is the first one to be taken off. The primary operations of a stack are: Push

(adding an element to the stack), Pop (removing the top element from the stack), Peek (viewing the

top element without removing it).

Q: What is the significance of the Namespace in C++?

A: A Namespace in C++ is a declarative region that provides a scope to the identifiers (such as

variables, functions, and classes) within it. Namespaces are used to organize code into logical groups

and to avoid name conflicts, especially when different libraries have functions or variables with the

same name. The std namespace is the standard namespace that includes features like the cout and

cin functions. The syntax to define a namespace is: namespace namespace_name {...}.

Q: What do you understand by Sequential Search?

Join my community : https://chat.whatsapp.com/K0fZdK8oYOTBJNulvKlbwU


Important question by MrDnobody
A: Sequential Search, also known as Linear Search, is a simple search algorithm where each element

in a list is checked in sequence from the beginning until the desired element is found. If the element

is not present in the list, the algorithm concludes after checking all the elements. This search method

is called sequential because the elements are processed one by one in a sequential manner. Its time

complexity is O(n), where n is the number of elements in the list.

Q: What is the difference between Push and Pop operations in a Stack?

A: In a Stack, the two primary operations are Push and Pop: Push: The push operation adds an

element to the top of the stack. This operation increases the size of the stack by one and places the

new element at the top. If the stack is full, push will fail if it's a bounded stack (implemented using an

array). Pop: The pop operation removes the element from the top of the stack. It decreases the size

of the stack by one and returns the element that was removed.

Q: Describe a Node in a Linked List.

A: A Node in a linked list is a basic unit of a linked list data structure, consisting of two parts: Data:

The actual data stored within the node (e.g., an integer, string, or object). Next Pointer: A reference

(or pointer) to the next node in the sequence. In the case of a singly linked list, each node points to

the next node in the list. For a doubly linked list, each node has two pointers: one pointing to the next

node and one pointing to the previous node.

Q: What is the purpose of an Inline Function in C++?

A: An Inline Function in C++ is a function that is expanded in place where it is called, rather than being

invoked through a standard function call. The keyword inline is used to suggest to the compiler that

the function's code should be inserted directly into the calling code. The primary purpose of inline

functions is to reduce function call overhead, which can be significant in small, frequently called

functions. However, this is beneficial only for small functions.

Join my community : https://chat.whatsapp.com/K0fZdK8oYOTBJNulvKlbwU


Important question by MrDnobody
Q: What do you mean by Destructor in Object-Oriented Programming?

A: A Destructor is a special member function in C++ that is automatically invoked when an object is

destroyed. It is used to clean up resources that were acquired during the object's lifetime, such as

releasing dynamically allocated memory, closing file handles, or releasing any other system resources.

A destructor has the same name as the class, but with a tilde (~) prefix. Unlike constructors,

destructors do not take parameters and do not return any values.

Q: Explain the concept of Memory Allocation in Arrays.

A: In C++, arrays can be statically or dynamically allocated in memory. Static Memory Allocation:

When you define an array with a fixed size, like int arr[5];, the memory is allocated at compile time.

The size of the array must be known and fixed when the program starts. This is efficient, but it can

waste memory if the array is not fully utilized or if the size is too small. Dynamic Memory Allocation: In

cases where the size of the array is not known at compile time, dynamic memory allocation is used.

Q: What is a Circular Queue?

A: A Circular Queue is a type of Queue in which the last element is connected to the first element,

forming a circle. It eliminates the issue of wasted space in a regular queue where the front pointer

may need to shift when an element is dequeued, making the queue inefficient. A Circular Queue allows

both enqueue and dequeue operations to happen in a circular manner, improving memory

utilization.

Join my community : https://chat.whatsapp.com/K0fZdK8oYOTBJNulvKlbwU


Important question by MrDnobody

You might also like