0% found this document useful (0 votes)
6 views109 pages

CSE357 WorKsheets

Uploaded by

ankitwww0306
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)
6 views109 pages

CSE357 WorKsheets

Uploaded by

ankitwww0306
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/ 109

OS WORKSHEET

Worksheet 1
1. Which of the following statements about the kernel in an operating system is true?
A. The kernel is responsible for managing user interfaces and applications.
B. The kernel is a separate program that runs only when the user interacts with the system.
C. The kernel is the core component that manages hardware resources and provides essential services.
D. The kernel is primarily responsible for handling user-level processes and multitasking.
2. What is the primary purpose of an operating system?
A. Managing hardware resources
B. Running user applications
C. Providing a graphical user interface
D. All of the above
3. Which of the following is not a function of the operating system?
A. Process management
B. File management
C. Application development
D. Memory management
4. What does a system call provide in an operating system?
A. User interface
B. A way for programs to request services from the operating system
C. Hardware resources
D. File management
5. Which component of the operating system handles communication between hardware and software?
A. Scheduler
B. Kernel
C. File Manager
D. Shell
6. What is the significance of the bootstrap program in the boot process of an operating system?
A. Manages user interfaces
B. Loads the kernel into memory
C. Allocates memory to applications
D. Handles peripheral devices
7. What does the fork system call do in an operating system?
A. Allocates memory for a new process
B. Creates a new process by duplicating the calling process
C. Terminates the calling process
D. Reads data from a file
8. What is the return value of the fork system call in the parent process?
A. -1
B. 0
C. Process ID (PID) of the child process
D. Process ID (PID) of the parent process
9. In the context of operating systems, which statement accurately describes a characteristic of microkernels?
A. Microkernels generally have a larger kernel size compared to monolithic kernels.
B. Microkernels move most of the operating system services into kernel space.
C. Microkernels provide higher performance due to reduced inter-process communication.
D. Microkernels emphasize minimalism, with essential services implemented as user-level processes.
10. What is the primary goal of multiprogramming in operating systems?
A. To improve the performance of a single program
B. To execute multiple programs concurrently for better CPU utilization
C. To simplify the user interface
D. To reduce the size of the operating system

Subjective Questions
1. Compare and contrast the characteristics of real-time operating systems (RTOS) and general-purpose operating
systems.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Discuss the differences between microkernels and monolithic kernels. Evaluate the strengths and weaknesses of
each architecture and provide examples of operating systems that use each type of kernel.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Describe the booting process of an operating system. Include the role of the bootloader and the initialization of
the kernel.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Explain the role of device drivers in an operating system and how they facilitate communication between software
and hardware.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Describe the purpose and functionality of system calls in an operating system. Provide examples of common
system calls.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Explain the concept of interrupts in the context of computer systems.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
Worksheet 2

Multiple Choice Questions


1: What is a process in the context of operating systems?
A. A program in execution
B. A system utility
C. A file stored on the hard disk
D. An input device
2: What is the purpose of a process control block (PCB)?
A. To store the program’s source code
B. To manage file I/O operations
C. To store information about a process
D. To allocate memory to a process
3: What is CPU scheduling in an operating system?
A. Allocating memory to processes
B. Assigning tasks to peripheral devices
C. Determining the order in which processes are executed by the CPU
D. Managing file systems
4: Which scheduling algorithm aims to minimize the turnaround time?
A. First-Come-First-Serve (FCFS)
B. Shortest Job Next (SJN)
C. Round Robin (RR)
D. Priority Scheduling
5: What is a thread in the context of multitasking?
A. A process in execution
B. A lightweight process sharing the same address space
C. A file in use by the operating system
D. A system utility for file management
6: In Round Robin CPU scheduling, what does the term ”time quantum” refer to?
A. The total time required to complete a process.
B. The amount of time a process is allowed to run in one continuous time slot.
C. The time taken by the CPU to switch between processes.
D. The priority assigned to each process in the ready queue.
7: Which of the following statements accurately distinguishes between user-level threads (ULTs) and kernel-level
threads (KLTs)?
A. User-level threads are managed by the operating system kernel, while kernel-level threads are managed by
user-level libraries.
B. User-level threads are more efficient in terms of context switching compared to kernel-level threads.
C. Kernel-level threads are visible to the operating system scheduler, allowing for better utilization of multiple
processors.
D. User-level threads provide stronger isolation between threads, preventing interference with each other.
8: Which of the following is a characteristic of user-level threads (ULTs)?
A. Better responsiveness to system events.
B. Lower context-switching overhead.
C. Directly visible to the operating system scheduler.
D. Kernel support is required for their management.
9: In a system with user-level threads, if one thread in a process is blocked, what happens to the other threads in
the same process?
A. All threads in the process are blocked.
B. Other threads continue executing independently.
C. The process is terminated.
D. A system interrupt is triggered.
10: Consider a system with three processes (P1, P2, and P3) scheduled using the First-Come-First-Serve (FCFS)
scheduling algorithm. The arrival time and burst time for each process are as follows:

Process Arrival Time Burst Time


P1 0 6
P2 2 4
P3 4 8
If the waiting time is defined as the total time a process spends waiting in the ready queue, what is the waiting
time for process P2?
A. 4 units of time
B. 5 units of time
C. 7 units of time
D. 9 units of time

Subjective Questions
1. Explain the concept of a process in operating systems. Highlight the key components of a process and the role
they play in program execution.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Describe the life cycle of a process. Discuss the transitions between different states and the events triggering
these transitions.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Compare and contrast preemptive and non-preemptive CPU scheduling algorithms. Provide examples of sce-
narios where each type of algorithm is beneficial.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Define the term ”thread” in the context of multitasking. Explain the advantages of using threads over processes
and how they contribute to parallelism.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Explain the difference between user-level threads (ULTs) and kernel-level threads (KLTs). Discuss the advan-
tages and disadvantages of each type and scenarios where they are most suitable.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Consider a system with three processes scheduled using the Round Robin (RR) scheduling algorithm. The time
quantum is set to 4 milliseconds. The arrival time and burst time for each process are as follows:

Process Arrival Time Burst Time


P1 0 8
P2 2 5
P3 4 6
If the processes follow the FCFS order when multiple processes have the same remaining time, what is the
turnaround time of process P2?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
Worksheet 3

Multiple Choice Questions


1: What is the primary goal of synchronization in operating systems?
A. Minimizing memory usage
B. Ensuring fair CPU scheduling
C. Coordinating the execution of multiple processes
D. Enhancing disk I/O performance
2: In synchronization, what does the term ”race condition” refer to?
A. A competition between processes
B. A condition of deadlock
C. Undesirable interference between concurrent operations
D. A priority inversion scenario
3: What is the critical section problem in concurrent programming?
A. Ensuring all processes run concurrently
B. Managing access to shared resources
C. Coordinating process termination
D. Balancing system load
4: Which condition must be satisfied for a solution to the critical section problem to be effective?
A. Mutual exclusion
B. Starvation
C. Deadlock
D. Priority inversion
5: What is a deadlock in the context of operating systems?
A. Simultaneous execution of multiple processes
B. Inability to acquire necessary resources and proceed
C. Efficient scheduling of processes
D. Fair distribution of CPU time
6: Which of the following is a classic synchronization problem that involves two processes sharing a single, finite-
sized buffer?
A. Readers-Writers Problem
B. Dining Philosophers Problem
C. Producer-Consumer Problem
D. Banker’s Algorithm
7: What is the purpose of a semaphore in process synchronization?
A. Identify the priority of a process
B. Ensure mutual exclusion among processes
C. Schedule processes based on their arrival time
D. Allocate memory to processes
8: In Banker’s algorithm, what information does the ”maximum need matrix” represent?
A. The maximum number of resources that each process may request.
B. The current allocation of resources to each process.
C. The total available resources in the system.
D. The resources released by each process.
9: What does Banker’s algorithm consider when deciding to grant or deny a resource request?
A. Only the maximum need of the process.
B. Only the available resources in the system.
C. Both the maximum need and available resources.
D. Only the current allocation of the process.
10: In an operating system, which of the following represents a valid sequence of process state transitions?
A. Ready → Running → Blocked → Ready → Terminated
B. Blocked → Terminated → Running → Ready → Blocked
C. Running → Ready → Terminated → Blocked → Ready
D. Ready → Blocked → Running → Terminated → Ready

Subjective Questions
1. Explain the concept of synchronization in operating systems. Why is it essential for concurrent program execu-
tion, and what challenges does it address?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Define the critical section problem and explain why it is a fundamental concern in concurrent programming.
Describe the requirements that a solution to the critical section problem must satisfy.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Define deadlock in the context of operating systems. Discuss the necessary conditions for deadlock occurrence
and how they contribute to the formation of a deadlock.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Explain the difference between deadlock prevention and deadlock avoidance strategies.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. A system has three processes with the following burst times (in milliseconds) and priorities:

Process Burst Time Priority


P1 6 3
P2 4 1
P3 8 2

