0% found this document useful (0 votes)
14 views7 pages

Week 8

The document covers various programming concepts including stack operations in C, memory allocation for 3D arrays, and functions like ldexp() and frexp(). It also discusses C++ static functions, data structures like Binary Search Trees, Unix process management calls, DBMS join operations, operating system thread scheduling strategies, and SQL operations. Additionally, it explains terminal emulation in computer networks and its relation to the OSI model.

Uploaded by

aloksharma8867
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)
14 views7 pages

Week 8

The document covers various programming concepts including stack operations in C, memory allocation for 3D arrays, and functions like ldexp() and frexp(). It also discusses C++ static functions, data structures like Binary Search Trees, Unix process management calls, DBMS join operations, operating system thread scheduling strategies, and SQL operations. Additionally, it explains terminal emulation in computer networks and its relation to the OSI model.

Uploaded by

aloksharma8867
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/ 7

Week8

C Programming

Q1) A stack is a data structure that follows the LIFO (Last In, First Out) principle. It means the
last element added to the stack will be the first one to be removed. Operations typically
performed on a stack include:

●​ Push: Add an element to the top of the stack.


●​ Pop: Remove the top element from the stack.
●​ Peek: View the top element without removing it.
●​ isEmpty: Check if the stack is empty.​
Stacks are widely used in recursive algorithms, expression evaluation, and memory
management.

Q2) #include <stdio.h>


#include <stdlib.h>
int main() {
int ***array;
int x = 3, y = 3, z = 3; // Dimensions of the 3D array
// Allocating memory
array = (int ***)malloc(x * sizeof(int **));
for (int i = 0; i < x; i++) {
array[i] = (int **)malloc(y * sizeof(int *));
for (int j = 0; j < y; j++) {
array[i][j] = (int *)malloc(z * sizeof(int));
}
}
// Example: Assign values and print
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int k = 0; k < z; k++) {
array[i][j][k] = i + j + k; // Assign some values
printf("array[%d][%d][%d] = %d\n", i, j, k, array[i][j][k]);
}
}
}
// Freeing memory
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
free(array[i][j]); }
free(array[i]);
}
free(array);

return 0;
}

Q3) The ldexp() function in C is used to calculate the result of multiplying a floating-point
number by 2 raised to the power of a given integer. Its prototype is:
double ldexp(double x, int exp);

Q4) Use the frexp() function, which decomposes a floating-point number into its mantissa
and exponent. The prototype is:
double frexp(double x, int *exp);

Q5) Use the atexit() function to register a function that is called when the program
terminates normally. Example:
#include <stdio.h>
#include <stdlib.h>

void cleanup() {
printf("Program is terminating. Cleanup function executed.\n");
}

int main() {
atexit(cleanup); // Register the cleanup function
printf("Program is running.\n");
return 0;
}

C++ Programming

Q1) No, a static function cannot be declared as virtual in C++.

●​ Reason:​
Static functions are not tied to any specific instance of a class and do not operate on
instance data (i.e., this pointer is not available in static functions).​
Virtual functions, on the other hand, rely on the this pointer and polymorphism, which is
dependent on an object instance. Hence, these two concepts are fundamentally
incompatible.

Q2) The confusion arises from the term const in const char *p.
Here, const char *p means that the data being pointed to by p cannot be modified, but the
pointer p itself can be reassigned to point to another memory location.
In the program, p is declared but not initialized initially. Later, it is assigned the address of the
string literal "A const pointer". This assignment is valid because the const qualifier
applies to the data pointed to by p, not the pointer p itself.

Data Structure

Q1) The most suitable data structure for efficient tree construction is the Binary Search Tree
(BST) or specialized versions like AVL Trees or Red-Black Trees.

●​ BST provides efficient insertion, deletion, and searching operations, with an


average-case time complexity of O(log n).
●​ AVL Trees and Red-Black Trees are self-balancing trees that ensure the tree height
remains logarithmic.

Q2) The Backtracking algorithm is used to solve the 8 Queens problem.

○​ Backtracking explores all possible arrangements of queens on the chessboard


