Cognizant Technical Screening 1 — Questions and Answers
Question 1: What is the time complexity of binary search in a sorted array?
- O(n)
- O(n^2)
- O(log n) (Correct answer)
- O(1)
Correct answer: O(log n)
Binary search is an efficient algorithm for finding an item from a sorted list of items. It works by repeatedly dividing the search interval in half. Because the search space is halved in each step, the number of operations required grows logarithmically with the size of the input (n), giving it a time complexity of O(log n).
Question 2: Which of the following is a primary function of a database index?
- To store metadata
- To improve query performance (Correct answer)
- To encrypt data
- To normalize data
Correct answer: To improve query performance
A database index is a data structure that significantly improves the speed of data retrieval operations on a database table. It works by creating a quick lookup mechanism for rows based on the values in one or more columns, similar to how an index in a book helps you find information faster. This reduces the amount of data the database system needs to scan, thereby enhancing query performance.
Question 3: Which programming language is commonly used for backend web development?
- HTML
- CSS
- Python (Correct answer)
- Bootstrap
Correct answer: Python
Python is a highly versatile and popular programming language widely used for backend web development. Its extensive ecosystem includes powerful frameworks like Django and Flask, which provide robust tools for building server-side logic, handling databases, and managing APIs. This makes Python an excellent choice for powering the 'behind-the-scenes' operations of web applications.
Question 4: What does the 'public' keyword signify in Java?
- Accessible only within the package
- Accessible only to the class
- Accessible from any other class (Correct answer)
- Accessible to subclasses only
Correct answer: Accessible from any other class
In Java, the 'public' keyword is an access modifier that grants the broadest visibility to a class, method, or variable. When an element is declared 'public', it can be accessed from any other class within the same package or from any other package. This makes the element universally available throughout the application, allowing for maximum interoperability.
Question 5: Which protocol is used for secure communication over the internet?
- HTTP
- FTP
- HTTPS (Correct answer)
- SMTP
Correct answer: HTTPS
HTTPS (Hypertext Transfer Protocol Secure) is the standard protocol used for secure communication over a computer network, especially the internet. It encrypts the data exchanged between a user's browser and a website, protecting it from eavesdropping, tampering, and forgery. This security is primarily achieved through the use of SSL/TLS protocols, ensuring data integrity and confidentiality.
Question 6: What is the primary purpose of version control systems like Git?
- Compile source code
- Track changes in source code (Correct answer)
- Monitor runtime performance
- Encrypt source code
Correct answer: Track changes in source code
Version control systems (VCS) like Git are essential tools primarily designed to track and manage changes to source code and other files over time. They enable multiple developers to collaborate efficiently on a project, maintain a complete history of all modifications, revert to previous versions if needed, and merge different branches of development seamlessly. This ensures code integrity and facilitates organized teamwork.
What is the time complexity of binary search in a sorted array?