Assuming Priority scheduling algorithm, calculate the average waiting time and average turnaround time.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Consider a system with five processes (P 1, P 2, P 3, P 4, and P 5) and three resource types (A, B, and C). The
current allocation matrix, maximum demand matrix, and available matrix are given as follows:
Current Allocation Matrix:
A B C
P1 1 2 2
P2 3 1 3
P3 1 3 5
P4 4 2 2
P5 2 4 2
Maximum Demand Matrix:
A B C
P1 3 4 3
P2 6 2 5
P3 3 6 8
P4 7 4 7
P5 5 8 3
Available Matrix: [ ]
A B C
2 1 3
Using Banker’s algorithm, determine if the system is in a safe state. If it is, provide a safe sequence; otherwise,
explain why the system is not safe.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
Worksheet 4

Multiple Choice Questions


1: Which of the following is a type of volatile memory?
A. ROM
B. RAM
C. SSD
D. Hard Disk
2: What is the purpose of a page table in a paging memory management scheme?
A. To store page faults
B. To translate virtual addresses to physical addresses
C. To manage cache memory
D. To allocate memory to processes
3: Which file system is commonly used in Linux operating systems?
A. NTFS
B. FAT32
C. ext4
D. HFS+
4: Which of the following is a characteristic of SSD (Solid State Drive) as compared to traditional HDD (Hard
Disk Drive)?
A. Magnetic storage
B. Mechanical components
C. Slower access times
D. No moving parts
5: Which disk scheduling algorithm uses a queue to organize pending requests and serves them in the order they
are received?
A. FCFS (First-Come-First-Serve)
B. SSTF (Shortest Seek Time First)
C. C-SCAN (Circular SCAN)
D. LOOK
6: What is thrashing in the context of memory management?
A. Excessive page faults leading to degraded performance
B. Efficient use of virtual memory
C. Rapid data transfer between RAM and cache
D. Successful page replacement
7: Which disk scheduling algorithm aims to minimize the total movement of the disk arm by choosing the request
that is closest to the current arm position?
A. First-Come-First-Serve (FCFS)
B. Shortest Seek Time First (SSTF)
C. Circular SCAN
D. LOOK
8: What is the primary advantage of using demand paging in virtual memory systems?
A. Reduced page faults
B. Increased RAM capacity
C. Faster data retrieval
D. Simplicity of implementation
9: Which of the following is a primary purpose of RAID technology?
A. Disk Encryption
B. Improved File Compression
C. Increased Data Redundancy and Fault Tolerance
D. Enhanced Disk Formatting
10: In a paging system, if the logical address space is divided into pages of size 212 bytes and the physical memory
is divided into frames of the same size, how many bits are needed for the page number and the offset within the
page, respectively, for a 32-bit logical address?
A. 20 bits for page number, 12 bits for offset
B. 10 bits for page number, 22 bits for offset
C. 12 bits for page number, 20 bits for offset
D. 14 bits for page number, 18 bits for offset

Subjective Questions
1. Explain the working principles of the Least Recently Used (LRU) page replacement algorithm. Discuss its
advantages and potential drawbacks. Can you suggest scenarios where LRU might perform exceptionally well
or poorly?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Explain the structure of a disk in detail, including the terms like tracks, sectors, and cylinders. How do these
components contribute to efficient data storage and retrieval on a disk?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Discuss the advantages and disadvantages of disk partitioning in terms of organization and performance. How
does partitioning contribute to disk management and data security in an operating system?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Consider the following scenario:
Page Reference String: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Number of Page Frames: 3
Use the Least Recently Used (LRU) page replacement algorithm to calculate the number of page faults.
LRU Page Replacement Algorithm:
Initially, all page frames are empty.
When a page is referenced:
If the page is already in a frame, it becomes the most recently used.
If the page is not in any frame, a page fault occurs, and the least recently used page is replaced.
Question:
Calculate the number of page faults using the LRU page replacement algorithm for the given page reference
string and a total of 3 page frames.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Provide an overview of what RAID is and describe at least three common RAID levels (e.g., RAID 0, RAID 1,
RAID 5).
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

....................................................................................................
3.10 Frequently Asked Interview Questions
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Consider a disk with 100 tracks numbered from 0 to 99. The current position of the disk arm is at track 50. The
following disk access requests are given:

45, 60, 20, 90, 10

Assuming the SSTF (Shortest Seek Time First) disk scheduling algorithm, calculate the total head movement
using the current disk arm position.
Solution Steps:
(a). Calculate the absolute seek time for each request by finding the absolute difference between the current
position and the requested track.
(b). Select the request with the shortest seek time and move the disk arm to that track.
(c). Repeat steps 1 and 2 until all requests are processed, and calculate the total head movement.
Provide the final total head movement as the answer.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

16
3.10 Frequently Asked Interview Questions

NETWORK WORKSHEET
Multiple Choice Questions Worksheet 1
1. 1. How many bits are in an IPv4 and IPv6 address?
A. 32 and 64 bits
B. 64 and 32 bits
C. 32 and 128 bits
D. 32 and 256 bits
2. What is the primary purpose of a computer network?
A. To enhance computer aesthetics
B. To facilitate communication and resource sharing
C. To replace standalone computers
D. To generate electricity
3. What is the OSI model used for in computer networks?
A. To design computer hardware
B. To standardize network protocols and communication
C. To analyze data signals
D. To create computer games
4. Which of the following is a network topology where each device is connected to a central hub?
A. Mesh
B. Bus
C. Star
D. Ring
5. What is the purpose of a router in a computer network?
A. To connect devices within the same local area network (LAN)
B. To connect different networks and manage data traffic between them
C. To display network statistics
D. To provide power to network devices
6. In digital communication, what is a bit?
A. A group of bytes
B. A binary digit, representing 0 or 1
C. A unit of time
D. A type of cable
7. Which modulation technique is commonly used in wireless communication?
A. Amplitude Modulation (AM)
B. Frequency Modulation (FM)
C. Binary Modulation (BM)
D. Phase Modulation (PM)
8. What is the purpose of a firewall in a computer network?
A. To protect against unauthorized access and malicious activities
B. To enhance network speed
C. To create a physical barrier between devices
17
D. To filter internet content 2.14 Worksheets

18
2.14 Worksheets

9. Which network type is characterized by limited geographical coverage, such as within a single building or cam-
pus?
A. Local Area Network (LAN)
B. Wide Area Network (WAN)
C. Metropolitan Area Network (MAN)
D. Personal Area Network (PAN)
10. What is the purpose of DNS (Domain Name System) in computer networks?
A. To encrypt data transmissions
B. To convert domain names to IP addresses
C. To manage network hardware
D. To monitor network performance

Subjective Questions
1. Explain the importance of the OSI model in the context of computer networks
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Compare and contrast the star and mesh network topologies, highlighting their advantages and disadvantages.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Describe the role of a router in a computer network and how it contributes to efficient data transmission.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

19
2.14 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Discuss the key functions of a firewall in ensuring network security.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Explain the concept of DNS (Domain Name System) and its significance in simplifying internet communication.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Differentiate between analog and digital signals, providing examples of each and discussing their applications
in communication systems.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

20
2.14 Worksheets

....................................................................................................

21
2.14 Worksheets

Worksheet 2

Multiple Choice Questions


1: In which network topology does each device have a direct connection to every other device?
A. Bus
B. Ring
C. Mesh
D. Star
2: What is a characteristic of a ring topology?
A. Easy to troubleshoot
B. Redundant pathways
C. Centralized control
D. Unidirectional data flow
3: Which layer of the OSI model is responsible for error detection and correction?
A. Physical Layer
B. Data Link Layer
C. Network Layer
D. Transport Layer
4: Which protocol is commonly used for secure data transmission over the internet?
A. HTTP
B. FTP
C. TCP/IP
D. HTTPS
5: What is the primary advantage of a bus topology?
A. High fault tolerance
B. Simple to install and cost-effective
C. Centralized control
D. Redundant pathways
6: Which network model is based on a layered architecture and consists of four layers Application, Transport,
Network, and Link?
A. TCP/IP model
B. OSI model
C. Internet model
D. Ethernet model
7: What is a characteristic of a wireless transmission medium?
A. Limited mobility
B. High security risks
C. Requires physical cables
D. Allows for flexible device mobility
8: What is the purpose of the TCP (Transmission Control Protocol) in the TCP/IP protocol suite?
A. To ensure the physical connection between devices
B. To provide error detection and correction
C. To manage network traffic
D. To establish a reliable, connection-oriented communication
9: In which transmission medium do data signals travel in the form of light pulses?

22
2.14 Worksheets

A. Twisted Pair Cable


B. Fiber Optic Cable
C. Coaxial Cable
D. Wireless Transmission
10: Which protocol is responsible for addressing and routing data packets across a network?
A. ICMP
B. IP
C. UDP
D. SMTP

Subjective Questions
1. Explain the advantages and disadvantages of a star topology in computer networks.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Discuss the characteristics of a bus topology and elaborate on its suitability for specific network environments.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Compare and contrast the OSI model and the TCP/IP model, highlighting their similarities and differences.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

23
2.14 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Describe the role of the TCP (Transmission Control Protocol) in ensuring reliable communication within the
TCP/IP protocol suite.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Discuss the importance of the transmission medium in network communication, focusing on the differences
between wired and wireless transmission.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Explain the role of protocols in computer networks, providing examples and discussing their significance in
facilitating communication between devices.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

24
2.14 Worksheets

....................................................................................................

25
2.14 Worksheets

Worksheet 3

Multiple Choice Questions


