Docsity

CS 120 Computational Thinking module 2, Exams of Computer Science

Toggle sidebar
bg1
CS 120 Computational Thinking module 1
1. Which of the following best describes an algorithm?
A) A physical device used to input data into a computer
B) A step-by-step sequence of instructions for solving a problem
C) A type of computer virus that spreads through networks
D) A language used exclusively for database queries
Correct Answer: A step-by-step sequence of instructions for solving a problem
Rationale: An algorithm is a finite, ordered set of clear instructions designed to
accomplish a specific task or solve a problem. It is not a hardware device, malware,
or a database-specific language. Algorithms can be expressed in pseudocode,
flowcharts, or programming languages.
2. What is the primary purpose of pseudocode?
A) To execute code directly on a computer
B) To describe an algorithm in a human-readable, code-like format
C) To replace flowcharts entirely in programming
D) To encrypt data during transmission
Correct Answer: To describe an algorithm in a human-readable, code-like format
Rationale: Pseudocode is a structured, informal language that resembles
programming code but is not executable. It allows programmers to plan and
communicate algorithms without worrying about syntax. It does not replace
flowcharts, execute code, or encrypt data.
3. According to the module, which shape in a flowchart represents a decision point?
A) Oval
B) Rectangle
C) Diamond
D) Parallelogram
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29

Partial preview of the text

Download CS 120 Computational Thinking module 2 and more Exams Computer Science in PDF only on Docsity!

CS 120 Computational Thinking module 1

  1. Which of the following best describes an algorithm? A) A physical device used to input data into a computer B) A step-by-step sequence of instructions for solving a problem C) A type of computer virus that spreads through networks D) A language used exclusively for database queries Correct Answer: A step-by-step sequence of instructions for solving a problem Rationale: An algorithm is a finite, ordered set of clear instructions designed to accomplish a specific task or solve a problem. It is not a hardware device, malware, or a database-specific language. Algorithms can be expressed in pseudocode, flowcharts, or programming languages.
  2. What is the primary purpose of pseudocode? A) To execute code directly on a computer B) To describe an algorithm in a human-readable, code-like format C) To replace flowcharts entirely in programming D) To encrypt data during transmission Correct Answer: To describe an algorithm in a human-readable, code-like format Rationale: Pseudocode is a structured, informal language that resembles programming code but is not executable. It allows programmers to plan and communicate algorithms without worrying about syntax. It does not replace flowcharts, execute code, or encrypt data.
  3. According to the module, which shape in a flowchart represents a decision point? A) Oval B) Rectangle C) Diamond D) Parallelogram

Correct Answer: Diamond Rationale: In flowcharts, a diamond shape represents a decision or branching point where the flow can go in different directions based on a condition. Ovals represent start/end, rectangles represent processes, and parallelograms represent input/output.

  1. In the context of control structures, which term refers to executing steps in order, one after another? A) Selection B) Iteration C) Sequence D) Recursion Correct Answer: Sequence Rationale: Sequence is the control structure where instructions are executed in a linear order, one after another. Selection introduces decision-making, iteration enables repetition, and recursion is a technique where a function calls itself.
  2. What is the most likely outcome of using a loop without a proper termination condition? A) The loop will execute once and stop B) The loop may run indefinitely, causing an infinite loop C) The loop will automatically correct itself D) The loop will skip all iterations Correct Answer: The loop may run indefinitely, causing an infinite loop Rationale: A loop without a proper termination condition may run indefinitely, causing an infinite loop that never stops. This can freeze the program or consume

