CS101-Intro_Exam

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

1

Uploaded by PrivateMonkey2307

Report
Computer Science Introductory Evaluation This examination is designed to evaluate your understanding of fundamental concepts in computer science. Please read each question carefully and provide concise and accurate responses. You are allotted 1 hour for the completion of this exam. Question 1: Programming Basics (10 points) Write a simple Python program that takes two integers as input and outputs their sum. Answer Key: def add_two_numbers(a, b): return a + b # Taking input from the user num1 = int(input("Enter the first integer: ")) num2 = int(input("Enter the second integer: ")) # Calculating and displaying the sum result = add_two_numbers(num1, num2) print("The sum is:", result) Question 2: Data Structures (15 points) Explain the difference between a stack and a queue. Provide a real-world example where each data structure could be applied. Answer Key: A stack is a Last In, First Out (LIFO) data structure, meaning that the last element added is the first one to be removed. An example of a stack in the real world is the undo feature in software applications, where the last action performed is the first one that can be undone. A queue, on the other hand, is a First In, First Out (FIFO) data structure, where the first element added is the first one to be removed. A real-world example of a queue is a printer queue, where the first document sent to the printer is the first one to be printed. Question 3: Algorithms (20 points) Describe the bubble sort algorithm and provide an example of its application on an array of integers. Answer Key: Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The process is repeated until the list is sorted.
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help