1: Which model is used to standardize network protocols and facilitate communication in computer networks?
A. OSI model
B. TCP/IP model
C. Internet model
D. Ethernet model
2: How many layers does the OSI model have?
A. Five
B. Six
C. Seven
D. Eight
3: In the TCP/IP model, which layer is responsible for logical addressing and routing of data packets?
A. Network Layer
B. Data Link Layer
C. Application Layer
D. Transport Layer
4: Which protocol is commonly associated with the Application Layer of the TCP/IP model?
A. HTTP
B. TCP
C. IP
D. UDP
5: What is the primary purpose of the Presentation Layer in the OSI model?
A. Encryption and decryption of data
B. Logical addressing
C. Data link establishment
D. Error detection and correction
6: In the TCP/IP model, which layer is responsible for establishing, maintaining, and terminating connections
between devices?
A. Transport Layer
B. Network Layer
C. Data Link Layer
D. Application Layer
7: What is the function of the Transport Layer in the TCP/IP model?
A. Logical addressing
B. Error detection and correction
C. End-to-end communication and data segmentation
D. Physical transmission of data
8: Which layer of the OSI model deals with the physical transmission of data bits over the network medium?
A. Physical Layer
B. Data Link Layer
C. Transport Layer
D. Network Layer
9: Which protocol is responsible for dynamically assigning IP addresses to devices on a network?

26
2.14 Worksheets

A. ICMP
B. DHCP
C. TCP
D. DNS
10: What is the primary advantage of the TCP/IP model over the OSI model in practical implementations?
A. Simplicity and widespread adoption
B. Robust security features
C. Better error detection mechanisms
D. Real-time data processing capabilities

Subjective Questions
1. Explain the key differences between the OSI model and the TCP/IP model, emphasizing their structures and
functionalities.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Describe the role of the Application Layer in the TCP/IP model, providing examples of protocols and applications
associated with this layer.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Discuss the functions of the Transport Layer in the TCP/IP model and how it ensures reliable communication
between devices.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

27
2.14 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Explain the significance of the Presentation Layer in the OSI model and its role in data exchange between different
systems.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Describe the working of the Internet Control Message Protocol (ICMP) and its role in the TCP/IP model.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Discuss the importance of the Dynamic Host Configuration Protocol (DHCP) in the context of the TCP/IP model
and network configuration.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

28
2.14 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................

29
2.14 Worksheets

Worksheet 4

Multiple Choice Questions


1: What is the primary purpose of subnetting in a computer network?
A. To divide a network into smaller, more manageable sub-networks
B. To increase the overall network speed
C. To connect two different types of networks
D. To encrypt data transmissions
2: In subnetting, what is the purpose of a subnet mask?
A. To identify the network portion of an IP address
B. To determine the host portion of an IP address
C. To encrypt data during transmission
D. To assign dynamic IP addresses
3: What is the primary function of a router in a computer network?
A. To assign IP addresses to devices
B. To connect devices within the same LAN
C. To forward data packets between different networks
D. To provide physical connectivity to devices
4: Which routing algorithm considers the number of hops to reach the destination?
A. Dijkstra’s algorithm
B. Bellman-Ford algorithm
C. Link-state routing
D. Distance-vector routing
5: What is the purpose of the default gateway in a computer network?
A. To provide a backup route for data packets
B. To forward data packets to devices within the same network
C. To connect the network to the internet or another network
D. To filter incoming data packets
6: In CIDR (Classless Inter-Domain Routing), what is represented by the prefix length?
A. The number of hosts in the network
B. The size of the network address
C. The number of subnets
D. The network’s geographic location
7: What is the advantage of using Variable Length Subnet Masking (VLSM) in subnetting?
A. It simplifies network management
B. It allows for more efficient use of IP addresses
C. It enhances network security
D. It provides faster data transmission
8: In routing, what is the purpose of RIP (Routing Information Protocol)?
A. To determine the best path based on link costs
B. To broadcast routing information to all devices in the network
C. To establish a secure connection between networks
D. To assign IP addresses dynamically
9: What is the primary benefit of using a hierarchical routing structure?
A. Increased network complexity

30
2.14 Worksheets

B. Reduced routing table size


C. Slower data transmission
D. Enhanced security features
10: What is the role of NAT (Network Address Translation) in routing?
A. To convert private IP addresses to public IP addresses
B. To assign IP addresses to devices dynamically
C. To encrypt data during transmission
D. To filter incoming data packets

Subjective Questions
1. Explain the concept of subnetting and its advantages in managing large computer networks.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Describe the role of a subnet mask in IP addressing and how it influences the division of network and host
portions.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Discuss the functions of a router in a computer network, emphasizing its role in forwarding data packets between
different networks.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

31
2.14 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Compare and contrast distance-vector routing and link-state routing algorithms, highlighting their characteristics
and applications.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Explain the significance of a default gateway in a computer network and its role in facilitating communication
between networks.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Describe the benefits and challenges associated with Variable Length Subnet Masking (VLSM) in subnetting.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

32
2.14 Worksheets

....................................................................................................

33
2.14 Worksheets

Worksheet 5

Multiple Choice Questions


1: Which protocol is commonly used for retrieving emails from a mail server?
A. HTTP
B. SMTP
C. POP
D. FTP
2: What is the primary function of the HTTP protocol?
A. Sending emails
B. Transferring files
C. Retrieving web pages
D. Resolving domain names
3: Which protocol is responsible for the transfer of files between a client and a server?
A. SMTP
B. HTTP
C. FTP
D. DNS
4: What is the role of SMTP (Simple Mail Transfer Protocol) in email communication?
A. Retrieving emails
B. Sending emails
C. Storing emails
D. Filtering emails
5: Which protocol is used for translating human-readable domain names into IP addresses?
A. DHCP
B. DNS
C. FTP
D. POP
6: What is the purpose of the DNS (Domain Name System) protocol?
A. Transferring files
B. Resolving domain names to IP addresses
C. Sending emails
D. Assigning IP addresses dynamically
7: Which protocol is commonly used for the dynamic assignment of IP addresses to devices on a network?
A. DNS
B. DHCP
C. FTP
D. HTTP
8: What does FTP (File Transfer Protocol) primarily facilitate?
A. Email communication
B. Dynamic IP assignment
C. File transfer between a client and a server
D. Web page retrieval
9: Which protocol allows clients to retrieve emails from a mail server and supports multiple devices syncing with
the server?

34
2.14 Worksheets

A. HTTP
B. SMTP
C. POP
D. IMAP
10: What is the primary function of the DHCP (Dynamic Host Configuration Protocol) in a network?
A. Translating domain names to IP addresses
B. Assigning IP addresses dynamically to devices
C. Transferring files between clients and servers
D. Filtering web content

Subjective Questions
1. Explain the roles of SMTP, POP, and IMAP in the process of sending and receiving emails.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Describe the functions of DNS and how it contributes to the efficient functioning of the internet.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Discuss the key features and use cases of the FTP (File Transfer Protocol) in network communication.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

35
2.14 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Explain the purpose of DHCP and how it simplifies the management of IP addresses in a network.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Compare and contrast HTTP and FTP, highlighting their respective roles in web communication and file transfer.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Discuss the significance of DNS in the context of internet security and privacy.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
7. Describe the process of email retrieval using POP and IMAP, highlighting their differences and advantages.
....................................................................................................

36
2.14 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
8. Explain how DHCP dynamically assigns IP addresses to devices in a network and its role in preventing IP
conflicts.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

37
3.11 Worksheets

DBMS WORKSHEET
3.7 Worksheets

Worksheet 1

Multiple Choice Questions


1. What is an example of RDBMS?
A. SQL
B. MS SQL Server
C. IBM DB2
D. All of the above
2. What is TRUE about RDBMS?
A. Representation of data is done in form of Column.
B. Every table contains its own candidate key.
C. There is a collection of organized set of tables.
D. It is uncommonly used database.
3. A small entity that contains the specific information of each record in the table is known as ...........
A. Row
B. Column
C. Field
D. Record
4. An operation is part of a transaction if it is ........... related.
A. Logically
B. Analytically
C. Reasonably
D. None
5. What is the purpose of the UNION operator in SQL?
A. It combines the results of two or more SELECT statements.
B. It performs a pattern match on a string.
C. It retrieves the maximum value in a column.
D. It filters the rows returned by the SELECT statement.
6. Which SQL command is used to update existing data in a database table?
A. MODIFY
7. By normalizing relations or sets of relations, one minimizes
.

A. Data
B. Fields
C. Redundancy
D. Database
8. In addition to removing undesirable characteristics, normalization also eliminates anomalies.

A. Insert
B. Update
C. Delete
D. All of the above
9. To access the contents of the database,
A. Single B. Two
38
userperforms
transactions. 3.11 Worksheets

39
3.11 Worksheets

C. Three
D. Multiple
10. A common approach to normalization is to thelargertableintosmallertablesandlinkthemtogetherbyusingrelationships.

A. Add
B. Subtract
C. Multiply
D. Divide

Subjective Questions
1. Define SQL?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. List out the Numeric Data and character Data Types in MySQL?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. List out the commands under DML and their syntax.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

40
3.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
4. Based on the given table “SALE” answer the question (i) and (ii)

PRODID QTY RATE AMOUNT