C) To describe the steps of the algorithm D) To determine the programming language used Correct Answer: To provide data that the algorithm processes to produce output Rationale: Input provides the data that an algorithm processes to produce output. It is a key property of algorithms. It does not store final results, describe steps, or determine programming language.

  1. In the context of algorithms, what does effectiveness mean? A) The algorithm produces the correct result but takes a long time B) Each step of the algorithm is basic enough to be carried out exactly C) The algorithm uses the most advanced programming language D) The algorithm is written in the fewest lines of code possible Correct Answer: Each step of the algorithm is basic enough to be carried out exactly Rationale: Effectiveness means that each step of an algorithm is basic enough to be carried out exactly and in a finite amount of time. It is not about speed, language choice, or code length.
  2. Which of the following best describes a loop in programming? A) A control structure that repeats a block of code B) A decision-making structure C) A type of variable D) A function that returns a value Correct Answer: A control structure that repeats a block of code Rationale: A loop is a control structure that repeats a block of code as long as a condition is met or for a specified number of times. Conditionals make decisions, variables store data, and functions are reusable blocks of code.
  1. What is the most likely purpose of using pseudocode before writing actual code? A) To test the program's performance on different hardware B) To plan and communicate the algorithm without worrying about syntax C) To automatically generate the final program D) To encrypt the program's source code Correct Answer: To plan and communicate the algorithm without worrying about syntax Rationale: Pseudocode allows programmers to focus on the logic and structure of an algorithm without being concerned with the specific syntax of a programming language. It is a planning and communication tool. It does not test performance, generate code automatically, or encrypt code.
  2. Which of the following is a property of a good algorithm? A) Definiteness B) Ambiguity C) Infiniteness D) Randomness Correct Answer: Definiteness Rationale: A good algorithm must have definiteness, meaning each step is precisely defined and unambiguous. Other key properties include input, output, finiteness, and effectiveness. Ambiguity, infiniteness, and randomness are not properties of a good algorithm.
  3. In the context of control structures, which term refers to repeating a set of instructions multiple times? A) Sequence B) Selection C) Iteration

Rationale: An algorithm is a conceptual, language-independent sequence of steps for solving a problem. A program is the implementation of an algorithm in a specific programming language. Algorithms can be expressed in various forms, not just visually, and programs are not necessarily shorter.

  1. What is the most likely outcome of a syntax error in a program? A) The program will run but produce incorrect results B) The program will fail to compile or run C) The program will run faster than expected D) The program will automatically correct the error Correct Answer: The program will fail to compile or run Rationale: A syntax error violates the rules of the programming language, causing the program to fail to compile or run. Logic errors may allow the program to run but produce incorrect results. Syntax errors are not automatically corrected.
  2. According to the module, which term refers to a rule-of-thumb or approximate problem-solving method used when finding the perfect solution would take too long? A) Algorithm B) Heuristic C) Decomposition D) Abstraction Correct Answer: Heuristic Rationale: A heuristic is a practical, approximate problem-solving method that provides a satisfactory solution when an optimal one would be too time-consuming or resource-intensive. An algorithm is a precise sequence of steps, decomposition breaks problems down, and abstraction simplifies by focusing on essentials.
  3. What is the primary function of a flowchart symbol for a process?

A) A rectangle B) A diamond C) A parallelogram D) An oval Correct Answer: A rectangle Rationale: In flowcharts, a rectangle represents a process or action step. A diamond represents a decision, a parallelogram represents input/output, and an oval represents start/end points. Standardized symbols make flowcharts universally understandable.

  1. Which of the following is an example of an algorithm in everyday life? A) A recipe for baking a cake B) A painting hanging on a wall C) A random collection of numbers D) A computer's hard drive Correct Answer: A recipe for baking a cake Rationale: A recipe is a finite, well-defined sequence of steps for achieving a specific outcome (baking a cake), making it an everyday example of an algorithm. A painting, random numbers, and a hard drive are not algorithms.
  2. In computational thinking, what does the term "automation" refer to? A) Using computing technology to carry out tasks with little or no human intervention B) Writing code manually without any tools C) Breaking a problem into smaller parts D) Ignoring unnecessary details in a problem
  1. In a spreadsheet, what does the formula =SUM(A1:A10) do? A) Multiplies the values in cells A1 through A B) Adds the values in cells A1 through A C) Finds the average of the values in cells A1 through A D) Counts the number of non-empty cells in A1 through A Correct Answer: Adds the values in cells A1 through A Rationale: The SUM function adds all numerical values in the specified range. Multiplication would require the PRODUCT function, averaging uses AVERAGE, and counting uses COUNT or COUNTA.
  2. Which principle explains why a spreadsheet cell reference like $A$1 remains fixed when copied to another cell? A) Relative referencing B) Absolute referencing C) Mixed referencing D) Circular referencing Correct Answer: Absolute referencing Rationale: An absolute cell reference uses dollar signs before both the column letter and row number, locking the reference so it does not change when copied. Relative references adjust based on the new location, mixed references lock only one part, and circular references create errors.
  3. What is the primary purpose of a data structure in programming? A) To organize and store data for efficient access and modification B) To display output to the user C) To connect to the internet D) To compile source code into machine code

