Week 1 -2-3-4-5-6

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

D (Explanation: Machine code is pure binary digits, zeros and ones.)

The language directly understood and executed by a computer, consisting of pure 0s and 1s. A- Architecture B- Pseudocode C- Artificial Intelligence D- Machine Language E- Assembly Language

B (Explanation The constructor is defined in lines 4 through 6. The toString method defined in lines 7 and 8 controls how the object will be displayed when output.)

1 class StudentInfo 2 private int age 3 private string name 4 StudentInfo(string n, int a) 5 name ← n 6 age ← a 7 string toString() 8 return "Name:"+name+", Age:"+age 9 void setName(string n) 10 name ← n 11 void setAge(int a) 12 age ← a 13 string getName() 14 return name 15 int getAge() 16 return age 17 end class StudentInfo Which of the statements below is NOT correct regarding the class definition shown above? A- Lines 2 and 3 contain private instance field declarations B- The method defined in lines 7 and 8 controls the construction of a StudentInfo object C- The methods defined in lines 9 through 12 are mutator methods D- The methods defined in lines 13 through 16 are accessor methods

A (Explanation Since the instance field age is private, it is not possible to directly access it using dot notation. The proper way is to use the getAge() accessor method.)

1 class StudentInfo 2 private int age 3 private string name 4 StudentInfo(string n, int a) 5 name ← n 6 age ← a 7 string toString() 8 return "Name:"+name+", Age:"+age 9 void setName(string n) 10 name ← n 11 void setAge(int a) 12 age ← a 13 string getName() 14 return name 15 int getAge() 16 return age 17 end class StudentInfo 18 //client code 19 StudentInfo s ← new StudentInfo("Harry",23) 20 client code statement Using the class definition and client code shown above, which of the following is NOT a valid client code statement for line 20? A- print s.age B- s.setAge(24) incorrect C- print s.toString() D- print s.getAge()

B (Explanation: The term "bit" stands for "binary digit", and represents an electronic impulse that is either zero volts or around 5 volts of power.)

The fundamental type of data in a computer, often represented as zero and 1, false and true, off and on, etc. A- AI B- Bit C- DOS D- Byte

D (Explanation: Abstraction refers to the idea that not all about an object needs to be known or accessible in order to interface with it or use it.)

A certain method of class A works in a certain way, but how this is accomplished is not known. A- Inheritance B- Encapsulation C- Polymorphism D- Abstraction E- Composition

E (Explanation: When previously developed and tested modules already exist that will accomplish part of the job, it is certainly wise to use them in the design and implementation process.)

A design process that takes previously developed and tested modules to build a larger software project. A- UML B- Flowchart C- Top down D- Stepwise refinement E- Bottom up

E (Explanation: Data is simply information that comes in several data types, such as numbers, text, and true or false values.)

A general term that refers to information used by a computer program, such as words and values. A- procedure B- data structure C- method D- data type E- data

E (Explanation: A linked list is linear, and has the ability to add, access, and delete elements as necessary, anywhere in the collection.)

A linear data structure is required that needs to be flexible in size, where elements can be added and accessed anywhere in the list. Which of the following data structures meets these requirements? A- Array B- Tree C- Stack D- Queue E- Linked List F- Graph

F (Explanation: Overriding is when a method inherited from another class is customized for more specific use for the new object.)

A method of class F that was inherited from class G is redefined. A- Composition B- Polymorphism - polymorphic object C- Abstraction D- Encapsulation E- Inheritance F- Polymorphism - overriding G- Polymorphism - overloading

E (Explanation: Procedures (void methods) perform tasks without returning values. Fuctions (return methods) return some kind of value based on a calculation of some sort.)

A programming block of code that returns a calculated value. A- Definition B- Call C- Header D- Procedure, void method E- Function, return method

C (Explanation: High level languages were created to make it easier to develop programs, which were then translated to machine language using a compiler or interpreter.)

A programming language using words and commands easy for humans to understand and organize, but which must be translated into a language easy for the computer to understand and execute. A- Low Level B- Syntax diagram C- High Level correct D- Backus-Naur

B (Explanation Although selection sort also appears to be a close fit, recall that selection sort finds the best value for the next place, where the insertion sort finds the best place for the next value.)

A sort algorithm finds the best place in an already sorted portion of the list for the next unsorted item. Which sort algorithm best fits this description? A- selection sort B- insertion sort C- merge sort D- quick sort

D (Explanation: The state of a minimum heap is that the root node is always the smallest value, and is optimal for implementing a priority queue, where the root is removed each time during a pop operation. The last element of the tree is placed in the root position after the pop operation, and the min heap state is restored, ready for the next pop operation.)

A special kind of queue is required where elements are inserted in natural ascending order, often called a priority queue. The element popped from the front of this queue is always the smallest item in the list. Which of the following data structures will best implement this requirement? A- Linked List B- Array C- Binary Search Tree D- Minimum Heap

B (Explanation: The statement that executes the process, either from another location in the program, or through a recursive statement inside the process, is referred to as the method call.)