1 10 100 1000
2 5 50 250
3 10 20 200
4 20 100 2000

(i) Can we take QTY column of the above table as Primary Key? If no give reason?
(ii) Which column is best suitable for applying Primary Key?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. What is referential Integrity? How it is implemented in any table?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Table T1 contains 10 Rows and 4 Columns; Table T2 contains 20 Rows and 3 Columns. After performing
Cartesian product of T1 and T2, what will be the degree and cardinality of Resultant output?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

41
3.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

42
3.11 Worksheets

Worksheet 2

Multiple Choice Questions


1: What For each attribute of a relation, there is a set of permitted values, called the of that attribute.
A. Dictionaries
B. Domain
C. Directory
D. Relation
2: What does NULL value specify in RDBMS?
A. The field is set to Zero
B. The field is set to Infinite
C. The field is left blank
D. The field is set to Whole Number
3: RDBMS applications stores data
.
A. In tabular form
B. As file
C. Both a and b
D. None of the above
4: What is the purpose of the WHERE clause in SQL?
A. It specifies the columns to be retrieved.
B. It filters the rows returned by the SELECT statement.
C. It orders the results in ascending or descending order.
D. It creates a new table.
5: In what format data is stored in DBMS?
A. Hierarchal form
B. Navigational form
C. Both A. and B.
D. None of the above
6: Redundancy is reduced in a database table by using the f orm.
A. Abnormal
B. Normal
C. Special
D. None
7: X is read from a database and stored in a buffer in main memory with the operation.

A. Read
B. Write
C. Commit
D. Rollback
8: In practical applications, how many types of Normal Forms are there?
A. 3
B. 4
C. 5
D. 6
9: In DBMS –
A. There is no relation between the tables

43
3.11 Worksheets

B. There is relation between the tables


C. There is custom relation between the databases
D. There is data value relation between the databases
10: Which of the following is not a type of Normal Form?
A. 1NF
B. 2NF
C. 3NF
D. 10NF

Subjective Questions
1. Write any 2 characteristics of a Relation.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. What is alternate Key?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. From the following Tables: Table 3.2 (EMP) AND Table 3.3 (JOB) answer the questions

Table 3.2: Employee Table


EMPNO ENAME JOB SALARY DEPTNO
E001 PETER ADMIN 4500 10
E002 SCOTT SALESMAN 3500 20
E003 ALBERT CLERK 2800 10
E004 RUSSEL CLERK 2900 40

(a). Identify Primary Key from both the tables

44
3.11 Worksheets

Table 3.3: Job Table


DEPTNO DNAME DLOCATION DHEAD
10 PETER ADMIN 4500
20 SCOTT SALESMAN 3500
30 ALBERT CLERK 2800
40 RUSSEL CLERK 2900

(b). Identify the foreign key column in the table EMP


(c). Can we delete the record of PETER from table JOB?
(d). If not, give a reason
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
Table 3.4: Visitor Table
VisitorID VisitorName ContactNumber
V001 ANAND 9898989898
V002 AMIT 9797979797
V003 SHYAM 9696969696
V004 MOHAN 9595959595

4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Mr. Peter created a table in MySQL. later on, he found that there should have been another column in the table.
Which command should he use to add another column to the table.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

45
3.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Give 1 example for aggregate functions (count, max, min, sum).
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

46
3.11 Worksheets

Worksheet 3

Multiple Choice Questions


1: What is the purpose of the GROUP BY clause in SQL?
A. It filters the rows returned by the SELECT statement.
B. It groups rows with the same values into summary rows.
C. It orders the results in ascending or descending order.
D. It specifies the columns to be retrieved.
2: ........... is used to permanently save the work.
A. Read
B. Write
C. Commit
D. Rollback
3: Distributed database is supported by -
A. RDBMS
B. DBMS
C. Both RDBMS DBMS
D. Neither RDBMS nor DBMS
4: RDBMS supports ........... users.
A. One
B. Two
C. None
D. Multiple
5: An undo operation is called a .........
A. Rollback
B. Commit
C. Write
D. Read
6: What is the purpose of the DISTINCT keyword in SQL?
A. It filters the rows returned by the SELECT statement.
B. It specifies the columns to be retrieved.
C. It removes duplicate rows from the result set.
D. It orders the results in ascending or descending order.
7: How many properties of transactions are there?
A. 4
B. 5
C. 6
D. 7
8: DBMS deals with ........ amount of data.
A. Large
B. Small
C. Custom
D. None
9: What is the purpose of the UNION operator in SQL?
A. It combines the results of two or more SELECT statements.

47
3.11 Worksheets

B. It performs a pattern match on a string.


C. It retrieves the maximum value in a column.
D. It filters the rows returned by the SELECT statement.
10: “Address” field of a table cannot be a part of Primary key as it is likely to:
A. Dependent
B. Changed
C. Too Long
D. Not Changed

Subjective Questions
1. Observe the following table and answer the questions TABLE 3.5 VISITOR and answer the question (i) , (ii)
and (iii)

Table 3.5: Visitor Table


VisitorID VisitorName ContactNumber
V001 ANAND 9898989898
V002 AMIT 9797979797
V003 SHYAM 9696969696
V004 MOHAN 9595959595

(i) Write the name of most appropriate columns which can be considered as Candidate keys
(ii) Out of selected candidate keys, which one will be the best to choose as Primary Key?
(iii) What is the degree and cardinality of the table
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. What is the difference between Primary Key and Candidate Key?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

48
3.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
3. What are the differences between DELETE and DROP commands of SQL?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Write the SQL query to display price of products without duplicate values.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Write the SQL query to drop the table employee.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Write the SQL query to count the number of product with product code is PEN.
....................................................................................................
....................................................................................................
....................................................................................................

49
3.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

50
3.11 Worksheets

Worksheet 4

Multiple Choice Questions


1: There needs to be which of the following conditions for each nontrivial dependency of function X on function
Y for a relation to be in third normal form.
A. A super key is X.
B. Every element of Y is a part of some candidate key, i.e, Y is a prime attribute.
C. Either A or B
D. None of the above
2: What is TRUE about the First Normal Form (1NF)?
A. If a relation contains an atomic value, it will be 1NF.
B. A table attribute cannot contain more than one value, according to this rule.
C. A single-valued attribute can only be stored in it.
D. All of the above
3: What is TRUE about Isolation?
A. By using the data used during a transaction, the second transaction will not be able to use it until the first
has been executed.
B. The data item X cannot be accessed by any other transaction T2 until the transaction T1 is completed and
the data item X is used by the transaction T1.
C. It enforced the isolation property via its concurrency control subsystem.
D. All of the above
4: 2NF relations are those that are in 1NF with all the attribute types dependent on the ........ key.
A. Primary
B. Foreign
C. Composite
D. Alternate
5: When a relation contains an atomic value, it is a........ relation.
A. 1NF
B. 2NF
C. 3NF
D. BCNF
6: Transactions that are ........ do not expose all changes.
A. Committed
B. Rollbacked
C. Aborted
D. None of the above
7: What is TRUE about atomicity?
A. The transaction cannot be partially completed, since there is no midway.
B. In each transaction, either the entire transaction is executed or it is not.
C. Both A and B
D. None of the above
8: ....... states that all operations of a transaction must occur simultaneously; otherwise, the transaction will be
aborted.
A. Atomicity
B. Consistency

51
3.11 Worksheets

C. Isolation
D. Durability
9: In a database, prior to and after a transaction, properties are used to ensure .......
A. Consistency
B. Redundancy
C. Latency
D. Anonymity
10: Column names of any table must be:
A. Must be numeric type
B. Must be unique
C. Must be in sorted order
D. Must not be greater than 40 characters

Subjective Questions
1. Write the SQL query to update product code to PEC for product ID 1002.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Write short notes on following relational terms:
a. Tuple
b. Attribute
c. Relation
d. Domain
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Write the SQL query to display the maximum, minimum, average of price and total quantity of all products.

52
3.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Differentiate between DBMS and RDBMS. Discuss its different functions.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Observe the following Table 3.6 TEACHER and Table 3.7 TASK carefully and write the names of the RDBMS
operation out of (i) EQUI JOIN(ii) NATURAL JOIN(iii) SELECTION (iv)CARTESIAN PRODUCT, which
has been used to product the output as shown below. Also find the Degree and Cardinality of final RESULT.

Table 3.6: Teacher Information


Teacher_Code Teacher_Name Subject
T001 Amit Biology
T002 Anand Hindi
T003 Mohan Physics

Table 3.7: Task


Teacher Name Subject Task Name Completion Date
Amit Biology SBSB 30-04-2020
Amit Biology EBSB 31-05-2020
Amit Biology GANGA_QUEST 30-04-2020
Anand Hindi SBSB 30-04-2020
Anand Hindi EBSB 31-05-2020
Anand Hindi GANGA_QUEST 30-04-2020
Mohan Physics SBSB 30-04-2020
Mohan Physics EBSB 31-05-2020
Mohan Physics GANGA_QUEST 30-04-2020

53
3.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Write the SQL queries:
(a). Retrieve all tasks along with the respective teacher information.
(b). Find out the completion date and subject for each task.
(c). Get the teacher name, subject, and task name for tasks completed on 31-05-2020.
(d). List all tasks along with the teacher’s subject and the completion date.
(e). Find out the tasks completed by each teacher with their respective subjects.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

54
4.10 Frequently Asked Interview Questions

55
4.11 Worksheets

OOPS CONCEPT
WORKSHEET Worksheet 1

1. Which was the first purely object-oriented programming language developed?


A. Kotlin
B. SmallTalk
C. Java
D. C++
2. Why Java is Partially OOP language?
A. It allows code to be written outside classes
B. It supports usual declaration of primitive data types
C. It does not support pointers
D. It doesn’t support all types of inheritance
3. How many objects can be created from a single class?
A. Limited to 1
B. Fixed number depends on class
C. Unlimited
D. Depends on memory available
4. Which access specifier hides data members completely?
A. public
B. protected
C. private
D. default
5. What benefit does data abstraction provide?
A. Increased program size
B. Easier debugging
C. Simplified interface
D. Reduced performance
6. Which type of inheritance allows a class to inherit from multiple parent classes?
A. Single
B. Multi-level
C. Hierarchical
D. Multiple
7. What is the relationship between a subclass and its superclass?
A. Equal
B. Peers
C. Siblings
D. Is-a
8. Which principle allows different objects to respond to the same message differently?
A. Encapsulation
B. Abstraction

56
C. Inheritance 3.10 Frequently Asked Interview Questions
D. Polymorphism

57
3.10 Frequently Asked Interview Questions

9. What operator is commonly used to overload functions for polymorphism?


A. +
B. –
C. =
D. ?
10. What is the purpose of a constructor?
A. Destroy an object
B. Print object information
C. Initialize an object
D. Access object data

Subjective Questions
1. Write down about the four pillars of OOP.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Write suitable example which one differentiate between logical and type errors.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. When is it appropriate to use typedef in code?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

58
3.10 Frequently Asked Interview Questions

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. What are functions and how do they work with arguments and return values?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. How classes and objects are used represent real-world entities?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Explain the role of seekg(),seekp(),tellg(),tellp() function in the process of random access in a file.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

59
3.10 Frequently Asked Interview Questions

Worksheet 2

Multiple Choice Questions


1: What is the benefit of using interfaces?
A. Code flexibility
B. Data protection
C. Reduced memory usage
D. Standardized method definitions
2: Which keyword defines a class in Java?
A. class
B. object
C. type
D. structure
3: How is a method overloaded in Java?
A. By different return types
B. By different access modifiers
C. By different parameter lists
D. y different method names
4: What is the purpose of the Singleton design pattern?
A. Create multiple instances of an object
B. Ensure only one instance of an object exists
C. Share data between objects
D. Implement observer pattern
5: What is the ability of a program to manipulate its own source code called?
A. Debugging
B. Optimization
C. Metaprogramming
D. Compilation
6: Which among the following doesn’t come under OOP concept?
A. Data hiding
B. Message passing
C. Platform independent
D. Data binding
7: Which OOP concept is used to bundle data and methods that operate on the data?
A. Inheritance
B. Encapsulation
C. Polymorphism
D. Abstraction
8: What is the process by which one class acquires the properties of another class?
A. Composition
B. Polymorphism
C. Inheritance
D. Encapsulation
9: Which of the following is not true about polymorphism?
A. Helps in redefining the same functionality

60
3.10 Frequently Asked Interview Questions

B. Increases overhead of function definition always


C. It is feature of OOP
D. Ease in readability of program
10: Inheritance allows a class to:
A. Access methods of another class
B. Hide its methods
C. Extend and override methods of another class
D. None of the above

Subjective Questions
1. What are templates and how do they work with generic programming?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. How do member functions and constructors work within a class?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. How do we manage memory allocation and deallocation in C++?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

61
3.10 Frequently Asked Interview Questions

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Write a program to add two complex numbers using object as arguments.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Discuss the benefits of returning objects from functions.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Write down the scenario where we require user defined exceptions.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

62
3.10 Frequently Asked Interview Questions

Worksheet 3

Multiple Choice Questions


1: In OOP, what does the term ”polymorphism” mean?
A. One name, multiple forms
B. Many names, one form
C. No names, multiple forms
D. Multiple names, multiple forms
2: Which OOP concept allows a class to have multiple methods with the same name but different parameters?
A. Overloading
B. Overriding
C. Encapsulation
D. Polymorphism
3: What is the purpose of an abstract class in OOP?
A. To create objects
B. To provide a base class for other classes
C. To hide implementation details
D. To encapsulate data
4: Which keyword is used to implement abstraction in Java?
A. abstract
B. final
C. static
D. public
5: Which of the following is NOT a fundamental OOP concept?
A. Encapsulation
B. Abstraction
C. Modularity
D. Polymorphism
6: Which among the following can show polymorphism?
A. Overloading &&
B. Overloading «
C. Overloading ||
D. Overloading +=
7: Which OOP principle is violated if a subclass tries to override a final method of its superclass?
A. Encapsulation
B. Polymorphism
C. Inheritance
D. Abstraction
8: What is the purpose of the ”super” keyword in Java?
A. To call the superclass constructor
B. To call the subclass constructor
C. To create an object
D. To access static members of a class
9: What is the term for the ability of a class to have multiple methods with the same name but different implemen-
tations?

63
3.10 Frequently Asked Interview Questions

A. Overloading
B. Overriding
C. Polymorphism
D. Encapsulation
10: Which of the following is a correct syntax for implementing an interface in Java?
A. class MyClass implements MyInterface { }
B. class MyClass extends MyInterface { }
C. interface MyInterface implements MyClass { }
D. interface MyInterface extends MyClass { }

Subjective Questions
1. How overriding is different from the overloading?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Write a program to demonstrate friend function in C++.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Compare and contrast error, exception, warning and fault.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

64
3.10 Frequently Asked Interview Questions

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Write down a C++ program to implement function overloading.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Write down the role of abstract class in C++.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Write down the role and different manipulators in C++.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

65
3.10 Frequently Asked Interview Questions

Worksheet 4

Multiple Choice Questions


1: The copy constructors can be used to .......
A. Copy an object so that it can be passed to another primitive type variable
B. Copy an object for type casting
C. Copy an object so that it can be passed to a function
D. Copy an object so that it can be passed to a class
2: What is the purpose of the ”this” keyword in Java?
A. To create an object
B. To refer to the current object
C. To call the superclass constructor
D. To access static members of a class
3: Which among the following represents correct constructor?
A. –classname()
B. classname()
C. ()classname
D. ~classname()
4: What is the purpose of the ”try”, ”catch”, and ”finally” blocks in exception handling?
A. To handle errors and exceptions
B. To create objects
C. To define a class
D. To implement polymorphism
5: Which of the following is NOT a valid modifier for a class in Java?
A. public
B. private
C. protected
D. static
6: What is the purpose of the ”instanceof” operator in Java?
A. To check if an object is an instance of a particular class
B. To create an instance of a class
C. To check if a class is abstract
D. To check if a class is final
7: What is the difference between method overloading and method overriding?
A. Overloading is static binding, and overriding is dynamic binding
B. Overloading is dynamic binding, and overriding is static binding
C. Overloading has the same method name with different parameters, while overriding has the same method
signature
D. Overloading has the same method signature, while overriding has a different method signature
8: Which keyword is used to prevent a method from being overridden in Java?
A. static
B. final
C. abstract
D. private
9: What happens when an object is passed by reference?

66
3.10 Frequently Asked Interview Questions

A. Destructor is called at end of function


B. Destructor is called when called explicitly
C. Destructor is not called
D. Destructor is called when function is out of scope
10: How to overcome diamond problem?
A. Using seperate derived class
B. Using virtual keyword with same name function
C. Can’t be done
D. Using alias name

Subjective Questions
1. How string is used in C++? How can we create string object?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Write a C++ program involving a virtual function.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Draw a neat and clean sketch to show the different streams available in C++.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

67
3.10 Frequently Asked Interview Questions

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Differentiate between formatted and unformatted I/O. Discuss its different functions.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Write a program in C++ to extract character from a string.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. When do we need multiple catch blocks for a single try block? Give an example.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

68
5.11 Worksheets

DS WORKSHEET
Worksheet 1

Multiple Choice Questions


1. In a time-space tradeoff, time is................ proportional to space?
A. Directly
B. Indirectly
C. Equal
D. None of above
2. Which of the following is non-liner data structure?
A. Stacks
B. List
C. Strings
D. Trees
3. The operation of processing each element in the list is known as ............
A. sorting
B. merging
C. inserting
D. traversal
4. The elements of a linked list are stored?
A. In a structure
B. In an array
C. Anywhere the computer has space for them
D. In contiguous memory locations
5. The number K in A[k] is called .......... ?
A. Integer
B. Subscript
C. Superscript
D. Array
6. Which of following data structure is more appropriate for implementing quick sort iteratively?
A. Deque
B. Queue
C. Stack
D. Priority queue
7. Finding the location of a given item in a collection of items is called ..........
A. Discovering
B. Finding
C. Searching
D. Mining
8. The time complexity of quicksort is .........
A. O(n)
B. O(logn)

69
C. O(n2) 3.10 Frequently Asked Interview Questions
D. O(n logn)

70
3.10 Frequently Asked Interview Questions

9 ............. sorting is good to use when alphabetizing a large list of names.