Correct Answer: To organize and store data for efficient access and modification Rationale: A data structure defines the way data is organized and stored so it can be efficiently accessed and modified. It influences how well a computational solution performs. Displaying output, connecting to the internet, and compiling code are separate concerns.

  1. In the context of data structures, what is an array? A) A collection of elements of the same type stored in contiguous memory locations B) A collection of elements connected by pointers C) A data structure that follows LIFO order D) A data structure that follows FIFO order Correct Answer: A collection of elements of the same type stored in contiguous memory locations Rationale: An array is the simplest data structure, containing elements of the same size stored in contiguous memory locations and accessed by indexes. Linked lists use pointers, stacks follow LIFO, and queues follow FIFO.
  2. What is the primary characteristic of a stack data structure? A) First-In, First-Out (FIFO) B) Last-In, First-Out (LIFO) C) Random access by index D) Elements connected by pointers Correct Answer: Last-In, First-Out (LIFO) Rationale: A stack follows the LIFO principle, meaning the most recently added element is the first one removed. Queues follow FIFO, arrays allow random access by index, and linked lists use pointers.

Correct Answer: Graph Rationale: A graph is a data structure consisting of nodes (vertices) connected by edges, used to model relationships and networks. Arrays, stacks, and queues are linear data structures with different organizational principles.

  1. What is the primary purpose of a tree data structure? A) To store elements in a linear sequence B) To represent hierarchical relationships between nodes C) To follow the LIFO principle D) To follow the FIFO principle Correct Answer: To represent hierarchical relationships between nodes Rationale: A tree is a hierarchical data structure consisting of nodes, with a root at the top and children branching below. It represents hierarchical relationships. Linear sequences, LIFO, and FIFO are characteristics of other data structures.
  2. In a tree data structure, what is the root? A) A node with no children B) The topmost node of the tree C) A node connected to exactly one other node D) The last node in the tree Correct Answer: The topmost node of the tree Rationale: The root is the topmost node of a tree, from which all other nodes descend. A leaf is a node with no children, and internal nodes have at least one child. The root has no parent.
  3. Which of the following best describes a leaf node in a tree? A) A node with no children

B) The topmost node C) A node with exactly one child D) A node connected to all other nodes Correct Answer: A node with no children Rationale: A leaf node is a node in a tree that has no children. The root is the topmost node, and internal nodes have at least one child. Leaf nodes represent the endpoints of the tree's branches.

  1. What is the primary function of a queue's enqueue operation? A) To remove an element from the front of the queue B) To add an element to the end of the queue C) To view the first element without removing it D) To check if the queue is empty Correct Answer: To add an element to the end of the queue Rationale: The enqueue operation adds an element to the end (rear) of the queue. Dequeue removes from the front, front views the first element, and isEmpty checks the queue's status.
  2. In a stack, what operation removes the top element? A) Push B) Pop C) Peek D) Enqueue Correct Answer: Pop

