Cognizant Core Knowledge and Fundamentals 3 ā Questions and Answers
Question 1: Which sorting algorithm has the best average-case time complexity?
- Bubble Sort
- Insertion Sort
- Merge Sort (Correct answer)
- Selection Sort
Correct answer: Merge Sort
Merge Sort achieves O(n log n) average-case time complexity, making it more efficient than O(n²) algorithms like Bubble, Insertion, and Selection sort.
Question 2: What is a primary key in a relational database?
- A foreign key that references another table
- A column that uniquely identifies each row in a table (Correct answer)
- An index created automatically on every column
- A constraint that allows duplicate values
Correct answer: A column that uniquely identifies each row in a table
A primary key uniquely identifies each record in a table and cannot contain NULL values or duplicates.
Question 3: Which HTTP method is typically used to update an existing resource partially?
- GET
- POST
- PUT
- PATCH (Correct answer)
Correct answer: PATCH
PATCH is used for partial updates to a resource, while PUT replaces the entire resource.
Question 4: What is the purpose of a constructor in object-oriented programming?
- To destroy an object after use
- To initialize an object when it is created (Correct answer)
- To define static class methods
- To override inherited methods
Correct answer: To initialize an object when it is created
A constructor is a special method automatically called when an object is instantiated to set initial values for its attributes.
Question 5: Which of the following is an example of a non-linear data structure?
- Array
- Queue
- Stack
- Graph (Correct answer)
Correct answer: Graph
Graphs are non-linear data structures where elements (nodes) can have multiple connections (edges) to other elements.
Question 6: In networking, what does DNS stand for?
- Data Network System
- Domain Name System (Correct answer)
- Digital Network Service
- Dynamic Node Service
Correct answer: Domain Name System
DNS (Domain Name System) translates human-readable domain names like www.example.com into IP addresses.
Question 7: Which access modifier in Java makes a member accessible only within its own class?
- public
- protected
- private (Correct answer)
- default
Correct answer: private
The private access modifier restricts visibility to only the class in which the member is declared.
Which sorting algorithm has the best average-case time complexity?