AS Associate Degree In Computer Science 4 — Questions and Answers
Question 1: Which sorting algorithm uses a divide-and-conquer approach and has O(n log n) average performance?
- Selection sort
- Insertion sort
- Merge sort (Correct answer)
- Counting sort
Correct answer: Merge sort
Merge sort recursively divides the array in half and merges sorted halves, achieving O(n log n) average and worst-case performance.
Question 2: What does the acronym 'API' stand for?
- Application Programming Interface (Correct answer)
- Automated Program Integration
- Application Process Interpreter
- Advanced Programming Input
Correct answer: Application Programming Interface
API stands for Application Programming Interface, a set of rules allowing different software to communicate.
Question 3: In C, what is the output of printf("%d", 5 % 2)?
- 2
- 1 (Correct answer)
- 0
- 2.5
Correct answer: 1
The modulo operator % returns the remainder of division; 5 divided by 2 has remainder 1.
Question 4: Which design pattern ensures only one instance of a class is created?
- Factory
- Observer
- Singleton (Correct answer)
- Decorator
Correct answer: Singleton
The Singleton pattern restricts a class to having only one instance and provides a global access point to it.
Question 5: What is the primary purpose of a compiler?
- Execute code line by line
- Translate high-level source code into machine code (Correct answer)
- Manage memory allocation
- Debug runtime errors
Correct answer: Translate high-level source code into machine code
A compiler translates the entire high-level source program into machine or object code before execution.
Question 6: In a relational database, a foreign key in one table refers to which element in another table?
- Any column
- Primary key (Correct answer)
- Index
- Foreign key
Correct answer: Primary key
A foreign key references the primary key of another table to enforce referential integrity.
Question 7: Which protocol is used to securely transfer files over the internet using encryption?
- FTP
- SFTP (Correct answer)
- HTTP
- SMTP
Correct answer: SFTP
SFTP (SSH File Transfer Protocol) encrypts both commands and data, providing secure file transfer.
Which sorting algorithm uses a divide-and-conquer approach and has O(n log n) average performance?