A statement that activates a procedure, function, or method A- Return method B- Call C- Definition D- Header E- Void method

C (Explanation: The postcondition statement is used to help the reader of the code know what can be expected as the result of a process.)

A structured comment block that describes what type of result a process expects to provide. A- Class B- Precondition C- Postcondition D- Constant E- Method

A (Explanation: The primary use of a switch statement is to provide a more clarified structure to use in the event a chain of else statements gets too long winded.)

A switch statement is useful when your program logic contains a chain of ______. A- if else statements B- variable declarations C- loops D- method calls E- parameters

D (Explanation: Since the 6 is greater than the 5, it slides to the right, and then to the left of the 7, inserted in the left child position of the 7. 5 / \ 3 7 / \ / 1 4 6 )

After the integer elements 5, 3, 7, 1, 2, 4 are correctly inserted into a binary search tree, and the value 6 is then added to the tree, which statement below best describes the resulting position of the node that contains the 6? A- Right child of 4 B- Left child of 1 C- Root node D- Left child of 7

B (Explanation: Since all positions are filled at all levels, this is a full, complete, and balanced tree.)

After the integer elements 5, 3, 7, 1, 2, 4 are correctly inserted into a minimum heap tree, with the value 5 as the initial root, and the value 6 added to the heap, which term or terms below best describes the resulting tree? I. Full tree II. Complete tree III. Balanced tree A- II only B- III only C- I only D- All of these

