Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Programming and Algorithms, Exams of Computer Science

Examples and exercises related to programming, algorithms, and data structures. It covers topics such as program development, user needs, encryption, and binary search algorithms. It also includes exercises on coding segments and flowcharts.

Typology: Exams

2023/2024

Available from 05/30/2024

maryjayson
maryjayson ๐Ÿ‡ฌ๐Ÿ‡ง

413 documents

1 / 21

Toggle sidebar

Related documents


Partial preview of the text

Download Programming and Algorithms and more Exams Computer Science in PDF only on Docsity! Comp sci Practice Attempt - 2020 Practice Exam 1 MCQ Questions with Answers 2024 Which of the following expressions represents the value stored in the variable x as a result of executing the program? A. 2 * 3 * 3 * 3 B. 2 * 4 * 4 * 4 C. 2 * 3 * 3 * 3 * 3 D 2 * 4 * 4 * 4 * 4 โœ” C A small team of wildlife researchers is working on a project that uses motion-activated field cameras to capture images of animals at study sites. The team is considering using a "citizen science" approach to analyze the images. Which of the following best explains why such an approach is considered useful for this project? A Distributed individuals are likely to be more accurate in wildlife identification than the research team. B The image analysis is likely to be more consistent if completed by an individual citizen. C The image analysis is likely to require complex research methods. D The image analysis is likely to take a longer time for the research team than for a distributed group of individuals. โœ” D An algorithm is intended to display the following output. red red blue red red blue red red blue Which of the following code segments can be used to display the intended output? โœ” C In a certain computer program, two positive integers are added together, resulting in an overflow error. Which of the following best explains why the error occurs? A The program attempted to perform an operation that is considered an undecidable problem. B The precision of the result is limited due to the constraints of using a floating-point representation. C The program can only use a fixed number of bits to represent integers; the computed sum is greater than the maximum representable value. D The program cannot represent integers; the integers are converted into decimal approximations, leading to rounding errors. โœ” C For which of the following input values will the circuit have an output of true ? A A = true, B = true, C = true, D = false B A = true, B = false, C = false, D = true C A = false, B = true, C = true, D = true D A = false, B = false, C = true, D = true โœ” The following programs are each intended to move the robot to the gray square. Program II uses the procedure GoalReached, which returns true if the robot is in the gray square and returns false otherwise. Which of the following statements best describes the correctness of the programs? A Program I correctly moves the robot to the gray square, but program II does not. B Program II correctly moves the robot to the gray square, but program I does not. C Both program I and program II correctly move the robot to the gray square. D Neither program I nor program II correctly moves the robot to the gray square. โœ” C Flight simulation software, which imitates the experience of flying, is often used to train airline pilots. Which of the following is LEAST likely to be an advantage of using flight simulation software for this purpose? A Flight simulation software allows pilots to practice landing in a variety of different terrains and weather conditions without having to physically travel. B Flight simulation software could save money due to the cost of maintenance and fuel for actual training flights. C Flight simulation software provides a more realistic experience for pilots than actual training flights. D โœ” B Which of the following best compares the values displayed by programs A and B? A Program A and program B display identical values in the same order. B Program A and program B display the same values in different orders. C Program A and program B display the same number of values, but the values differ. D Program B displays one more value than program A. โœ” A A student wrote the following program to remove all occurrences of the strings "the" and "a" from the list wordList. Line 1: index โ†โ† LENGTH (wordList) Line 2: REPEAT UNTIL (index < 1) Line 3: { Line 4: IF ((wordList[index] = "the") OR (wordList[index] = "a")) Line 5: { Line 6: REMOVE (wordList, index) Line 7: } Line 8: } While debugging the program, the student realizes that the loop never terminates. Which of the following changes can be made so that the program works as intended? A Inserting index โ†โ† index + 1 between lines 6 and 7 B Inserting index โ†โ† index + 1 between lines 7 and 8 C Inserting index โ†โ† index - 1 between lines 6 and 7 D Inserting index โ†โ† index - 1 between lines 7 and 8 โœ” D Which of the following can be represented by a sequence of bits? An integer An alphanumeric character A machine language instruction A I only B III only C I and II only D I, II, and III โœ” D The code segment below uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise. REPEAT UNTIL (GoalReached ()) { <MISSING CODE> } Which of the following replacements for <MISSING CODE> can be used to move the robot to the gray square? A REPEAT UNTIL (CAN_MOVE (forward) = false) {ROTATE_RIGHT () } MOVE_FORWARD () B REPEAT UNTIL (CAN_MOVE (forward) = false) { MOVE_FORWARD () } ROTATE_RIGHT () C REPEAT UNTIL (CAN_MOVE (right)) { ROTATE_RIGHT () } MOVE_FORWARD () D REPEAT UNTIL (CAN_MOVE (right)) { MOVE_FORWARD () } ROTATE_RIGHT () โœ” B Which of the following best describes the growth in the number of registered users for the first eight years of the application's existence? A The number of registered users increased at about a constant rate each year for all eight years. B The number of registered users increased at about a constant rate for years 1 to 5 and then about doubled each year after that. C The number of registered users about doubled each year for years 1 to 5 and then increased at about a constant rate after that. D The number of registered users about doubled each year for all eight years. โœ” C Which of the following best describes the average amount of data stored per user for the first eight years of the application's existence? A Across all eight years, the average amount of data stored per user was about 10 GB. B Across all eight years, the average amount of data stored per user was about 100 GB. C The average amount of data stored per user appears to increase by about 10 GB each year. D The average amount of data stored per user appears to increase by about 100 GB each year. โœ” A Which of the following observations is most consistent with the information in the circle graph? A Over 75% of the files stored are 1 MB in size or less. B Over 75% of the files stored are 10 MB in size or less. C Over 75% of the files stored are at least 100 KB in size. D Over 75% of the files stored are at least 1 MB in size. โœ” B Which of the following code segments can be used to simulate the behavior of the spinner? โœ” D Which of the following statements is equivalent to the algorithm in the flowchart? โœ” B Which of the following describes the result of executing the program? A The program displays the sum of the even integers from 2 to 10. B The program displays the sum of the even integers from 2 to 20. C The program displays the sum of the odd integers from 1 to 9. D The program displays the sum of the odd integers from 1 to 19. โœ” B Which of the following statements correctly explain how the Internet is able to facilitate communication at a large scale? A central monitoring computer is used to track and maintain the connections of the Internet. Data is routed between points in multiple ways so that if a connection fails, the data can be rerouted around the inoperative connections. Protocols for packets and routing are used so that computers from different manufacturers can communicate in a standard way. A student's overall course grade in a certain class is based on the student's scores on individual assignments. The course grade is calculated by dropping the student's lowest individual assignment score and averaging the remaining scores. For example, if a particular student has individual assignment scores of 85, 75, 90, and 95, the lowest score (75) is dropped. The calculated course grade is (85+90+95)/3=90(85+90+95)/3=90. An administrator at the school has data about hundreds of students in a particular course. While the administrator does not know the values of each student's individual assignment scores, the administrator does have the following information for each student. The student name A unique student ID number The number of assignments for the course The average assignment score before the lowest score was dropped The course grade after the lowest score was dropped Which of the following CANNOT be deter โœ” A Which of the following code segments will move the robot to the gray square along the path indicated by the arrows? A B C D โœ” C A programmer notices the following two procedures in a library. The procedures do similar, but not identical, things. Procedure MaxTwo (x, y) returns the greater of its two integer parameters. Procedure MaxThree (x, y, z) returns the greatest of its three integer parameters. Which of the following procedures is a generalization of the MaxTwo and MaxThree procedures? A Procedure Min (x, y), which returns the lesser of its two integer parameters B Procedure Max (numList), which returns the maximum value in the list of integers numList C Procedure MaxFour (w, x, y, z), which returns the greatest of its four integer parameters D Procedure OverMax (numList, max), which returns the number of integers in numList that exceed the integer value max โœ” B A group of planners are using a simulation to examine whether or not a park that they are designing is going to affect foot traffic in the area. The simulation uses a model that includes input variables for the park such as the number of entrances, sidewalks, and bike trails and the square footage of open space (grassy areas). The simulation can then be run multiple times using different values for the input variables to represent different park designs. However, the simulation takes a very long time to run. The planners update the model by removing some variables they consider less important than others. Of the following, which is the most likely effect the updated model will have on the simulation? A The updated model is likely to decrease the runtime of the simulation because the time required for simulations generally depends on the complexity of the model used. B The updated model is likely to decrease the runti โœ” A The following code segment is intended to draw the figure. startX โ†โ† 2 startY โ†โ† 6 endX โ†โ† 8 endY โ†โ† 8 REPEAT 4 TIMES { <MISSING CODE> } Which of the following can be used to replace <MISSING CODE> so that the figure is drawn correctly? A DrawLine (startX, startY, endX, endY) endY โ†โ† endY - 2 B DrawLine (startX, startY, endX, endY) endX โ†โ† endX - 2 endY โ†โ† endY - 2 C endY โ†โ† endY - 2 DrawLine (startX, startY, endX, endY) D endX โ†โ† endX - 2 endY โ†โ† endY - 2 DrawLine (startX, startY, endX, endY) โœ” A Internet protocol version 6 (IPv6) has been introduced to replace the previous version (IPv4). Which of the following best describes a benefit of IPv6 over IPv4? A IPv6 addresses are shorter than IPv4 addresses, which allows for faster routing of packets. B IPv6 allows for a greater number of addresses than IPv4, which allows more devices to be connected to the Internet. C IPv6 eliminates the use of hierarchy in addressing, making addresses easier to use. D IPv6 allows users to bypass older security protocols so that data can be sent peer-to- peer without the use of routers. โœ” B Assume that the list of numbers nums has more than 10 elements. The program below is intended to compute and display the sum of the first 10 elements of nums. Line 1: i โ†โ† 1 Line 2: sum โ†โ† 0 Line 3: REPEAT UNTIL (i > 10) Line 4: { Line 5: i โ†โ† i + 1 Line 6: sum โ†โ† sum + nums[i] Line 7: } Line 8: DISPLAY (sum) Which change, if any, is needed for the program to work as intended? A Lines 1 and 2 should be interchanged. B Line 3 should be changed to REPEAT UNTIL (i โ‰ฅ 10). C Lines 5 and 6 should be interchanged. D No change is needed; the program works correctly. โœ” C Which of the following best explains how a certificate authority is used in protecting data? A A certificate authority certifies the safety of a particular Web site so that users know that it does not contain any viruses. B A certificate authority issues passwords that grant access to secure databases. C A certificate authority maintains a secure database that maps all Web domain names to the IP addresses of the servers where the sites are hosted. D A certificate authority verifies the authenticity of encryption keys used in secured communications. โœ” D A photographer has a collection of digital pictures, each using the same file-naming format: a date tag, followed by a description, followed by the file extension ".jpg". The photographer wants to write a code segment to extract the description from each file name, as shown in the following table. Original File NameExtracted Description2016-05-22-Andrews-Graduation.jpgAndrews- Graduation2016-07-04-Fireworks.jpgFireworks2017-10-18-Grandmas- Birthday.jpgGrandmas-Birthday The photographer has the following procedures available. Procedure CallExplanationTrimLeft (str, n)Returns a copy of the string str with the n leftmost characters removed. For example, TrimLeft ("keyboard", 3) returns "board".TrimRight (str, n)Returns a copy of the string str with the n rightmost characters removed. For example, TrimRight ("keyboard", 3) returns "keybo". Let an original file name be stored in the string variable original. Which of the โœ” C A Creative Commons gives creators of digital content the ability to indicate how their works can be legally used and distributed, enabling broad access to digital information. B Creative Commons gives Internet users the right to legally use and distribute any previously copyrighted work, enabling broad access to digital information. C Create Commons provides lossless transmission of messages, enabling reliable distribution of digital information. D Creative Commons provides private transmission of messages, enabling secure distribution of digital information. โœ” A Code for the simulation is shown below. hours โ†โ† 0 startPop โ†โ† InitialPopulation () currentPop โ†โ† startPop REPEAT UNTIL ((hours โ‰ฅ 24) OR (currentPop โ‰ค 0)) { currentPop โ†โ† NextPopulation (currentPop) hours โ†โ† hours + 1 } DISPLAY (currentPop - startPop) Which of the following are true statements about the simulation? The simulation continues until either 24 hours pass or the population reaches 0. The simulation displays the average change in population per hour over the course of the simulation. The simulation displays the total population at the end of the simulation. A I only B II only C III only D I and II โœ” A A system is being developed to help pet owners locate lost pets. Which of the following best describes a system that uses crowdsourcing? A A mobile application and collar that uses GPS technology to determine the pet's location and transmits the location when the owner refreshes the application B A mobile application and collar that uses wireless technology to determine whether the pet is within 100 feet of the owner's phone and transmits a message to the owner when the pet is nearby C A mobile application that allows users to report the location of a pet that appears to be lost and upload a photo that is made available to other users of the application D A mobile application that transmits a message to all users any time a lost pet is returned to its owner โœ” C Assume that the list originalList contains integer values and that the list newList is initially empty. The following code segment is intended to copy all even numbers from originalList to newList so that the numbers in newList appear in the same relative order as in originalList. The code segment may or may not work as intended. Line 1: FOR EACH number IN originalList Line 2: { Line 3: IF (number MOD 2 = 0) Line 4: { Line 5: INSERT (newList, 1, number) Line 6: } Line 7: } Which of the following changes, if any, can be made so that the code segment works as intended? A Changing line 1 to FOR EACH number IN newList B Changing line 3 to IF (number MOD 2 = 1) C Changing line 5 to APPEND (newList, number) D No change is needed; the code segment is correct as is. โœ” C The following algorithm is intended to determine the average height, in centimeters, of a group of people in a room. Each person has a card, a pencil, and an eraser. Step 2 of the algorithm is missing. Step 1: All people stand up. Step 2: (missing step) Step 3: Each standing person finds another standing person and they form a pair. If a person cannot find an unpaired standing person, that person remains standing and waits until the next opportunity to form pairs. Step 4: In each pair, one person hands their card to the other person and sits down. Step 5: At this point, the standing person in each pair is holding two cards. The standing person in each pair replaces the top number on their card with the sum of the top numbers on the two cards and replaces the bottom number on their card with the sum of the bottom numbers on the two cards. The sitting partner's card is discarded. Step 6: Repeat steps 3-5 until there is โœ” A An online game collects data about each player's performance in the game. A program is used to analyze the data to make predictions about how players will perform in a new version of the game. The procedure GetPrediction (idNum) returns a predicted score for the player with ID number idNum. Assume that all predicted scores are positive. The GetPrediction procedure takes approximately 1 minute to return a result. All other operations happen nearly instantaneously. Two versions of the program are shown below. Version I topScore โ†โ† 0 idList โ†โ† [1298702, 1356846, 8848491, 8675309] FOR EACH id IN idList { score โ†โ† GetPrediction (id) IF (score > topScore) { topScore โ†โ† score } } DISPLAY (topScore) Version II idList โ†โ† [1298702, 1356846, 8848491, 8675309] topID โ†โ† idList[1] FOR EACH id IN idList { IF (GetPrediction (id) > GetPrediction (topID)) { topID โ†โ† id } } DISPLAY (GetPrediction (topID)) Which of the following best c โœ” D The transmission control protocol (TCP) and Internet protocol (IP) are used in Internet communication. Which of the following best describes the purpose of these protocols? A To ensure that communications between devices on the Internet are above a minimum transmission speed B To ensure that private data is inaccessible to unauthorized devices on the Internet C To establish a common standard for sending messages between devices on the Internet D Multiply -2, -5 โœ” B AND D Which of the following can be used to store the string "jackalope" in the string variable animal ? Select two answers. A animal โ†โ† Substring ("antelope", 5, 4) animal โ†โ† Concat (animal, "a") animal โ†โ† Concat (Substring ("jackrabbit", 1, 4), animal) B animal โ†โ† Substring ("antelope", 5, 4) animal โ†โ† Concat ("a", animal) animal โ†โ† Concat (Substring ("jackrabbit", 1, 4), animal) C animal โ†โ† Substring ("jackrabbit", 1, 4) animal โ†โ† Concat (animal, "a") animal โ†โ† Concat (animal, Substring ("antelope", 5, 4)) D animal โ†โ† Substring ("jackrabbit", 1, 4) animal โ†โ† Concat (animal, "a") animal โ†โ† Concat (Substring ("antelope", 5, 4), animal) โœ” B AND C In mathematics, a perfect number is a type of integer. The procedure IsPerfect (num) returns true if num is a perfect number and returns false otherwise. The following program is intended to count and display the number of perfect numbers between the integers start and end, inclusive. Assume that start is less than end. The program does not work as intended. Line 1: currentNum โ†โ† start Line 2: count โ†โ† 0 Line 3: REPEAT UNTIL (currentNum > end) Line 4: { Line 5: count โ†โ† count + 1 Line 6: IF (IsPerfect (currentNum)) Line 7: { Line 8: count โ†โ† count + 1 Line 9: currentNum โ†โ† currentNum + 1 Line 10: } Line 11: currentNum โ†โ† currentNum + 1 Line 12: } Line 13: DISPLAY (count) Which two lines of code should be removed so that the program will work as intended? Select two answers. A Line 5 B Line 8 C Line 9 D Line 11 โœ” A AND C
Docsity logo



Copyright ยฉ 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved