Computer Science Interview Questions

0xBen
11 min readJul 28, 2023

--

Q1 Explain what is the computer system?

it is the collection of hardware and software that makes up a computer. It consists of the processor, memory, storage devices, input/output devices, and other components

Let’s explain each component individually :

- The processor is the central processing unit (CPU) that controls the computer’s operations , It is often referred to as the “brain” of the computer

The CPU has several components that work together to carry out Operations :

-1 Control Unit (CU): is responsible for fetching instructions from memory, decoding them, and managing the execution of instructions

-2 Arithmetic Logic Unit (ALU): performs all the arithmetic (addition, subtraction, multiplication, division) and logical (AND, OR, NOT) operations

-3 Registers: are small, high-speed memory units within the CPU. They store data that the CPU needs to access quickly during its operations

Let’s Explain RAM First and after this we will Know How they work together (RAM , CPU )

Random Access Memory (RAM) is the computer’s temporary storage area ,

it consists of number of cells and each cell stores fixed amount of data

Why is it called by this name (Random Access) : because the CPU can access any location in RAM directly, without the need to read through the data in sequence , RAM is volatile memory meaning its contents are lost when the power is turned off

The structure and operations of random memory :

-1 Memory Cells: RAM is organized into a collection of memory cells, each capable of storing a fixed amount of data. Each memory cell has a unique address, which allows the CPU to access specific data quickly

-2 Binary Data: RAM stores data in binary form, using 0s and 1s. Each memory cell can hold a certain number of bits

-3 Reading from RAM: When the CPU needs to read data from RAM, it sends a memory address to the RAM controller, specifying which memory cell it wants to access. The RAM controller then retrieves the data from the specified memory cell and sends it back to the CPU

-4 Writing to RAM: When the CPU needs to write data to RAM, it sends the memory address and the new data to the RAM controller. The RAM controller then stores the new data in the specified memory cell, overwriting the previous content

Let’s take an example that shows how the CPU works with RAM :

Imagine you have a basic calculator that can perform addition and subtraction , and want to calculate (2 + 3–1) ???

Step 1: Fetch , it is the task of Control unit (CU)

The Control unit fetches the first instruction from RAM , which is “2” It knows this is the first number to be used in the calculation

Note : Number 2 in RAM represented as “00000010” Binary for 2 , That’s why the CPU does “Decoding”

Step 2 : Decode: it is the task of Control unit (CU)

The CU decodes the fetched instruction “00000010” and recognizes it as a number “2” and stores this value in a temporary register

Step 3: Fetch

The CU fetches the next instruction from RAM , which is the addition symbol “+”

Step 4: Decode

The CU decodes the fetched instruction and recognizes it as an addition operation and stores this value in a temporary register

Step 5: Fetch

The Control unit fetches the Next instruction from RAM , which is “3”

Step 6: Decode

The CU decodes the fetched instruction “00000011” and recognizes it as a number “3” and stores this value in a temporary register

Note : For Now The temporary register has values ( 2 , + , 3 )

Step 7 : Execute task of Arithmetic Logic Unit (ALU)

Execute: The Arithmetic Logic Unit (ALU) performs the addition operation using the value stored in the temporary register (which is

“2”) and the next number in the expression, which is “3.” The result of the addition, “5,” is stored in the temporary register

Step 8: Fetch

The CU fetches the next instruction from Ram , which is the subtraction symbol “-”

Step 9 : Decode

The CPU decodes the fetched instruction and recognizes it as a subtraction operation “-”

Step 10 : Fetch

The CU fetches the Next instruction from RAM , which is “1”

Step 11 : Decode

The CU decodes the fetched instruction and recognizes it as “1”

Step 12 : Execute

Execute: The ALU performs the subtraction operation using the result of the previous addition (“5”) and the next number in the
expression, which is “1.” The result of the subtraction, “4,” is stored in the temporary register

Step 13 : Write-back

The final result “4” is now available in the temporary register and can be displayed on the calculator’s screen or used further in
subsequent calculations

As u can see the final result and you have known How CPU works

Q2 What is an operating system (OS) ?

is a software program that acts as an intermediary between the hardware components of a computer system and the user or applications.
It manages and coordinates various tasks, resources, and processes to provide a user-friendly and efficient computing environment

Different types Of OS

The main functions of an operating system include:

Main functions of an operating system

1- Process Management: The operating system manages and oversees multiple tasks or processes running on the computer simultaneously. It allocates CPU time and system resources to each process, ensuring that they can execute efficiently without interfering with one another

Example: Imagine you have multiple applications open on your computer, such as a web browser, a word app and a media player. The operating system ensures that each application gets its fair share of the CPU’s processing time and memory so that they can all run smoothly together

-2 Memory Management: The operating system handles the computer’s memory (RAM) and ensures that each running program gets the necessary amount of memory to function properly

Example: When you run multiple programs simultaneously, the operating system ensures that each program gets the memory it needs to function, and if the RAM becomes full , it may use a part of the hard drive as temporary storage (virtual memory) to handle the overflow

-3 File System Management: The operating system organizes and manages the storage of files and data on various storage devices, such as hard drives and SSDs

-4 Device Management : The operating system interacts with various hardware devices connected to the computer, such as printers, keyboards, and network adapters

Example When you connect a new device, like a printer, to your computer, the operating system detects it, installs the necessary drivers, and makes the printer accessible to applications, so you can print documents without directly dealing with the printer’s technicalities

-6 User Interface: The operating system provides a user interface (UI) that allows users to interact with the computer system

  • 7 Security and Protection: The operating system enforces security measures to protect the computer and data from unauthorized access. It controls user permissions and provides authentication mechanisms to ensure only authorized users can access sensitive resources

Q3 What are the Layers of the OSI Model

Layers of the OSI Model

OSI stands for “Open Systems Interconnection,” and it refers to a conceptual framework that standardizes the functions of a telecommunication or computing system into different layers ,it was introduced by the International Organization for Standardization (ISO)

The seven layers of the OSI model, from the top layer to the bottom layer, are:

- Application Layer (Layer 7):

  • This is where user applications (like web browsers, email programs, etc.) interact with the network
  • Example: In the application layer, you have your email client software (e.g., Microsoft Outlook or Gmail). You compose an email, add the recipient's address, and click the "Send" button. The email client formats the email message and adds necessary headers like "To," "From," and "Subject."

- Presentation Layer (Layer 6):

  • The presentation layer makes sure data is presented in a format that applications can understand and Responsible for encryption and compression
  • Example: The presentation layer takes care of data encryption. In this case, your email client(gmail , outlook) encrypts the email message before it is transmitted over the network to protect its contents from unauthorized access

- Session Layer (Layer 5):

  • This layer manages communication sessions between applications on different devices.
  • It sets up, and ends connections between devices
  • Note :Think of the session as the one that determines when the connection starts and when it ends

- Transport Layer (Layer 4):

  • The transport layer takes care of end-to-end data delivery
  • It ensures data is delivered reliably and in the right order, and it handles any errors that may occur during transmission
  • Example: In the transport layer, the email client(gmail , outlook) splits the email message into smaller packets, each with its sequence number. It also adds error-checking information to ensure reliable delivery. The transport layer (e.g., TCP) ensures that these packets are sent and received in the correct order and reassembles them at the destination

- Network layer (Layer 3) :

  • deals with logical addressing and routing of data across networks.
  • It decides the best path for data to travel from the sender to the receiver

Example: The network layer is responsible for logical addressing and routing. The email client determines the IP address of the email server (using DNS, the Domain Name System) and sets the destination IP address in the packets

- Data Link Layer (Layer 2):

  • This layer provides reliable data transfer between directly connected devices on the same network.
  • It uses physical hardware addresses (MAC addresses) to identify devices on the local network
  • Example: The data link layer adds physical hardware addresses (MAC addresses) to the packets. These addresses identify the network interface cards of the devices on the local network. The email client uses ARP (Address Resolution Protocol) to find the MAC address of the email server

- Physical Layer (Layer 1):

  • The bottom layer deals with the physical transmission of data over the network medium.
  • It defines the hardware specifications, such as cables, connectors, and electrical signals used to transmit data

Q4 What is an array?

An array is a data structure that can hold a lot of data. Arrays are used in a lot of different applications, such as databases, spreadsheets, and games. Arrays are made up of different data types, such as numbers, strings, and characters