while ensuring no two queens threaten each other.
○​ It employs recursion and backtracks whenever it encounters an invalid solution.

Unix

Q1) Key system calls in Unix for process management include:

●​ fork(): Creates a new process by duplicating the current process.


●​ exec(): Replaces the current process image with a new one.
●​ wait(): Suspends the calling process until one of its child processes terminates.
●​ exit(): Terminates a process.
●​ getpid(): Returns the process ID of the calling process.
●​ kill(): Sends a signal to a process.
●​ nice(): Sets process priority.

Q2) Get an environment variable: Use getenv() from the stdlib.h library.

char *value = getenv("ENV_VAR_NAME");

if (value) printf("Value: %s\n", value);

Set an environment variable: Use setenv() or putenv()

setenv("ENV_VAR_NAME", "value", 1); // Overwrites if exists


DBMS

Q1) A join operation in DBMS combines rows from two or more tables
based on a related column. Types of joins include:

●​ Inner Join: Returns matching rows from both tables.


●​ Left Join: Returns all rows from the left table and matching rows
from the right table.
●​ Right Join: Returns all rows from the right table and matching
rows from the left table.
●​ Full Join: Returns all rows when there is a match in either
table.

Q2) Base operations in relational algebra are:

●​ Selection (σ): Filters rows based on a condition.


●​ Projection (π): Selects specific columns.
●​ Union (∪): Combines rows from two relations.
●​ Set Difference (-): Finds rows in one relation but not in the
other.
●​ Cartesian Product (×): Combines every row of one relation with
every row of another.
●​ Rename (ρ): Renames a relation or its attributes.

Operating System

Q1) Busy waiting occurs when a process continuously checks for a


condition to become true without releasing the CPU.

●​ This wastes CPU cycles and can degrade system performance.


●​ Alternative: Use blocking mechanisms like semaphores, mutexes, or
condition variables.

Q2) Popular thread-scheduling strategies in multiprocessor systems


include:

●​ Load Balancing: Ensures threads are evenly distributed across


processors to avoid idle CPUs.
●​ Thread Affinity (Processor Binding): Threads are tied to specific
processors to improve cache utilization.
●​ Global Queue Scheduling: Threads are placed in a global queue and
assigned to any available processor.
●​ Local Queue Scheduling: Each processor has its own queue of
threads, reducing contention for the global queue.
●​ Work Stealing: Processors with idle time "steal" tasks from busy
processors.

SQL

Q1) Operation Type:

●​ TRUNCATE: DDL (Data Definition Language)


●​ DELETE: DML (Data Manipulation Language)

Action:

●​ TRUNCATE: Removes all rows from a table without logging


individual row deletions.
●​ DELETE: Removes rows selectively based on a condition or all
rows.

WHERE Clause:

●​ TRUNCATE: Not allowed.


●​ DELETE: Allowed.

Trigger Execution:

●​ TRUNCATE: Does not fire triggers.


●​ DELETE: Fires triggers if defined.

Rollback:

●​ TRUNCATE: Cannot be rolled back (committed immediately).


●​ DELETE: Can be rolled back if within a transaction.

Speed:

●​ TRUNCATE: Faster due to minimal logging.


●​ DELETE: Slower due to logging each deletion.
Q2) CREATE TABLE new_table_name AS

SELECT * FROM existing_table_name WHERE 1 = 0;

Q3)1) SELECT *

FROM SOFTWARE

WHERE DEVIN = 'Rakesh';

Q3)2) SELECT COUNT(*) AS Programmer_Count

FROM STUDIES

WHERE SPLACE = 'Pentafour';

Computer Networks

Q1) Terminal Emulation:​


Terminal emulation is a process that allows a computer to mimic the
functionality of a terminal or a different system. It enables a system
to connect to a remote host and interact with it as though it were
directly connected. Terminal emulation software (e.g., Telnet, SSH
clients) is commonly used to access mainframes, servers, or other
remote systems.

Layer:​
Terminal emulation operates in the Application Layer of the OSI (Open
Systems Interconnection) model. This layer provides the interface
between the user and the network, facilitating services like file
transfers, email, and remote login.

You might also like