A. Merge
B. Heap
C. Radix
D. Bubble
10. .............form of access is used to add and remove nodes from a queue.
A. LIFO, Last In First Out
B. FIFO, First In First Out
C. Both a and b
D. None of these

Subjective Questions
1. Define data structure and various types of data structures.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. What are the various types of searching used in Data Structures? Explain with one example?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. What is algorithm and complexity? What are the types of algorithm analysis?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

71
3.10 Frequently Asked Interview Questions

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Explain about Linked List Data Structure. What is doubly linked list?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. What are the advantages of Binary search over linear search?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. What is a difference between graph and tree?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

72
3.10 Frequently Asked Interview Questions

Worksheet 2

Multiple Choice Questions


1: The linear relationship between the elements represented by means of pointers is called .............
A. Arrays
B. Linked list
C. Both
D. None
2: Which of the following data structure is required to convert arithmetic expression in infix to its equivalent postfix
notation?
A. Queue
B. Linked list
C. Binary search tree
D. Stack
3: The number of edges in a complete graph of n vertices is
A. n(n+1)
2
B. n(n−1)
n2 2
C. 2
D. n
4: If two trees have same structure and but different node content, then they are called ........
A. Synonyms trees
B. Joint trees
C. Equivalent trees
D. Similar trees
5: Quick sort is also known as ..........
A. merge sort
B. tree sort
C. shell sort
D. partition and exchange sort
6: The total number of comparisons in a bubble sort is
A. O(n log n)

B. O(2n)

C. O(n2)

D. O(n)
7: New nodes are added to the .............of the queue.
A. Front
B. Back
C. Middle
D. Both A and B
8: The term push and pop is related to
A. Array
B. Lists

73
3.10 Frequently Asked Interview Questions

C. Stacks
D. Trees
9: Which of the following is an application of stack?
A. finding factorial
B. tower of Hanoi
C. infix to postfix
D. all of the above
10: The situation when in a linked list START=NULL is .........
A. Underflow
B. Overflow
C. Houseful
D. Saturated

Subjective Questions
1. What are the types of queues in Data Structures?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Explain quick sort with an example.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. What do you understand by Tower of Hanoi? Explain with one example.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

74
5.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. What is the difference between PUSH and POP with example.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. In which condition linked list is better than array and vice versa?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. How can AVL Tree be useful in all the operations as compared to Binary search tree.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

75
5.11 Worksheets

....................................................................................................

76
5.11 Worksheets

Worksheet 3

Multiple Choice Questions


1: Identify the data structure which allows deletions at both ends of the list but insertion at only one end.
A. Input restricted dequeue
B. Output restricted qequeue
C. Priority queues
D. Stack
2: To represent hierarchical relationship between elements, which data structure is suitable?
A. Deque
B. Priority
C. Tree
D. Graph
3: Minimum number of fields in each node of a doubly linked list is .............. ?
A. 2
B. 3
C. 4
D. None of above
4: Which of the following data structure can’t store the non-homogeneous data elements?
A. Arrays
B. Records
C. Pointers
D. Stacks
5: Which is the pointer associated with the availability list?
A. FIRST
B. AVAIL
C. TOP
D. REAR
6: Which of the following are two-way lists?
A. Grounded header list
B. Circular header list
C. Linked list with header and trailer nodes
D. List traversed in two directions
7: A parentheses checker program would be best implemented using
A. List
B. Queue
C. Stack
D. Any of the above
8: If two trees have same structure and node content, then they are called ..........
A. Synonyms trees
B. Joint trees
C. Equivalent trees
D. Similar trees
9: The worst-case time required to search a given element in a sorted linked list of length n is
A. O(1)

77
5.11 Worksheets

B. O(log2 n)
C. O(n)
D. O(n log2 n)
10: Traversing a binary tree first root and then left and right subtrees called .......... traversal.
A. Postorder
B. Preorder
C. Inorder
D. None of these

Subjective Questions
1. What is the prefix and post fix notation of (a + b) * (c + d) ?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. How insertion sort and selection sorts are different?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Explain the types of algorithm with examples.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

78
5.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Explain the rate of growth. Which is commonly used with the help of table?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Which data structure is used to perform recursion?.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. What is merge sort and how it works?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

79
5.11 Worksheets

Worksheet 4

Multiple Choice Questions


1: A graph is a tree if and only if graph is
A. Directed graph
B. Contains no cycles
C. Planar
D. Completely connected
2: A binary tree in which all its levels except the last, have maximum numbers of nodes, and all the nodes in the
last level have only one child it will be its left child. Name the tree.
A. Threaded tree
B. Complete binary tree
C. M-way search tree
D. Full binary tree
3: A full binary tree with n non-leaf nodes contains
A. log(n) nodes
B. n + 1 nodes
C. 2n − 1 nodes
D. 2n + 1 nodes
4: ............... deque is a deque which allows deletions at only one end of the list.
A. input-restricted
B. output-restricted
C. Queue
D. Heap
5: Which of the following statements is True?
A. Preorder- Process the root, Traverse the left subtree, traverse the right subtree.
B. Preorder- Traverse the left subtree, process the root, traverse the right subtree.
C. Preorder- Traverse the left subtree, traverse the right subtree, process the root.
D. None of above.
6: The data structure required to evaluate a postfix expression is
A. Queue
B. Stack
C. Tree
D. linked-list
7: Reverse polish notation is ..........
A. Prefix
B. Infix
C. Postfix
D. None
8: The time complexity of linear search algorithm over an array of n elements is
A. O(log2 n)
B. O(n)
C. O(n log2 n)
D. O(n2)
9: Which of the following sorting algorithms does not have a worst case running time of O(n2)?

80
5.11 Worksheets

A. Insertion sort
B. Merge sort
C. Quick sort
D. Bubble sort
10: A search begins the search with the element that is located in the middle of the array
A. serial
B. random
C. parallel
D. binary

Subjective Questions
1. What is hashing? Explain different hashing techniques in detail.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. What is a postfix expression?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. What is Graph? What are the types of graph?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

81
5.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Which data structures are used in BFS and DFS algorithm?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Explain the terms: null tree, left and right successor, terminal nodes, similar and copy tree.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. What are the differences between BST and AVL tree?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

82
5.11 Worksheets

Worksheet 5

Multiple Choice Questions


1: The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19. Which one of the following is the
postorder traversal of the tree?
A. 10, 11, 12, 15, 16, 18, 19, 20
B. 11, 12, 10, 16, 19, 18, 20, 15
C. 20, 19, 18, 16, 15, 12, 11, 10
D. 19, 16, 18, 20, 11, 12, 10, 15
2: A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed effi-
ciently. Which one of the following statements is CORRECT (n refers to the number of items in the queue)?
A. Both operations can be performed in O(1) time.
B. At most one operation can be performed in O(1) time, but the worst-case time for the other operation will
be Ω(n).
C. The worst-case time complexity for both operations will be Ω(n).
D. Worst-case time complexity for both operations will be Ω(log n).
3: The result of evaluating the postfix expression 10 5 + 60 6/ ∗ 8 − is
A. 284
B. 213
C. 142
D. 71
4: A program P reads in 500 integers in the range [0, 100], representing the scores of 500 students. It then prints
the frequency of each score above 50. What would be the best way for P to store the frequencies?
A. An array of 50 numbers
B. An array of 100 numbers
C. An array of 500 numbers
D. A dynamically allocated array of 550 numbers
5: Consider the following statements:
(i) First-in-first-out types of computations are efficiently supported by STACKS.
(ii) Implementing LISTS on linked lists is more efficient than implementing LISTS on an array for almost all
the basic LIST operations.
(iii) Implementing QUEUES on a circular array is more efficient than implementing QUEUES on a linear array
with two indices.
(iv) Last-in-first-out type of computations are efficiently supported by QUEUES.
Which of the following statements is/are true?
A. (ii) and (iii) are true
B. (i) and (ii) are true
C. (iii) and (iv) are true
D. (ii) and (iv) are true
6: The postorder traversal of a binary tree is 8, 9, 6, 7, 4, 5, 2, 3, 1. The inorder traversal of the same tree is 8, 6, 9, 4, 7, 2, 5, 1, 3
The height of a tree is the length of the longest path from the root to any leaf. Then the height of the binary tree
is .
A. 5
B. 4
C. 10

83
5.11 Worksheets

Figure 5.1: Binary Tree

D. 1
7: Following are pass outputs of a program for an algorithm: 22, 14, 56, 7, 25, 8
Pass 1: 7, 14, 56, 22, 25, 8
Pass 2: 7, 8, 56, 22, 25, 14
And so on...
Final: 7, 8, 14, 22, 25, 56
Choose the name of the associated algorithm for the above results.
A. Selection sort
B. Insertion sort
C. Bubble Sort
D. Merge Sort
8: Following are the pass outputs of a program for an algorithm: 22, 14, 56, 7, 25, 8
Pass 1: 14, 22, 56, 7, 25, 8
Pass 2: 14, 22, 56, 7, 25, 8
Pass 3: 7, 14, 22, 56, 25, 8
And so on...
Final: 7, 8, 14, 22, 25, 56
Choose the name of the associated algorithm for the above results.
A. Selection sort
B. Insertion sort
C. Bubble Sort
D. Merge Sort
9: Following are the pass outputs of a program for an algorithm: 22, 14, 56, 7, 25, 8
Pass 1: 14, 22, 7, 25, 8, 56
Pass 2: 14, 7, 22, 8, 25, 56
And so on...
Final: 7, 8, 14, 22, 25, 56
Choose the name of the associated algorithm for the above results.
(A) Selection sort
(B) Insertion sort
(C) Bubble Sort
(D) Merge Sort
10: Array representation of Binary tree
0 1 2 3 4 5 6
A. 7 11 2 7 1 11 9