Two Dimensional Array

Q5 What is a constructor?

a constructor is a special method or function within a class that is automatically called when an object of the class is created. It is used to initialize the object’s state and set up its initial properties or attributes

Example: Creating a class to represent a basic person with a name and age

Parametrized Constructor

Let’s analyze this Code :

-Don’t worry if you’re not familiar with python

  • We define a class called “Person” with two attributes: name and age
  • Inside the class, there is a constructor method named __init__
  • When a new object of the class is created (e.g., person1 and person2), this method is automatically called.
  • The constructor takes three parameters: self, name, and age.
  • The self parameter refers to the instance of the object being created.
  • The name and age parameters are used to pass the initial values for the name and age attributes
  • Inside the constructor, we assign the values of the name and age parameters to the corresponding attributes of the object (self.name and self.age).
  • We create two objects of the Person class: person1 and person2.
  • Each time we create an object, the constructor is automatically called to set the initial values of the object’s attributes

Note : __init__ is a special method in Python known as the constructor , if u want define constructor use this keyword , It is automatically called when an object of a class is created

Q6 What is the thread in programming?

In programming, a thread is the smallest unit of execution within a process. It is a sequence of instructions that can be scheduled and executed independently by the operating system’s schedule

threads within Process

Q7 What is an abstract class?

An abstract class is a class that cannot be instantiated directly, meaning you cannot create objects directly from it

Let’s See Example :

The line : class Animal(ABC): in Python defines a class named Animal that is derived from the ABC class, which stands for “Abstract Base Class.” In Python, when you want to create an abstract class, you typically use the ABC module, which provides functionality to define abstract classes and abstract methods

if u Attempt to create an instance of the abstract class (will raise an error)
animal = Animal()

To Fix this You have to Create an instances of Subclasses that derived from the abstract class Animal :

dog = Dog()

cat = Cat()

Q8 What is normalization in a Database?

Normalization in a database refers to the process of organizing data in a structured and efficient manner to eliminate redundancy and minimize data anomalies. The goal of normalization is to design a database schema that reduces data duplication and ensures data integrity, making it easier to maintain and query the database

If you want to know more about normalization : https://www.sqlshack.com/what-is-database-normalization-in-sql-server/

Q9 Explain firewalls?

Firewalls are software programs that are used to protect your computer from viruses and other malware. They are also used to protect your privacy and to keep unauthorized people from accessing your computer. Firewalls are often used in conjunction with antivirus software

Q10 What are the Application layer protocols?

HTTP (Hypertext Transfer Protocol):

  • HTTP is the protocol used for transmitting web pages and other resources on the World Wide Web.
  • The client sends an HTTP request to the server, and the server responds with the requested data, typically in the form of HTML documents.
  • Note : HTTPS is a secure version of HTTP that uses encryption (TLS/SSL) to ensure data privacy and integrity during transmission

FTP (File Transfer Protocol):

  • FTP is used to transfer files between a client and a server over a network.
  • It allows users to upload, download, and manage files on a remote server

SMTP (Simple Mail Transfer Protocol):

  • SMTP is a protocol for sending and routing email messages between email servers.
  • It is responsible for the transmission of outgoing mail from the sender to the recipient’s email server

DNS (Domain Name System):

  • DNS is responsible for converting human-readable domain names (e.g., www.example.com) into IP addresses (e.g., 192.0.2.1).
Your Browser Ask DNS server what is IP OF www.example.com and then make a request to the web server

SNMP (Simple Network Management Protocol):

  • It allows network administrators to gather information, monitor device health, and manage configurations remotely from a centralized management station.
SNMP agents are software components running on network-attached devices that facilitate communication with the SNMP manager. These agents are responsible for collecting and organizing information about the device’s status, performance, and configuration, making it available to the SNMP manager for network management and monitoring purposes.

Telnet:

  • Telnet is a network protocol used for establishing a remote terminal connection to a host or a network device over a network, such as the internet
  • It allows users to log in to a remote system and access its command-line interface or text-based applications as if they were physically present at the remote location
Here the user provides the username and password for connection

--

--

0xBen

Cyber Security Engineer & Researcher | CTF Player