CS101-Exam1

pdf

School

New Jersey Institute Of Technology *

*We aren’t endorsed by this school

Course

100

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

2

Uploaded by PrivateMonkey2307

Report
Exam 1: Programming Fundamentals Question 1 (10 points): Write a Python function that calculates the factorial of a given positive integer. Provide an example of using the function to calculate the factorial of 5. Answer Key: def factorial(n): if n == 0 or n == 1: return 1 else: return n * factorial(n - 1) # Example usage result = factorial(5) print("Factorial of 5:", result) Question 2 (15 points): Explain the concept of a linked list and provide an example of a singly linked list in Python. Answer Key: python Copy code class Node: def __init__(self, data): self.data = data self.next = None # Example of a singly linked list node1 = Node(1) node2 = Node(2) node3 = Node(3) node1.next = node2 node2.next = node3 Question 3 (20 points): Describe the binary search algorithm and explain its time complexity. Provide a step-by-step example of a binary search on a sorted list with values [1, 3, 5, 7, 9] to find the value 5. Answer Key: Binary search is an algorithm that efficiently finds a target value within a sorted list. Its time complexity is O(log n). Example: Start with the entire sorted list: [1, 3, 5, 7, 9]. Compare the target value (5) with the middle element (5).
Since 5 equals the middle element, the search is successful. Question 4 (15 points): Explain the concept of version control and its importance in software development. Provide an example of a version control system. Answer Key: Version control is a system that records changes to a file or set of files over time, allowing you to recall specific versions later. It helps in collaborative development and tracking changes. An example of a version control system is Git.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help