84
5.11 Worksheets

0 1 2 3 4 5 6
B. 7 11 7 1 2 11 9
0 1 2 3 4 5 6
C. 7 1 11 11 9 2 7
D. Any of the above

Subjective Questions
1. Define the properties of recursion. Explain factorial.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Explain the all-possible complexities (best, worst and average case) in a table.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. What are records? Explain record structure with one example.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

85
5.11 Worksheets

....................................................................................................
4. Create a BST tree with the following data by inserting the elements in order of their occurrence: 200, 150, 350,
100, 70, 110, 250, 500, 400, 550, 450
Delete the following nodes in sequential order: 150, 500, 450, 200, 110
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Consider the graph given below. Find out its Breadth-First Traversal and show each steps.

Figure 5.2: Graph

Note: consider starting node as r


....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. What do you mean by collision in hashing. Explain different techniques of collision resolution.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

86
5.11 Worksheets

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

87
6.12 Worksheets

ALGORITHM
WORKSHEET
Worksheet 1

Multiple Choice Questions


1. Find the recurrence relation of the Quick Sort algorithm in the worst case.
A. T (n) = T (n/10) + T (9n/10) + O(n)
B. T (n) = T (n − 1) + T (0) + O(n)
C. T (n) = 2T (n/2) + O(n)
D. T (n) = T (n − 2) + O(n)
2. Let us have an algorithm to find the median of the unsorted array having complexity O(n). Now we have
modified the quicksort algorithm and using the median algorithm to find the pivot element. What will be the
complexity of this modified quicksort algorithm in the worst case?
A. O(log log n)
B. O(n)
C. O(n2)
D. O(n log n)
3. If the array is already sorted or almost sorted then which algorithm will give the best results?
A. Quick Sort
B. Merge Sort
C. Heap Sort
D. Insertion Sort
4. If Swap operation is very costly then which sorting technique you will choose to sort the unsorted array?
A. Insertion Sort
B. Selection Sort
C. Merge Sort
D. Heap Sort
5. Suppose you have 2GB Data and you have to sort it, but you have only 100MB main memory available with you,
which sorting technique you are going to apply?
A. Merge Sort
B. Insertion Sort
C. Heap Sort
D. Quick Sort
6. What is the recurrence relation of Binary Search in Worst case?
A. T (n) = T (n/2) + O(1) and T (1) = T (0) = O(1)
B. T (n) = T (n − 1) + O(1) and T (1) = T (0) = O(1)
C. T (n) = 2T (n/2) + O(1) and T (1) = T (0) = O(1)
D. T (n) = T (n − 2) + O(1) and T (1) = T (0) = O(1)
7. Average number of comparisons in linear search when the element is present in the list is:
A. n
88
B. n/2 3.10 Frequently Asked Interview Questions
C. (n + 1)/2
D. (n − 1)/2
8. Average number of comparisons in linear search when the element is present in the list is:
A. n

89
3.10 Frequently Asked Interview Questions

B. n/2
C. (n + 1)/2
D. (n − 1)/2
9. If we have 11 sorted elements in an array and we apply Binary search to find the element and each time it is a
successful search. What will be the average number of comparisons we need to do?
A. 3.46
B. 3.0
C. 3.33
D. 2.81
10. Average case complexity of Linear Search occurs when:
A. Item is available exactly in the mid of the list.
B. Item is available somewhere in between the list.
C. Item is at the end of the list.
D. Item is not available in the list.

Subjective Questions
1. What do you mean by “Sort in Place”?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. What are the conditions for ideal sorting Algorithm?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Write Recursive function of Binary Search.
....................................................................................................
....................................................................................................

90
3.10 Frequently Asked Interview Questions

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Write iterative algorithm of Quick Sort.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Write a code to check whether given two strings are Anagram. (Anagram means the strings are of equal length
and have same characters, but order may be different).
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Consider we have 1000 sorted elements in an array and we are trying to find an element which is not available
in this array using binary search. Find how many comparisons will be required to find that the element is not
available. Write all the indices with which you are going to compare.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

91
3.10 Frequently Asked Interview Questions

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

92
3.10 Frequently Asked Interview Questions

Worksheet 2

Multiple Choice Questions


1: Which of the Hash Function will create a cluster in the hash table?
A. h(k) = k
B. h(k) = k%m
( )
C. h(k) = km+ k · m + k%m
D. h(k) = (k + 1) %m + m k

2: Hash Table T has 25 slots which are going to store 2000 elements. What will be the load factor?
A. 0.0125
B. 50000
C. 1.25
D. 80
3: Let a Hash Function distributes keys uniformly in the hash table. The hash table has size 50. After how many
keys are added will the probability of collision become 0.5?
A. 20
B. 25
C. 10
D. 30
4: Benefit of chaining over open addressing is:
A. Deletion is easier
B. Space used is less
C. Complexity of the search operation is less
D. None of these
5: Insert the characters of the string KRPY SNJM into a hash table of size 10. Use the hash function h(x) =
(ord(x) − ord(”A”) + 1) mod 10. If linear probing is used to resolve collisions, then the following insertion
causes a collision. ord(x) is a function that returns the alphabetical order of the letter.
A. P
B. M
C. C
D. K
6: Which is the most efficient algorithm to find a cycle in a graph?
A. BFS
B. DFS
C. Prim’s Algorithm
D. Kruskal Algorithm
7: How is traversal of a graph different from a tree?
A. BFS of a graph uses a queue, but a time-efficient BFS of a tree is recursive.
B. DFS of a graph uses a stack, but inorder traversal of a tree is recursive.
C. There can be a loop in a graph so we must maintain a visited flag for every vertex.
D. All of the above.
8: To implement Dijkstra’s shortest path algorithm on unweighted graphs so that it runs in linear time, the data
structure to be used is:
A. Queue
B. Stack

93
3.10 Frequently Asked Interview Questions

C. Heap
D. Binary Tree
9: Which of the following algorithms can be used to efficiently calculate single source shortest paths in a Directed
Acyclic Graph?
A. Topological Sort
B. Bellman-Ford
C. Dijkstra
D. Prim’s
10: Given a directed graph where the weight of every edge is the same, we can efficiently find the shortest path from
a given source to destination using:
A. DFS
B. BFS
C. Dijkstra
D. Kruskal

Subjective Questions
1. How can I pair socks from a pile efficiently
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open
addressing with hash function h(k) = k mod 10 and linear probing. What is the resultant hash table?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Write any five applications of BFS.
....................................................................................................

94
3.10 Frequently Asked Interview Questions

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Given a connected undirected graph, check if it contains any cycle or not. Write algorithm for it.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Why Dijkstra Algorithm get fail for graphs containing negative weights?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

95
3.10 Frequently Asked Interview Questions

Worksheet 3

Multiple Choice Questions


1: Which of the following problems can be efficiently solved using Greedy Programming?
A. Traveling Salesman Problem
B. Knapsack Problem
C. Shortest Path Problem
D. Fractional Knapsack Problem
2: Which of the following statements is true regarding Greedy Algorithms?
A. They always guarantee optimal solutions for any problem.
B. They are not suitable for problems where a globally optimal solution is required.
C. They are primarily based on backtracking.
D. They are applicable only to problems with small input sizes.
3: What is the time complexity of the Greedy Algorithm for Huffman coding?
A. O(n log n)
B. O(n2)
C. O(n)
D. O(log n)
4: Which of the following problems is NOT solved using a Greedy Algorithm?
A. Prim’s Algorithm for Minimum Spanning Tree
B. Dijkstra’s Algorithm for Shortest Path
C. Traveling Salesman Problem
D. Knapsack Problem
5: In the context of the Fractional Knapsack Problem, if the available capacity is 10 and there are items with weights
{5, 3, 8} and values {10, 6, 12}, what is the maximum value that can be obtained using a greedy approach?
A. 15
B. 18
C. 22
D. 28
6: In the context of Huffman coding, if the frequencies of characters are {2, 3, 7, 10} and a greedy algorithm is
used to build the Huffman tree, what is the total number of bits needed to represent the entire message?
a. 18
b. 20
c. 24
d. 28
7: For a given graph, if Prim’s algorithm is used to find the minimum spanning tree, and the graph is represented
using an adjacency matrix, what is the time complexity in terms of the number of vertices (V)?
A. O(V )
B. O(V 2)
C. O(V log V )
D. O(V 3)
8: In the Fractional Knapsack Problem, if the available capacity is 15 and there are items with weights {8, 4, 6}
and values {16, 10, 12}, what is the optimal solution obtained using a greedy approach?
A. 30
B. 28

96
3.10 Frequently Asked Interview Questions