C (Explanation: The heap insertion process starts with 5 as the root, which is then switched with the 3 when that is added to the left, in order to restore the min heap state (all parents less than kids). The 7 is added to the right, with no adjustment necessary. When the 1 is added to the left of the 3, it must be moved all the way to the root, moving the 5 and 3 down the left subtree one level each. When the 2 is added to the right of the 3, those two elements must be switched to maintain the min heap state. The 4 is added to the left of the 7, and then those two values are switched, resulting in the tree with 1 as the root, 2 and 4 at the next level, and 5, 3, and 7 at the lowest level. 5 3 3 1 1 1 / / \ / \ / \ / \ 5 5 7 3 7 2 7 2 4 / / \ / \ / 5 5 3 5 3 7 The pre-order traversal starts at the root and retrieves the value of each node as it is visited on the left, starting with the 1, then the 2, 5

After the integer elements 5, 3, 7, 1, 2, 4 are correctly inserted into a minimum heap tree, with the value 5 as the initial root, what is the preorder traversal of the tree? A- 5 3 2 7 4 1 B- 1 2 3 4 5 7 C- 1 2 5 3 4 7 D- 5 2 3 1 7 4

C (Explanation: The nature of the binary search tree is that all of the elements are in relative order, and when an inorder traversal is performed, the result is just that...the elements in ascending order. The resulting tree has 5 as the root, 3 and 7 at the next level, 1 and 4 as children of 3, and 2 as the right child of 1. 5 / \ 3 7 / \ 1 4 \ 2 )

After the integer elements 5, 3, 7, 1, 2, 4 are correctly inserted into an ascending order binary search tree, what is the resulting inorder traversal? A- 1 2 5 3 4 7 B- 5 3 1 2 4 7 C- 1 2 3 4 5 7 D- 5 3 1 2 7 4

B (Explanation: Encapsulation refers to the idea that an object is all packaged together in a bundle, to be used as one entity.)

An aspect of object oriented programming that incorporates related data items and methods into a class definition, including instance variables, constructors, accessor and modifer methods. A- Inheritance B- Encapsulation C- Abstraction D- Polymorphism E- Composition

B (Explanation The bubble sort is characterized by the use of a boolean value that helps detect a clear pass when all values are in sorted order. A pass through the list is made repeatedly, swapping neighboring elements that are out of order. The boolean value is initially set to true at the beginning of each pass, and set to false whenever a swap is made. Once a clear pass is achieved, and the boolean value remains true, the sort is completed.)

Assume there is a function defined swap( pass-by-reference int [] list, int position1, int position2 ) which swaps values in the array list at index position1 and index position2. What sorting routine is represented by the code shown below? void mystSort( pass-by-reference int [] list ) boolean b ← false while ( not b ) b ← true for ( int k ← 0; k < list.length - 1; k ← k + 1 ) if ( list[ k ] > list[ k + 1] ) swap( list, k, k + 1 ) b ← false end if end for end while end void A- Selection B- Bubble C- Insertion D- Quick E- Merge

D (Explanation: An identifier cannot contain any symbols, except for the underscore character.)

Choose the statement below that best classifies the following identifier example. me%You A- Invalid - does not start with a letter or underscore B- Valid C- Invalid identifier - contains spaces D- Invalid - contains invalid symbols E- Invalid identifier - Java reserved word

A (Explanation: This is perfectly good identifier.)

Choose the statement below that best classifies the following identifier example. name A- Valid B- Invalid identifier - contains spaces C- Invalid - contains invalid symbols D- Invalid identifier - Java reserved word E- Invalid - does not start with a letter or underscore

D (Explanation: This is a standard convention among most languages.)

Choose the statement that best classifies the identifier creation guideline shown. A- Constants in all upper case letters. B- Good idea C- Rule D- Convention

B (Explanation: This is the primary rule for creating identifiers.)

Choose the statement that best classifies the identifier creation guideline shown. Contains only alphanumeric characters, or the underscore character A- Good idea B- Rule C- Convention

C (Explanation Ultimately, the entire list must be divided into sublists with only 1 element each. Since there are 8 elements to begin with, it will take 7 divisions to create 8 sublists with 1 element each. The first division creates two lists of four elements each. The next division splits the left side into two elements each, then the left side of that division splits into one element each, stopping the division process for that portion, and then merging those two into a sorted portion. The right side containing two elements is then split into halves of size one, and then merged back into a sorted portion. Those two sorted two-element portions are then merged back into the sorted left half four-element portion. The right half of the original list then undergoes the same division and merging process, until the entire list is merged back into a completely sorted list.)

Consider a list that contains eight integer values. If the list is sorted using the merge sort, how many total division operations will take place during the entire process? A- 1 B- 3 C- 7 D- 8

B (Explanation Three operations are required. The first "middle" value considered is 14 in position 4(middle of positions 0-9), then 123 in position 7(middle of 5-9), and finally 34 in position 5(middle of 5-6).)

Consider a list: { 3, 5, 8, 10, 14, 34, 78, 123, 513, 999 } If a binary search for the value 34 is performed, how many comparison operations will be required to find it? A- 1 B- 3 C- 5 D- 6

B (Explanation A linear search will return the index of the target value. In this case, the first instance of the value -1 occupies position 9 in the list.)

Consider a list: { 9, 2, 6, 8, -3, 7, 2, 15, 0, -1, 14, 99, -1 } If a linear search for the value -1 is performed, what will be returned? A- -1 B- 9 C- 10 D- 12

C (Explanation During an ascending order insertion sort, the value to be inserted will occupy a space made available by shifting greater values one space to the right until the next value is no longer greater than the value being considered. In this case, 5, 6 and 7 must be shifted so that 4 must be placed after the 1. Therefore, 3 shifts will occur.)

Consider a partially sorted list that is undergoing the insertion sort in ascending order, with the first four values already in sorted order: { 1, 5, 6, 7, 4, 2, 3 } How many shifts must be performed to insert the value 4 into the correct position? A- 1 B- 2 C- 3 D- 4

A (Explanation In each pass of a selection sort, the next smallest value (in an ascending sort) is placed in the correct position. The only values that are swapped are the next smallest value and the value in the position where the next smallest value should go. In this case, the next smallest value after 0, 1 and 2 is 3. Therefore, the values 3 and 4 will be swapped in the next pass.)

Consider the following array, partially sorted using a selection sort process. { 0, 1, 2, 4, 5, 7, 3, 6 } If elements have been correctly selected for the first three positions, what will the array look like after the next pass? A- { 0, 1, 2, 3, 5, 7, 4, 6 } B- { 0, 1, 2, 3, 5, 6, 4, 7 } C- { 0, 1, 2, 3, 5, 4, 6, 7 } D- { 0, 1, 2, 3, 4, 5, 7, 6 }

B (Explanation During the first pass, the 6 makes its way to the end, swapping places with 4, and then 2, with a final first pass order of 0, 1, 4, 2, 6. In the second pass, 4 swaps with the 2, with a final order of 0, 1, 2, 4, 6. Although the list is clearly in order, a final clear pass is required for the bubble sort, which makes a total of three passes to sort this list.)

Consider the following array: { 0, 1, 6, 4, 2} In how many passes will an ascending order bubble sort be accomplished? A- 2 B- 3 C- 4 D- 5

C (Explanation Working from the outside ends of the list towards the pivot value, a quick sort pass will swap elements on either side of the pivot that are on the wrong side. During this process, a right side index and left side index move toward the pivot and swap "out of position" values. In this case, 6 and 2 will swap positions and 7 and 3 will swap positions.)

Consider the following list: { 1, 6, 7, 4, 3, 9, 2, 5, 8 } If the entire list is undergoing the initial partitioning pass using a quick sort process, with the middle value as the pivot, what will the list look like after the first pass? A- { 1, 2, 7, 4, 3, 9, 6, 5, 8 } B- { 1, 6, 7, 4, 3, 9, 2, 5, 8 } C- { 1, 2, 3, 4, 7, 9, 6, 5, 8 } D- { 1, 6, 4, 3, 7, 2, 5, 8, 9 }

C (Explanation The code shows the list being repeatedly divided into two halves, with no regard to the actual values contained, using a recursive process. The rest of the code merges each pair of divided lists back into the larger list in sorted order, resulting in a final sorted list. This is the nature of the merge sort.)

Consider the following partial pseudocode for a sort: void sort(pass-by-reference int [] list, int lo, int hi ) if ( lo ≠ hi ) sort( list, lo, (lo + hi) / 2 ) sort( list, (lo + hi) / 2 + 1, hi) end if ...more code here end void Which sort is this code most likely to represent? A- insertion sort B- selection sort C- merge sort D- quick sort

D (Explanation If the size of the partition is 1 (lo is equal to hi), or zero (lo is greater than hi), a base case of the quick sort process has been reached with this partition, and no attempt will be made to further partition this segment of the list.)

Consider this partial pseudocode segment for a quick sort, given a lo and hi index representing the inclusive bounds of the partition to be sorted. void quickSort(pass-by-reference int [] list, int lo, int hi ) if ( lo ≥ hi ) return end if ...more code here What is the purpose of the if statement in this pseudocode? A- The if statement detects a pivot value and returns it. B- The if statement detects new bounds of a partition and returns it. C- The if statement detects that the entire list has been sorted and ends execution. D- The if statement detects a section of the list that is too small to partition any further and ends execution for that part of the process.

D (Explanation: Similar to the incremental process, an additional risk assessment was included in the process, deciding whether the change to be made was a risk worth taking in the whole process.)

Development process that combines features of other development models into a cyclical process, including several phases, one of which is risk analysis. A- Agile B- Incremental C- Waterfall D- Spiral

C (Explanation: For most languages, string variables will accept anything input from the keyboard, but more specialized variables, such as numeric values, boolean values, and characters, require precise data entry, otherwise a runtime error will occur.)

During the execution of a program, entering a string when an integer is expected is a ______________ error. A- Syntax B- Lexical C- Runtime D- Logic

B (Explanation The nature of an O(log N) process is that the maximum number of steps required to complete the task is the log value, base 2, of the size of the data set. In this case, 10 is the log value, base 2, of 1024, which is the closest exact power of 2 just beyond 1000. This means that it will take no more than 10 steps to process this list of 1000 elements using an O(log N) process.)

For a list of 1000 elements, using a process that is considered to have an O(log N) running time in all situations, what value below represents the maximum number of steps it will take for the algorithm to complete its task? A- 1 B- 10 C- 500 D- 1000

B (Explanation: Any punctuation type error is referred to as a syntax error.)

Forgetting to end a string with a double quote symbol is a ______________ error. A- Lexical B- Syntax C- Runtime D- Logic

C (Explanation: Since x decrements, getting smaller and smaller, this causes an infinite loop.)

How many stars will be output by this loop? int x ← -4 while(x < 0) print "*" x ← x - 1 A- None B- 4 C- Infinitely many D- 3 E- 5

C (Explanation: The check of a loop can happen many times, only once if the check is false, or more than once if the check is true, and finally, hopefully, reaching a false condition to stop the loop.)

How many times can the check of a loop happen? A- Only three times B- Only once C- One or more times D- Only four times E- Only twice

B (Explanation: The start of a loop only happens once.)

How many times can the start of a loop happen? A- Three times B- Once C- More than four times D- Four times E- Twice

C (Explanation: The action happens when "x < 23" is true, which is the case for the x values of 0 through 22, a total of 23 actions.)

How many times will the <action> statement happen in the loop shown? int x ← 0 while(x < 23) <action> x ← x + 1 A- 21 B- 22 C- 23 D- 24 E- 25

A (Explanation: Since the do while is a posttest loop, and always acts at least once, this loop will act one time before the while condition is deemed false, since 25 < 23 is a false condition.)

How many times will the action statement happen in the loop shown? int x ← 24 do{ <action> x ← x + 1 }while(x < 23) A- 1 B- 2 C- 4 D- 0 E- 3

D (Explanation: The main data types are: int - integer, non decimal float - decimal, like 3.14 char - single character, enclosed in single quotes, like 'A' string - a row of characters, enclosed in double quotes, like "HELLO" boolean - a true or false value)

Identify the data type for this value: "G" A- boolean B- char C- float D- string E- int

A (Explanation: The main data types are: int - integer, non decimal float - decimal, like 3.14 char - single character, enclosed in single quotes, like 'A' string - a row of characters, enclosed in double quotes, like "HELLO" boolean - a true or false value)

Identify the data type for this value: 9.532 A- float B- string C- char D- int E- boolean

A (Explanation: In order to insert an element of a linked list where only the head is referenced, it requires traversing the entire list using a temporary pointer object until it reaches the last element, at which time the new element is attached to the back of the list. This will take as many steps as there are elements in the list._)

If a linked list contains N elements, and only the head of the list is referenced, which statement below best describes how many steps it will take to insert another element at the back of the list? A- N steps B- One step C- N*2 steps D- N/2 steps

B (Explanation: The letter 'a' matches the first case, which has no action directly associated with it, but since there is no break, control falls down to the next statement, which is executed, resulting in "dog" being output, and then stopped by the break.)

In the switch statement shown below, what is the output when the letter 'a' is input? char let print "Enter a letter..." input let switch(let) case 'a': case 'A': print "dog"; break; case 'b': case 'B': print "cat"; case 'c': case 'C': print "pig";break; case 'd': case 'D': print "horse"; case 'e': case 'E': print "cow"; break; end switch A- dogcatpig B- dog C- dogcatpighorsecow D- nothing

A (Explanation: Variables in method headers are called formal parameters.)

In this pseudocode example, string name is an example of a(an) __________ parameter void sayHello(string name) print("Hello "+name+"!") void main sayHello("Suzy") A- Formal B- Actual

C (Explanation: Any word related error, including mixed up order or misspelling, is considered a lexical error.)

Not capitalizing a reserved word that should be capitalized in a programming statement is a ______________ error. A- Syntax B- Runtime C- Lexical D- Logic

B (Explanation: To get paycheck value of $480 for 40 hours work, a wage of $12 an hour is required, which is achieved the 4 case, therefore the input value in years must be 4.)

Problem Statement The switch statement below should calculate a week's pay based on number of years experience. For 1 year of experience, the hourly wage is $7, for 2 years $8 an hour, 3 years $10, 4 years $12, and 5 years $15 per hour. The number of hours will vary between 1 and 40 hours. What input value for years will result in a totalWeekPay output value of $480? int years input years int hours ← 40 int totalWeekPay = 0; switch(years) case 1: totalWeekPay = hours*7;break; case 2: totalWeekPay = hours*8;break; case 3: totalWeekPay = hours*10;break; case 4: totalWeekPay = hours*12;break; case 5: totalWeekPay = hours*15;break; end switch print "$"+totalWeekPay A- 5 B- 4 C- 2 D- 1 E- 3

C (Explanation: In an adjacency matrix, each value 1 represents the number of direct connections, or 1-hop paths from a vertex to another vertex. The sum of the 1s in the matrix represents the number of direct connections.)

The adjacency matrix of a 4-node graph is given below. How many direct connection paths exist in the graph that is represented by this matrix? PQRS P1010 Q0101 R1100 S0001 A- 6 B- 4 C- 7 D- 5

C (Explanation: The class is the definition of the "thing", and the object IS the "thing".)

The definition of an object in OOP, describing the type of data owned by the object, as well as methods that act on that data. A- object B- method C- class D- procedure E- function

B (Explanation: Inheritance is a key feature of OOP, where new objects are based on previously created, defined, and tested objects, streamlining the software development process.)

The feature of OOP that allows for classes to be defined based on previously defined and developed classes, receiving all of the characteristics of the original class, and then expanding on those features, easily identified as an "is a" relationship. A- Composition B- Inheritance C- Polymorphism D- Encapsulation E- Abstraction

C (Explanation: Software System Life Cycle - Five general steps 1 - Analysis 2 - Design 3 - Implementation (Coding) 4 - Testing 5 - Maintenance)

The stage in the software system life cycle that determines the structure of the software strategy and code. A- Analysis B- Maintenance C- Design D- Testing E- Implementation (Coding)

A (Explanation: Polymorphism relates to overloading, overriding, and the ability of parent objects to refer to child objects.)

The term that means "many forms", and which indicates a key element of object oriented programming, where methods can be overloaded or overridden as needed and desired. A- Polymorphism B- Inheritance C- Abstraction D- Composition E- Encapsulation

C (Explanation: A parameter passed by reference sends the memory location of the actual parameter to the formal parameter, where any changes made in the method by the formal parameter instantly change the state of the actual paramter.)

The type of parameter where changes by the method DO affect the original data. A- Formal parameter B- Actual parameter C- Reference parameter D- Value parameter

D (Explanation: The value of lets.length is 4, since there are four rows in this matrix, and the value of lets[2] is 5, since there are five elements in row 2. The product of 4 and 5 is 20.)

What is output by the code shown below, where length represents the number of elements? char [ ][ ] lets ← {{'H','O','W'},{'N','O','W'},{'B','R','O','W','N'},{'C','O','W'}} print lets.length * lets[2].length A- 6 B- 12 C- 16 D- 20

A (Explanation: The value in list[2] is 3, and the value in list[list[2]], or list[3] is 8, therefore the sum of 3 and 8 is 11.)

What is output by the code shown below? int [ ] list ← {7,2,3,8,1,3} print list[2] + list[ list[2] ] A- 11 B- 5 C- 10 D- 4

C (Explanation: Since every grid element is assigned the product of its row and column index values, the element contained in row 2, column 3 is 2*3, or 6)

What is output by the code shown below? int [ ][ ] grid ← new grid[3][4] for(int r ← 0;r < grid.length;r ← r + 1) for(int c ← 0;c < grid[r].length;c ← c + 1) grid[r][c] ← r * c print grid[2][3] A- 2 B- 12 C- 6 D- 5

A (Explanation: After the first two values (7 and 3) are pushed, the front value 7 is doubled and pushed (14), and then the front two values (7 and 3) are removed and added to the remaining front value (14) for a total of 24, which is then pushed. The front value 14 is then output.)

What is output by the following code sequence? Queue q ← new Queue() q.push(7) q.push(3) q.push(q.peek() * 2) q.push(q.pop() + q.pop() + q.peek()) print q.peek() A- 14 B- 22 C- 24 D- 16

D (Explanation: After the first two values (7 and 3) are pushed, the top value 3 is doubled and pushed (6), and then the top two values (6 and 3) are removed and added to the remaining top value (7) for a total of 16, which is then pushed. The top value 16 is then output and removed.)

What is output by the following code sequence? Stack s ← new Stack() s.push(7) s.push(3) s.push(s.peek() * 2) s.push(s.pop() + s.pop() + s.peek()) print s.pop() A- 24 B- 22 C- 14 D- 16

A (Explanation: Since p is true, NOT p is false false OR true (the value of q) is true since OR only requires one operand to be true in order to evaluate to true)

What is output by the pseudocode segment shown? boolean p ← true boolean q ← true print NOT p OR q A- true B- false

B (Explanation: The variable num3 is assigned the mod value of 35 and 17, which is 1, and num4 is assigned the mod value of 17 and 35, which is 17. Since 1 is LESS THAN 17, the if expression is true, and num3 is output, which has the value 1.)

What is output by the pseudocode segment shown? int num1 ← 35, num2 ← 17 int num3 ← num1 % num2 int num4 ← num2 % num1 if(num3 < num4) print num3 else print num4 A- 18 B- 1 C- 17 D- 35 E- 0

B (Explanation: The value 10 is indeed equal to 10, therefore this expression is true.)

What is output by the pseudocode segment shown? int x ← 10 int y ← 10 print x ≤ y A- false B- true

B Explanation: Since 5 is indeed LESS THAN OR EQUAL TO 10 and 5 IS GREATER THAN OR EQUAL TO -3, this AND expression, which requires both operands to be true for a true result, is indeed true.

What is output by the pseudocode segment shown? int x ← 5 int y ← 10 int z ← -3 print x≤y AND x≥z A- false B- true

B (Explanation: Since x and y are indeed different values, x NOT EQUAL TO y is indeed true)

What is output by the pseudocode segment shown? int x ← 6 int y ← 10 print x ≠ y A- false B- true

A (Explanation: f(-10) = f(-5) + f(-2) = 0 + 1 = 1 f(-5) = f(0) + f(3) = 1 + -1 = 0 f(0) = f(5) + f(8) = -1 + 2 = 1 f(3) = -1 f(-2) = f(3) + f(6) = -1 + 2 = 1 f(5) = -1 f(8) = 2 f(6) = 2)

What is output by this pseudocode segment? int f(int x) if(x > 0 AND x % 2 == 0) return 2 else if(x > 0 AND x % 2 == 1) return -1 else return f(x + 5) + f(x + 8) end if else chain end f print f(-10) A- 1 B- 4 C- 0 D- 3 E- 2

A (Explanation: f(18) = f(14) - 2 = -8 - 2 = -10 f(14) = f(10 - 2 = -6 - 2 = -8 f(10) = f(6) - 2 = -4 - 2 = -6 f(6) = -4)

What is output by this pseudocode segment? int f(int x) if(x ≥ 10) return f(x - 4) - 2 else return -4 end if end f print f(18) A- -10 B- -4 C- -6 D- -8 E- -2

C (Explanation: sum is 0 x is 100, sum is 1, 100 / 2 is 50 x is 50, sum is 2, 50 / 2 is 25, x is 25, sum is 3, 25 / 2 is 12 x is 12, sum is 4, 12 / 2 is 6 x is 6, sum is 5, 6 / 2 is 3 x is 3, sum is 6, 3 / 2 is 1 x is 1, sum is 7, 1 / 2 is 0 loop stops)

What is output by this pseudocode segment? int sum ← 0 for(int x ← 100; x > 0 ; x ← x / 2) //assume integer division sum ← sum + 1 print sum A- 4 B- 8 C- 7 D- 5 E- 6

A (Explanation: x is 15, sum is 0 sum becomes -30, x becomes 12 sum becomes -54, x becomes 9 sum becomes -72, x becomes 6 sum becomes -84, x becomes 3 sum becomes -90, x becomes 0 loop stops)

What is output by this pseudocode segment? int x ← 15 int sum ← 0 do{ sum ← sum - x * 2 x ← x-3 }while(x > 0) print sum A- -90 B- -774 C- -186 D- -84 E- No output due to an infinite loop

D (Explanation: The sequence is: a gets 2, and is printed (2-) a is then passed twice to the doStuff method, first by reference to x, and then by value to y x and y are both printed (2:2:) x is incremented to 7, which automatically changes a in main to 7 since it was passed by reference this action has no affect on y, which was passed by value, and still contains the value 2 y is incremented to 5, which has no affect on either a or x x and y are printed (7:5:) control returns to main, where a is printed (7-))

What is the complete output of the pseudocode example shown here? void doStuff (passed_by_reference int x, passed_by_value y) print(x + ":" + y + ":") x ← x+5 y ← y+3 print(x + ":" + y + ":") void main int a ← 2 print(a + "-") doStuff(a, a) print(a + "-") A- 2-2:2:10:10:10- B- 2-2:2:7:10:2- C- 2-2:2:7:10:10- D- 2-2:2:7:5:7

D (Explanation: Since any value equal to or less than 23 will allow the loop to execute, all values GREATER than 23 will immediately cause the condition to be false, thus preventing the loop from acting at all.)

What statement best describes a value that could be input for x so that the while loop shown below will never act? int x input x while(x ≤ 23) <action> x ← x + 1 A- The value 23 B- Any value except 23 C- There is no value that will prevent this loop from executing D- Any value greater than 23 E- Any value less than 23

A (Explanation: x is 14 * is printed x is 16 * is printed x is 18 * is printed x is 20 * is printed x is 22 * is printed final value of x is 24 loop stops)

What value could be input for num in order to produce the output shown below? int x ← 0 int num input num for(x ← 14; x < num ; x ← x + 2) print "*" print x //output *****24 A- 23 B- 25 C- 27 D- 21

D (Explanation: The most difficult errors to discover and correct are logic errors, when there are no compile or runtime errors, but the program just doesn't work correctly.)

When a program executes just fine, but the outcome is incorrect, this is a ______________ error. A- Lexical B- Runtime C- Syntax D- Logic

C (Explanation: The sequence of values for the three loops are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 5, 8, 11, 14, 17, 20, 23, 26, 29, 32)

Which <start>, <check> and <step> options in the choices below will cause the action of this loop to occur 10 times? <start> do{ <action> <step> }while(<check>) A- int x ← 0 ; x < 10; x ← x + 1 B- int x ← 1 ; x ≤ 10 ; x ← x + 1 C- All of these D- Only two of these E- int x ← 5 ; x < 33; x ← x + 3

D (Explanation The binary search first considers the middle element of the list. If that middle element matches the target, only one step has occurred, representing the best case scenario of the binary search.)

Which choice below best describes the situation where the running time of a binary search is O(1)? A- When the target value being searched is not found. B- When the target value being searched is found at the end of the list. C- When the target value being searched is found at the beginning of the list. D- When the target value being searched is found in the middle of the list. correct

A (Explanation: A tree, more commonly a binary tree, has nodes called parents, and other nodes pointed to by the parent node called children.)

Which choice below is best described by the following statement? Data structure containing several nodes, each of which can point to two other nodes, often referred to as children. A- Tree B- Stack C- Queue D- Array E- Linked List F- Graph

B (Explanation: A graph is a collection of interconnected nodes, or vertices, with edges that are directed or undirected, linking them together into a system of nodes, which could represent a roadmap of system of interconnected tasks in a large project.)

Which choice below is best described by the following statement? Data structure containing several nodes, often called vertices, which are connected to other nodes using edges. A- Tree B- Graph C- Stack D- Linked List E- Queue F- Array

E (Explanation: A queue pushes items to the back of the list, and peeks or pops elements from the front of the list.)

Which choice below is best described by the following statement? Data structure that resembles a waiting line in a cafeteria, where elements join the list at the back, and are accessed or removed from the list at the front. A- Stack B- Array C- Tree D- Linked List E- Queue F- Graph

D (Explanation: A stack uses the push, pop, and peek commands to insert, delete, and access elements from only the top of the stack.)

Which choice below is best described by the following statement? Data structure where insertion or deletion of elements is restricted to only one end of the list. A- Array B- Tree C- Queue D- Stack E- Graph F- Linked List

D (Explanation: An array is contained in contiguous memory, which is static and unable to grow or shrink in size once created.)

Which choice below is best described by the following statement? Linear data structure that is contained in fixed, non-adjustable memory, where all items can be easily assigned and accessed using an indexing process. A- Graph B- Stack C- Tree D- Array E- Queue F- Linked List

B (Explanation: All elements contained in an array must be of the same data type.)

Which choice is NOT true about one dimensional arrays? A- Once an array has been created, it is static, and cannot grow or shrink in size. B- An array can contain elements of different data types at the same time. C- Values are accessed using an indexing process. D- Values are stored in contiguous memory.

A (Explanation: In most modern languages, two-dimensional arrays are accessed in "row major" order, with the row indicated first, and then the column.)

Which choice is NOT true about two dimensional arrays? A- Values are accessed using an indexing process, where the first index represents the column, and the second represents the row. B- The number of columns in each row can be different. C- Values are stored in contiguous memory. D- All elements contained in the array must be of the same data type.

A (Explanation: Since the Boolean order of priority is NOT, AND, XOR, then OR, to make this compound expression false, the two combinations on either side of the OR are evalatued first, and must both be false, which is: boolean p ← false, boolean q ← false The other three combinations make this expression true. boolean p ← true, boolean q ← true makes the AND expression true boolean p ← true, boolean q ← false makes the XOR expression true as does boolean p ← false, boolean q ← true)

Which combination below will make this expression FALSE? p AND q OR p XOR q A- boolean p ← false, boolean q ← false B- More than one of these C- boolean p ← true, boolean q ← true D- boolean p ← false, boolean q ← true E- boolean p ← true, boolean q ← false

E (Explanation: The if else statement is the key control structure for recursive methods.)

Which control structure listed below is the primary one used in a recursive method? A- Switch statement B- Loop C- All of these D- Sequential processing E- if else statement

A (Explanation: Since the do while is a posttest loop, the action of the loop takes place BEFORE the while condition is checked, and therefore will always act at least once. The for and while check the condition BEFORE the action takes place. If the condition is false from the start, no action will take place in these two loop structures.)

Which loop style will ALWAYS act at least once? A- do while B- for C- All will act at least once D- while

E (Explanation: Although the word "break" is indeed a command to stop a loop before its normal process of completion, it is not often used, and therefore is not considered one of the four standard parts of a loop.)

Which of the choices below is NOT one of the four standard parts of a loop? A- start B- check C- step D- action E- break

D (Explanation: All of these choices can be actions of a loop.)

Which of the choices shown could be the action part of a loop? A- Calculation B- Another loop C- Input D- All of these E- Output

B (Explanation The only requirement for a binary search is that the list being searched is in ascending sorted order.)

Which of the following NOT a true statement about the binary search process? A- The precondition is that the list must be sorted. B- The target value must be contained within the list. C- The process checks the middle item for a match, and then looks to the right or to the left if it doesn't match, repeating this process until a match is found, or not. D- The average case scenario Big O running time is O(log N).

D (Explanation A selection sort selects the next "best" value and swaps it into its correct position with each pass. An insertion sort shifts values that are out of place into the correct order. A bubble sort compares adjacent values and performs swaps. A quicksort partitions a list around pivot points.)

Which of the following describes a selection sort? A- The list is partitioned around a pivot point. B- Unsorted values are shifted into their "best position" in the list. C- Adjacent values are compared and swapped if out of order. D- The "best value for each position" is found and swapped into place with each pass.

A (Explanation The nature of an O(1) process is that, regardless of the size of the data set, it takes one step to achieve the task.)

Which of the following descriptions of the Big O analysis categories is NOT correct? A- An O(1) process only works on a data set of 100 items or less. B- An O(N) process is characterized by a loop that spans the entire data set of size N. C- An O(N2) process is characterized by a nested loop process based on the size of the data set. D- An O(N log N) process is characterized by a divide and conquer process combined with an N based loop.

D (Explanation: Deleting the entire program would be a terribly inefficient way to debug a program, especially if you have already spent significant time and effort, althought sometimes, if your program is hopelessly mangled, it may be the only option.)

Which of the following is NOT a good program debugging strategy? A- Look at the arrows in the error messages to locate the error B- Intentionally use bad data to see if your program can handle it C- Read the error messages provided by the compiler D- Delete the entire program and start all over again.

A (Explanation Due to the "divide and conquer" nature of the merge sort, it is considered an O(N log N) class sort for all cases, average, worst, and best. The quick sort is also considered O(N log N) for best and average cases, but not in the worst case scenario, when its running time is considered to be O(N2).)

Which of the following is considered an O(N log N) class sort for a worst case scenario? A- Merge Sort B- Selection Sort C- Insertion Sort D- Quick Sort

D (Explanation: Indeed, all of the statements are true regarding the use of loops and recursion.)

Which of the statements listed below is NOT true regarding the use of loops and recursion? A- There are some things a recursive process can do that a loop cannot. B- Both loops and recursion are processes used to repeat tasks in a program C- Loops are more memory efficient than recursive processes. D- All of these statements are true. E- When possible, use a loop, and only use recursion when a loop is not possible, or is less effective.

A (Explanation: The recursive call causes another method call to stack up, causing the repetitive nature of this method style.)

Which of the terms listed represents the part of the recursive method that causes repetition? A- Recursive call B- Loop C- Base case D- if else statement

B (Explanation: The base case is the part of the recursive process that causes the stacking process to stop.)

Which of the terms listed represents the part of the recursive method that stops the repetitive process? A- Loop B- Base case C- Recursive call D- if else statement

A (Explanation: Iteration is a term that means repeating a process. One way to do that is through the use of a loop structure, such as the while, do while, or for loop.)

Which of these terms refers to the process of using a loop in a program? A- iteration B- sequence C- recursion D- All of these E- branching

D (Explanation Although finding the target at the end of the list could be considered a worst case scenario, NOT finding it is actually one step worse than that.)

Which of these would be considered the worst case scenario for a linear search? A- The target value is found at the beginning of the list. B- The target value is found at the end of the list. C- The target value is found somewhere in the middle of the list. D- The target value is not found in the list.

A (Explanation: Since the value 14 is LESS THAN 35, and num1 will output when the expression is true, three operators will make this happen: <, ≤, and ≠.)

Which symbol below will correctly fill the blank to output the value 14? int num1 ← 14 int num2 ← 35 if(num1 ____ num2) println num1 else println num2 I. < II. > III. ≤ IV. ≥ V. == VI. ≠ A- I, III, VI B- III, IV, V C- II, IV, VI D- I, II, III, IV, VI E-I, III, V


Kaugnay na mga set ng pag-aaral

Advanced Patho/Pharm: Immune Diagnostic Tests Saunder's ?'s

View Set

Quiz: Chapter 19, Nursing Care of the Family During Labor and Birth

View Set

Part Seven: Professional Practice

View Set

Chapter 31: The Child with Musculoskeletal or Articular Dysfunction

View Set