C) A data structure that stores key-value pairs D) A function that returns a value Correct Answer: A control structure that executes different code based on a condition Rationale: A conditional statement, such as if-else, evaluates a condition and executes different code blocks depending on whether the condition is true or false. Loops repeat code, dictionaries store key-value pairs, and functions encapsulate reusable logic.

  1. In the context of algorithms, what does finiteness mean? A) The algorithm can run forever without stopping B) The algorithm must terminate after a finite number of steps C) The algorithm can only handle finite input D) The algorithm uses a finite amount of memory Correct Answer: The algorithm must terminate after a finite number of steps Rationale: Finiteness is a key property of algorithms, meaning they must terminate after a finite number of steps. It does not mean the algorithm can run forever, only handle finite input, or use a finite amount of memory.
  2. What is the primary purpose of a while loop? A) To execute a block of code a fixed number of times B) To execute a block of code as long as a condition remains true C) To define a function D) To declare a constant Correct Answer: To execute a block of code as long as a condition remains true

Rationale: A while loop checks a condition before each iteration and continues executing as long as the condition is true. A for loop is typically used for a fixed number of iterations. Functions and constants are separate concepts.

  1. Which of the following is a valid identifier for a variable in most programming languages? A) 2ndPlace B) total_score C) class D) my-var Correct Answer: total_score Rationale: Variable names typically must start with a letter or underscore and contain only letters, digits, and underscores. "2ndPlace" starts with a digit, "class" is a reserved keyword, and "my-var" contains a hyphen. "total_score" follows common naming conventions.
  2. What does the term "scope" refer to in programming? A) The region of a program where a variable is accessible B) The speed at which a program executes C) The number of lines in a function D) The type of data a variable can hold Correct Answer: The region of a program where a variable is accessible Rationale: Scope defines the visibility and lifetime of a variable within different parts of a program. It is not about execution speed, function length, or data type. Local variables are accessible only within their defining block, while global variables have broader scope.
  3. Which of the following best describes a global variable? A) A variable declared inside a function

Rationale: The return statement ends the function's execution and optionally passes a value back to the code that called it. Printing, variable declaration, and loops are separate operations. A function without a return statement may return None or void.

  1. Which of the following is a characteristic of a list in programming? A) It can store multiple values in a single variable B) It can only store values of the same data type C) It has a fixed size that cannot change D) It does not support indexing Correct Answer: It can store multiple values in a single variable Rationale: Lists are ordered collections that can hold multiple items, often of different types, in a single variable. They are typically dynamic, support indexing, and can grow or shrink. Fixed size and homogeneous types are characteristics of arrays in some languages, not general lists.
  2. What is the index of the first element in most programming languages? A) 1 B) 0 C) - D) The length of the list Correct Answer: 0 Rationale: Most programming languages use zero-based indexing, meaning the first element of a list or array is at index 0. Some languages use 1-based indexing, but 0 is the most common. The length of the list is the total number of elements, not the first index.
  3. Which operation adds an element to the end of a list? A) append

B) remove C) insert D) delete Correct Answer: append Rationale: The append method adds an element to the end of a list. Remove deletes an element, insert adds at a specific position, and delete removes an element or the entire list. Append is commonly used to build lists dynamically.

  1. What is the primary purpose of a dictionary in programming? A) To store key-value pairs for efficient lookup B) To perform mathematical calculations C) To control the flow of a program D) To display graphical user interfaces Correct Answer: To store key-value pairs for efficient lookup Rationale: A dictionary (or map) stores data as key-value pairs, allowing fast retrieval of a value based on its unique key. It is not primarily for calculations, flow control, or GUI display. Dictionaries are ideal for associative data.
  2. Which of the following best describes a set in programming? A) An unordered collection of unique elements B) An ordered collection that allows duplicates C) A key-value pair storage structure D) A type of loop Correct Answer: An unordered collection of unique elements