C. 26
D. 24
9: What is the time complexity of the greedy algorithm for job scheduling with deadlines?
A. O(n)
B. O(n log n)
C. O(n2)
D. O(log n)
10: For a given graph with weighted edges, if Kruskal’s algorithm is applied to find the minimum spanning tree,
what is the time complexity for a graph with V vertices and E edges?
A. O(V )
B. O(E)
C. O(V log V )
D. O(E log E)

Subjective Questions
1. 1. Consider the following tasks with their deadlines and profits. Schedule the tasks in such a way that they
produce maximum profit after being executed
Job J1 J2 J3 J4
Profit 50 15 10 25
Deadline 2 1 2 1
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Construct a minimum spanning tree of the graph given in Figure 6.5 Start the Prim’s algorithm from vertex D.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

97
3.10 Frequently Asked Interview Questions

Figure 6.5

3. Apply Kruskal’s algorithm on the graph given in Figure 6.6.

Figure 6.6

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Consider the graph G given in Figure 6.7 Taking S as the initial node, execute the Dijkstra’s algorithm on it.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

98
3.10 Frequently Asked Interview Questions

Figure 6.7

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Create a Huffman tree with the following nodes arranged in a priority queue in Figure 6.8.

Figure 6.8

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

99
3.10 Frequently Asked Interview Questions

Worksheet 4

Multiple Choice Questions


1: In the Merge Sort algorithm, what is the time complexity for sorting an array of n elements?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n2)
2: What is the base case in most Divide and Conquer algorithms?
A. When the input size becomes zero
B. When the input size becomes one
C. When the input size becomes two
D. When the input size becomes a prime number
3: In the QuickSort algorithm, what is the role of the ”pivot” element?
A. It is the smallest element in the array
B. It is the largest element in the array
C. It is used to partition the array into smaller and greater elements
D. It is the middle element of the array
4: Which of the following is a disadvantage of the Divide and Conquer approach?
A. It is difficult to implement
B. It often requires extra space
C. It is not suitable for parallel processing
D. It may have a high constant factor in the time complexity
5: What is the time complexity of the MergeSort algorithm for sorting an array of size n?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n2)
6: If an algorithm divides the problem into five subproblems and each subproblem is solved independently, what
would be its recurrence relation for time complexity?
A. T (n) = 5 · T (n/5)
B. T (n) = T (n/5) + T (4n/5)
C. T (n) = T (n/2) + 5
D. T (n) = 5 · T (n)
7: If a Divide and Conquer algorithm has a recurrence relation T (n) = T (n/2)+O(n), what is its time complexity?
A. O(n)
B. O(log n)
C. O(n log n)
D. O(n2)
8: If the size of the input is halved in each recursive call and an additional linear amount of work is done, what is
the overall time complexity of the algorithm?
A. O(log n)
B. O(n)
C. O(n log n)
D. O(n2)

100
3.10 Frequently Asked Interview Questions

9: Consider a recursive algorithm with a time complexity given by the recurrence relation T (n) = 3T (n/4) + n2.
What is the time complexity of this algorithm using the Master Theorem?
A. O(n)
B. O(n log n)
C. O(n2 log n)
D. O(n2)
10: The time complexity of an algorithm is given by T (n) = T (n/2) + T (n/4) + n. What is the time complexity
of the algorithm?
A. O(n log n)
B. O(n2)
C. O(n2 log n)
D. O(n3)

Subjective Questions
1. For each of the following recurrences, give an expression for the runtime T (n) if the recurrence can be solved
with the Master Theorem. Otherwise, indicate that the Master Theorem does not apply.
(a). T (n) = 3T (n/2) + n2
(b). T (n) = 4T (n/2) + n2
(c). T (n) = T (n/2) + 2n
(d). T (n) = 2nT (n/2) + nn
(e). T (n) = 16T (n/4) + n
(f). T (n) = 2T (n/2) + n log n
(g). T (n) = 2T (n/2) + n/ log n
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Apply QuickSort algorithm on the given array. Input: [2, 8, 7, 1, 3, 5, 6, 4]
Output: [1, 2, 3, 4, 5, 6, 7, 8]

Algorithm 5 Quick Sort


1: procedure QUICKSORT(A, low, high)
2: if low < high then
3: pivot → Partition(A, low, high)
4: QuickSort(A, low, pivot - 1)
5: QuickSort(A, pivot + 1, high)

....................................................................................................

101
3.10 Frequently Asked Interview Questions

Algorithm 6 Partition
1: procedure PARTITION(A, low, high)
2: pivot → A[high]
3: i → low − 1
4: for j → low to high − 1 do
5: if A[j] ≤ pivot then
6: i→i+1
7: swap A[i] and A[j]
8: swap A[i + 1] and A[high]
9: return i + 1

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Apply Merge Sort algorithm on following array Input: [2, 8, 7, 1, 3, 5, 6, 4]
Output: [1, 2, 3, 4, 5, 6, 7, 8]

Algorithm 7 Merge Sort


1: procedure MERGESORT(A, low, high)
2: if low < high then
3: mid → (low + high)/2
4: MergeSort(A, low, mid)
5: MergeSort(A, mid + 1, high)
6: Merge(A, low, mid, high)

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Solve the following recurrence relation using the substitution method:
( n)
T (n) = 2T + n, T (1) = 2
2

102
3.10 Frequently Asked Interview Questions

Algorithm 8 Merge
1: procedure MERGE(A, low, mid, high)
2: n1 → mid − low + 1
3: n2 → high − mid
4: create arrays L[1..n1 + 1] and R[1..n2 + 1]
5: for i → 1 to n1 do
6: L[i] → A[low + i − 1]
7: for j → 1 to n2 do
8: R[j] → A[mid + j]
9: L[n1 + 1] → ∞
10: R[n2 + 1] → ∞
11: i→1
12: j→1
13: for k → low to high do
14: if L[i] ≤ R[j] then
15: A[k] → L[i]
16: i→i+1
17: else
18: A[k] → R[j]
19: j →j +1

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Solve the following recurrence relation using the tree method:
( n)
T (n) = 2T +n
2

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................

103
3.10 Frequently Asked Interview Questions

....................................................................................................

104
3.10 Frequently Asked Interview Questions

Worksheet 5

Multiple Choice Questions


1: Which of the following is a key feature of problems suitable for dynamic programming?
A. They can be solved using a brute-force approach
B. They exhibit optimal substructure and overlapping subproblems
C. They are always easy to solve
D. They involve recursion
2: In dynamic programming, what is meant by ”optimal substructure”?
A. The smallest subproblem is always the optimal solution
B. The optimal solution of a problem can be constructed from optimal solutions of its subproblems
C. The subproblems are always solved in an optimal way
D. The optimal solution is always achieved using a brute-force approach
3: What is memoization in the context of dynamic programming?
A. A technique for storing and reusing previously computed results to avoid redundant computations
B. A method for writing code using memo pads
C. A way of measuring the time complexity of a dynamic programming algorithm
D. A type of optimization that prioritizes memory over speed
4: If a dynamic programming algorithm uses the tabulation approach to solve a problem of size n, and the table
has dimensions n × n, what is the space complexity of the algorithm?
A. O(n)
B. O(n2)
C. O(log n)
D. O(1)
5: Which of the following is an example of a problem that can be efficiently solved using dynamic programming?
A. Sorting an array
B. Finding the maximum element in an array
C. Longest Common Subsequence
D. Binary search
6: In the Fibonacci sequence, if F(0) = 0 and F(1) = 1, what is the value of F(5) using dynamic programming?
A. 3
B. 5
C. 8
D. 13
7: For the Longest Common Subsequence (LCS) problem, if the input sequences are ”ABCD” and ”ACDF,” what
is the length of the LCS using dynamic programming?
A. 2
B. 3
C. 4
D. 5
8: If a dynamic programming algorithm uses memoization and the result of F(3) is already computed, how many
times will F(3) be recalculated in the process of solving F(5)?
A. 0
B. 1
C. 2

105
3.10 Frequently Asked Interview Questions

D. 3
9: If a dynamic programming algorithm has a recurrence relation T (n) = T (n − 1) + T (n − 2) and base cases
T (0) = 1, T (1) = 1, what is the time complexity of the algorithm in terms of n?
A. O(n)
B. O(2n)
C. O(n2)
D. O(log n)
10: For the Knapsack problem, if the maximum capacity is 10 and there are items with weights [2, 4, 5] and values
[6, 8, 7], what is the maximum value that can be achieved using dynamic programming?
A. 13
B. 14
C. 15
D. 16

Subjective Questions
1. Find an optimal parenthesization of a matrix-chain product whose sequence of dimensions is (5,4,6,2,7).
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Determine an LCS of (1,0,0,1,0,1,0,1) and (0,1,0,1,1,0,1,1,0).

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Consider the problem having weights and profits are:
Weights: 2,3,4,5
Profits: 1,2,5,6

106
3.10 Frequently Asked Interview Questions

The weight of the knapsack is 8 kg. Solve the 0/1 knapsack using Dynamic Programming.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Discuss difference between Tabulation vs Memoization in Dynamic Programming.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Consider the following Graph given in Figure 6.9. Solve it for All Pair Shortest Path using Dynamic Program-
ming.
....................................................................................................

Figure 6.9

....................................................................................................
....................................................................................................
....................................................................................................

107
3.10 Frequently Asked Interview Questions

....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
. . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

108
A.13 Minimum Spanning Tree (MST) Algorithms

109

You might also like