Worksheet-1
Worksheet-1
Sec on : AB-1
——————————————————————————————————————
C-Programming
Q1)
#include <stdio.h>
return 0;
Q2)
The div() func on in C is used to perform integer division and return both the quo ent and
remainder in a single opera on. It is de ned in the stdlib.h header.
#include <stdio.h>
#include <stdlib.h>
int main() {
return 0;
Q3)
#include <stdio.h>
int main() {
prin ("Day: %d, Month: %d, Year: %d\n", day, month, year);
return 0;
Q4)
#include <stdio.h>
int main() {
return 0;
fl
tf
tf
tf
tf
}
Q5)
In C, you can dynamically allocate memory for an array using the malloc(), calloc(), or
realloc() func ons from the stdlib.h library. Dynamic memory alloca on allows you to
allocate memory at run me, giving exibility when the size of the array isn't known
beforehand.
C++ Programming
Q1)
#include <iostream>
class Date {
private:
public:
day = d;
month = m;
year = y;
cout << "Date: " << (day < 10 ? "0" : "") << day << "-"
}
ti
ti
fl
ti
};
int main() {
Date today;
today.setDate(26, 2, 2025);
today.displayDate();
return 0;
Q2)
The this pointer cannot be used inside a sta c member func on in C++. The this pointer
refers to the current object of a class. However, sta c member func ons belong to the class
itself rather than any par cular object. As a result, sta c func ons can be called without
crea ng an instance of the class. Since there is no object associated with the call, the this
pointer does not exist in the context of a sta c func on. Consequently, a emp ng to use
this inside a sta c member func on will result in a compila on error. Sta c func ons can
only access sta c data members and other sta c func ons directly. To access non-sta c
members, an explicit object reference is required.
DATA STRUCTURES
Q1)
Inorder Output:
HDBEAFCIGJ
Preorder Output:
ABDHECFGIJ
Postorder Output:
HDEBFIJGCA
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
tt
ti
ti
ti
ti
Unix
Q1)
1. New (Created) – The process is being created but has not started execu on yet.
2. Ready – The process is wai ng in the queue for CPU me to execute.
3. Running – The process is currently being executed by the CPU.
4. Wai ng (Blocked) – The process is wai ng for some resource (like I/O or another
process).
5. Terminated (Zombie) – The process has completed execu on but s ll exists in the
process table un l the parent collects its exit status.
6. Stopped (Suspended) – The process is stopped and can be resumed later (e.g., using
kill -STOP and kill -CONT).
Q2)
When you run a program (e.g., by typing ./a.out in the terminal), the following steps occur:
1. Fork: The shell creates a child process using the fork() system call.
2. Exec: The child process replaces itself with the new program using exec(), loading the
executable into memory.
3. Process Scheduling: The OS schedules the process for execu on, alloca ng CPU me.
4. Execu on: The program runs and interacts with system resources ( les, memory,
etc.).
5. Comple on: Once nished, the process exits (exit()) and becomes a zombie un l the
parent collects its exit status.
DBMS
Q1)
A Data Dic onary (or Data Directory) is a repository of metadata (data about data) in a
database. It stores informa on about database objects such as tables, columns, data types,
constraints, indexes, users, and rela onships.
1. Ac ve Data Dic onary – Automa cally updated by the DBMS when any changes
occur (e.g., in MySQL, Oracle).
Passive Data Dic onary – Manually updated by database administrators.
ti
ti
ti
ti
ti
ti
ti
ti
ti
fi
ti
ti
ti
ti
ti
ti
ti
ti
ti
fi
ti
ti
ti
ti
Q2)
Opera ng System
Q1)
Page replacement occurs when a process needs a page that is not in memory, and the
system selects a page to remove.
• Local Page Replacement
o The process replaces pages from its allocated memory only.
o Each process has a xed number of frames, and it cannot take memory from
other processes.
o Example: Fixed Alloca on – If a process has 5 frames, it can only replace
pages within those 5 frames.
• Global Page Replacement
o The process can replace any page in memory, even from another process.
o It improves system performance but may cause starva on (some processes
may keep losing pages).
ti
ft
ti
ft
ti
ti
fi
ti
ti
ti
ti
ti
ti
tt
ti
ti
ti
ti
o Example: LRU (Least Recently Used), FIFO (First In First Out) – The system
selects a page from all available frames, not just the current process’s
allocated memory.
Q2)
• Seek Time:
o Time taken by the disk’s read/write head to move to the required track
(cylinder).
o Most me-consuming part of disk access.
o Example: If data is on track 40 but the head is at track 10, it takes me to
move to track 40.
• Latency (Rota onal Latency):
o Time taken by the disk to rotate the required sector under the read/write
head.
o Depends on disk RPM (Rota ons Per Minute).
o Example: The sector might be at the other end of the disk, so it takes me to
rotate to the correct posi on.
• Transfer Time:
o Time required to transfer data from the disk to memory once the head is at
the right posi on.
o Example: Once the sector is under the head, the me taken to read and send
it to RAM.
Q3)
Paging is a memory management technique where the OS divides process memory into
xed-sized pages and physical memory into xed-sized frames.
• Why use Paging?
o Eliminates external fragmenta on (unused memory between allocated
spaces).
o Allows non-con guous memory alloca on (pages of a process can be
anywhere in RAM).
How Paging Works?
SQL
Q1)
1. Display the details of packages for which the development cost has been recovered.
SELECT *
FROM SOFTWARE
FROM SOFTWARE
Computer Networks
Q1)
As a data packet moves from the upper to lower layers in the OSI (Open Systems
Interconnec on) model, the following process occurs:
ti
ti
ft
ti
ft
fi
ff
Encapsula on Process:
Each layer adds its own header (and some mes trailer) to the data received from the layer
above before passing it down to the next layer.
Step-by-step process:
1. Applica on Layer (Layer 7) → The user interacts with an applica on (e.g., web
browser, email client).
2. Presenta on Layer (Layer 6) → Data is forma ed, encrypted, or compressed if
needed.
3. Session Layer (Layer 5) → Manages session crea on and termina on.
4. Transport Layer (Layer 4) → Adds a TCP/UDP header to ensure reliable (TCP) or fast
(UDP) delivery.
5. Network Layer (Layer 3) → Adds an IP header with source and des na on IP
addresses.
6. Data Link Layer (Layer 2) → Adds a MAC header and trailer (Frame) with physical
addresses.
7. Physical Layer (Layer 1) → Converts the data into electrical, op cal, or radio signals
for transmission over the network.
Example (Sending an HTTP request from a web browser):
• Applica on Layer: Sends "GET /index.html" (HTTP request).
• Transport Layer: Adds TCP header (e.g., Port 80 for HTTP).
• Network Layer: Adds IP header (e.g., Source IP: 192.168.1.2, Des na on IP: 8.8.8.8).
• Data Link Layer: Adds MAC header & trailer (e.g., Source MAC: A1:B2:C3:D4:E5:F6,
Des na on MAC: X1:Y2:Z3:W4:V5:U6).
• Physical Layer: Converts the frame into electrical signals or radio waves.
This process is known as Encapsula on and ensures that data reaches its des na on
correctly over the network.
Q2)
· Connec on Type
• TCP (Transmission Control Protocol) is a connec on-oriented protocol, meaning it
establishes a reliable connec on before data transfer begins.
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
tt
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
ti
• UDP (User Datagram Protocol) is connec onless, meaning data is sent without
se ng up a dedicated connec on.
· Reliability
• TCP is reliable as it ensures data is delivered correctly and in order. It retransmits lost
packets and waits for acknowledgments.
• UDP is unreliable since it does not guarantee data delivery, order, or retransmission
of lost packets.
· Error Checking
• TCP performs extensive error checking, acknowledgments, and retransmission to
ensure data integrity.
• UDP has minimal error checking and does not request retransmission if data is lost.
· Speed
• TCP is slower due to its reliability mechanisms, such as error checking,
acknowledgments, and conges on control.
• UDP is faster since it does not wait for acknowledgments or retransmit lost packets.
· Order of Data
• TCP ensures data arrives in the correct order using sequence numbers.
• UDP does not guarantee the order of data arrival, as packets may arrive out of
sequence.
· Usage
• TCP is used for applica ons where data integrity and reliability are important, such as
web browsing (HTTP/HTTPS), le transfer (FTP), and email (SMTP).
• UDP is used in applica ons where speed is more important than reliability, such as
video streaming, VoIP, gaming, and real- me communica on.
· Header Size
• TCP has a larger header (20-60 bytes) due to extra informa on for reliability and ow
control.
• UDP has a smaller header (8 bytes), making it more e cient for quick data
transmission.
· Flow Control
• TCP supports ow control and conges on control, which helps manage network
tra c and prevent packet loss.
tti
ffi
fl
ti
ti
fi
ti
ti
ti
ti
ti
ffi
ti
ti
fl
• UDP does not have ow control, making it more suitable for high-speed applica ons.
#include <iostream>
#include <vector>
int n = arr.size();
lis[i] = lis[j] + 1;
int maxLength = 0;
return maxLength;
}
fi
fl
fi
ti
ti
ti
int main() {
int n;
cin >> n;
vector<int> arr(n);
return 0;
Q2)
#include <iostream>
int totalRows = 2 * n - 1;
char le ers[n];
le ers[i] = 'a' + i;
int main() {
int n;
cin >> n;
printPa ern(n);
return 0;
}
tt
tt
tt