“Introduction to Computer Science II” typically serves as a continuation of the foundational concepts introduced in “Introduction to Computer Science I.” In this course, students delve deeper into programming, algorithms, data structures, and various advanced topics in computer science. Here’s a breakdown of what students might expect to learn:
- Object-Oriented Programming (OOP):
- Building upon the basics of OOP introduced in the first course, students may delve deeper into concepts like inheritance, polymorphism, encapsulation, and abstraction.
- Design patterns and best practices for OOP may also be covered.
- Data Structures:
- Advanced data structures such as trees (binary trees, AVL trees, B-trees), graphs, heaps, hash tables, and more.
- Analysis of data structure operations (time complexity, space complexity).
- Algorithms:
- Advanced sorting and searching algorithms (quick sort, merge sort, binary search, etc.).
- Graph algorithms (BFS, DFS, Dijkstra’s algorithm, etc.).
- Dynamic programming, greedy algorithms, and divide-and-conquer strategies.
- Software Engineering Principles:
- Topics may include software development methodologies (Agile, Waterfall, etc.).
- Version control systems (Git, SVN) and collaborative development.
- Testing methodologies (unit testing, integration testing, etc.).
- Concurrency and Parallelism:
- Introduction to concurrent programming concepts and techniques.
- Multi-threading, synchronization, and thread safety.
- Parallel programming paradigms and frameworks.
- Advanced Topics:
- Depending on the curriculum, students may be introduced to advanced topics such as machine learning, artificial intelligence, natural language processing, computer vision, etc.
- Other potential areas of study could include cryptography, network programming, database systems, etc.
- Practical Projects:
- Students are likely to work on practical projects that integrate the concepts learned throughout the course.
- These projects may involve designing and implementing complex algorithms, building software applications, or solving real-world problems using computer science principles.
Overall, “Introduction to Computer Science II” aims to equip students with a deeper understanding of fundamental computer science concepts and the ability to apply them to solve more complex problems. It serves as a bridge to more specialized courses and prepares students for further study or careers in computer science-related fields.
CS102: Introduction to Computer Science II Exam Quiz Answers
Question 1: How do object-oriented languages go beyond earlier programming languages?
- They have vastly superior compilers that create machine code that saves time and memory
- They provide libraries of functions, like C++’s Standard Template Library or Java’s Container Library
- They offer documentation tools that explain algorithms in more human-oriented, understandable ways
- They focus on problem spaces and do not constrain programmers to specific problem-solving approaches
Question 2: An object is an instance of a class. There can be multiple instances of the same class. Which of the following best summarizes the characteristics of an object?
- They have states, behavior, unique identities, and can communicate with other entities
- They have states, behavior, unique identities, and can communicate with other entities
- They are well-commented blocks of code that can be easily replaced and modified as the need arises
- They provide reusable code for common functionality and can be called from other program components
Question 3: What are the three basic logic structures that are common to all programming approaches?
- Classes, objects, iterators
- Subroutines, functions, methods
- Sequence of instructions, choose which instructions, repeat a block of instructions
- Problem statement, abstraction of the problem, implementation of the problem solution
Question 4: What terminology is used in object-orientation that is not found in functional or modular approaches?
- Messaging, remote-call, independent, thread, reuse, mutex
- Call, procedure, process, do-while, if-then-else, loop, function
- Class, method, attribute, polymorphism, inheritance, instance
- Lock, unlock, delete, garbage cleanup, orphaned memory, pointer
Question 5: What is the general thought process behind object-orientated programming?
- Solutions are defined in terms of classes; classes instantiate as objects; objects are formed into hierarchies by generalizing or specializing; objects can communicate with other objects
- Trusted reusable software functions and subroutines are formed into libraries that enable programmers to focus on the increasing complexity of modern-day problems and their solutions
- Independent software modules exist within a computer network; they do not necessarily share memory; the modules can communicate within various design architectures to enable problem solutions
- Software projects require using known, good software modules that are a natural part of a computer programming languages that focus on solving problems rather than the programming process
Question 6: Which of the following should be done when you are considering functionality such as maps, lists, and queues?
- Create reusable libraries to save project time in the future
- Write documentation to make clear which datasets can be employed
- Design and implement them to be agnostic of data type to give programmers greater flexibility
- Perform testing to determine if the functionality is superior to code written on a project-by-project basis
Question 7: What is the fundamental tradeoff discussed in generic programming?
- Whether to use non-local hosting versus using local hosting
- What things need to be accomplished versus how to accomplish things
- Creating multi-language systems versus creating same-language systems
- Implementation in non-shared memory versus implementation in shared memory
Question 8: How does the concept of generic programming involve abstraction?
- It enables libraries, which minimizes the amount of new programming needed to solve any given problem
- It constructs catalogs of useful and efficient algorithms and data structures that are agnostic of data type
- It produces essential data-flow architectures that act as problem-solving tools for modern, networked problems
- It does not matter where a function is physically located, since any function can be called as if it were hosted within the program itself
Question 9: Classes instantiated as objects are central to object-oriented programming. Which of the following C++ code snippets puts a native object into a list and uses an explicit iterator to visit each element in the list?
- #include <iostream>
#include <list>
#include <iterator>
using namespace std;
int main()
{
list <string> stringList;
list <string> ::iterator it;
stringList.push_back(“Dog”);
stringList.push_back(“Cat”);
stringList.push_back(“Horse”);
stringList.push_back(“Chicken”);
int length = stringList.size();
for (int i = 0; i < length; i++)
{
cout << stringList.front() << endl;
stringList.pop_front();
}
return 0;
}
- #include <iostream>
#include <list>
#include <iterator>
using namespace std;
int main()
{
list <string> stringList;
list <string> ::iterator it;
stringList.push_back(“Dog”);
stringList.push_back(“Cat”);
stringList.push_back(“Horse”);
stringList.push_back(“Chicken”);
while(stringList.size() > 0)
{
cout << stringList.front() << endl;
stringList.pop_front();
}
return 0;
}
- #include <iostream>
#include <list>
#include <iterator>
using namespace std;
int main()
{
list <string> stringList;
list <string> ::iterator it;
stringList.push_back(“Dog”);
stringList.push_back(“Cat”);
stringList.push_back(“Horse”);
stringList.push_back(“Chicken”);
for (it = stringList.begin(); it != stringList.end(); ++it)
std::cout << *it << endl;
return 0;
}
- #include <iostream>
#include <list>
#include <iterator>
using namespace std;
int main()
{
list <string> stringList;
list <string> ::iterator it;
stringList.push_back(“Dog”);
stringList.push_back(“Cat”);
stringList.push_back(“Horse”);
stringList.push_back(“Chicken”);
int length = stringList.size();
for (int i = length; i >= 1; i–)
{
cout << stringList.front() << endl;
stringList.pop_front();
}
return 0;
}
Question 10: A customer has an industrial process that generates anomalous events. It is desired to count the number of times each event occurs so that priorities on resolution can be decided. Which of the following Java and C++ code snippets prototype this capability without writing an explicit search function?
- package com.company;
public class Main
{
public static void main(String[] args)
{
Map<String, Integer> eventMap =
new HashMap<String, Integer>();
String thisEvent;
Integer count;
boolean keyPresent;
for (int i = 0; i < 100; i++)
for (Integer e = 0; e <= 127; e++)
{
thisEvent = Integer.toString(e.intValue());
keyPresent =
eventMap.containsKey(thisEvent);
if( ! keyPresent ) eventMap.put(thisEvent, 0);
else
{
count = eventMap.get(thisEvent);
eventMap.put(thisEvent, count + 1);
}
}
thisEvent = “2”;
count = eventMap.get(thisEvent);
System.out.println(“Example: ” + thisEvent +
” ” + Integer.toString(count.intValue()));
}
} #include <iostream>
#include <map>
#include <string>
int main()
{
map<string, unsigned int> eventMap;
map<string, unsigned int>::iterator
eventMapPointer;
string thisEvent;
for (int i = 0; i < 100; i++)
for (unsigned int e = 0; e <= 127; e++)
{
thisEvent = (char)e;
eventMapPointer = eventMap.find(thisEvent);
if (eventMapPointer == eventMap.end())
eventMap[thisEvent] = 0;
else (*eventMapPointer).second++;
}
eventMapPointer = eventMap.find(“2”);
cout << “Example: ” << (*eventMapPointer).first <<
‘ ‘ << (*eventMapPointer).second << endl;
return 0;
}
- package com.company;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Map<String, Integer> eventMap =
new HashMap<String, Integer>();
String thisEvent;
Integer count;
boolean keyPresent;
for (int i = 0; i < 100; i++)
for (Integer e = 0; e <= 127; e++)
{
thisEvent = Integer.toString(e.intValue());
keyPresent =
eventMap.containsKey(thisEvent);
if( ! keyPresent ) eventMap.put(thisEvent, 0);
else
{
count = eventMap.get(thisEvent);
eventMap.put(thisEvent, count + 1);
}
thisEvent = “2”;
count = eventMap.get(thisEvent);
System.out.println(“Example: ” + thisEvent +
” ” + Integer.toString(count.intValue()));
}
}
} #include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string, unsigned int> eventMap;
map<string, unsigned int>::iterator
eventMapPointer;
string thisEvent;
for (int i = 0; i < 100; i++)
for (unsigned int e = 0; e <= 127; e++)
{
thisEvent = (char)e;
eventMapPointer = eventMap.find(thisEvent);
if (eventMapPointer == eventMap.end())
eventMap[thisEvent] = 0;
else (*eventMapPointer).second++;
eventMapPointer = eventMap.find(“2”);
cout << “Example: ” << (*eventMapPointer).first <<
‘ ‘ << (*eventMapPointer).second << endl;
}
return 0;
}
- package com.company;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Map<String, Integer> eventMap =
new HashMap<String, Integer>();
String thisEvent;
Integer count;
boolean keyPresent;
for (int i = 0; i < 100; i++)
for (Integer e = 0; e <= 127; e++)
{
thisEvent = Integer.toString(e.intValue());
keyPresent =
eventMap.containsKey(thisEvent);
if( ! keyPresent ) eventMap.put(thisEvent, 0);
else
{
count = eventMap.get(thisEvent);
eventMap.put(thisEvent, count + 1);
}
}
thisEvent = “2”;
count = eventMap.get(thisEvent);
System.out.println(“Example: ” + thisEvent +
” ” + Integer.toString(count.intValue()));
}
} #include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string, unsigned int> eventMap;
map<string, unsigned int>::iterator
eventMapPointer;
string thisEvent;
for (int i = 0; i < 100; i++)
for (unsigned int e = 0; e <= 127; e++)
{
thisEvent = (char)e;
eventMapPointer = eventMap.find(thisEvent);
if (eventMapPointer == eventMap.end())
eventMap[thisEvent] = 0;
else (*eventMapPointer).second++;
}
eventMapPointer = eventMap.find(“2”);
cout << “Example: ” << (*eventMapPointer).first <<
‘ ‘ << (*eventMapPointer).second << endl;
return 0;
}
- package com.company;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Map<String, Integer> eventMap =
new HashMap<String, Integer>();
String thisEvent;
Integer count;
for (int i = 0; i < 100; i++)
for (Integer e = 0; e <= 127; e++)
{
thisEvent = Integer.toString(e.intValue());
count =
eventMap.get(thisEvent);
if(count != null) eventMap.put(thisEvent, 0);
else
{
eventMap.put(thisEvent, count + 1);
}
thisEvent = “2”;
count = eventMap.get(thisEvent);
System.out.println(“Example: ” + thisEvent +
” ” + Integer.toString(count.intValue()));
}
}
} #include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string, unsigned int> eventMap;
map<string, unsigned int>::iterator
eventMapPointer;
string thisEvent;
for (int i = 0; i < 100; i++)
for (unsigned int e = 0; e <= 127; e++)
{
thisEvent = (char)e;
eventMapPointer = eventMap.find(thisEvent);
if (eventMapPointer != eventMap.end())
eventMap[thisEvent] = 0;
else (*eventMapPointer).second++;
eventMapPointer = eventMap.find(“2”);
cout << “Example: ” << (*eventMapPointer).first <<
‘ ‘ << (*eventMapPointer).second << endl;
}
return 0;
}
Question 11: Modern computers that are used in industrial and business applications typically have CPUs with multiple cores. These cores access a shared memory and can execute code simultaneously. Threads are used to take advantage of this capability. Which of the following demonstrates a simple example of thread creation and execution in Java and C++, using only standard language components without using third-party libraries?
- package com.company;
public class Main
{
final static class MyThread extends Thread
{
public void run()
{
System.out.println(“MyThread running”);
}
}
public static void main(String[] args)
throws InterruptedException
{
MyThread myThread = new MyThread();
myThread.run();
myThread.join();
System.out.println(“myThread Completed”);
}
} #include <iostream>
#include <thread>
using namespace std;
void MyThread()
{
cout << “MyThread running” << endl;
}
int main()
{
thread myThread (MyThread);
myThread.run();
myThread.join();
cout << “myThread Completed\n”;
return 0;
}
- package com.company;
public class Main
{
final static class MyThread extends Thread
{
public void run()
{
System.out.println(“MyThread running”);
}
}
public static void main(String[] args)
throws InterruptedException
{
MyThread myThread = new MyThread();
myThread.start();
myThread.join();
System.out.println(“myThread Completed”);
}
} #include <iostream>
#include <thread>
using namespace std;
void MyThread()
{
cout << “MyThread running” << endl;
}
int main()
{
thread myThread (MyThread);
myThread.join();
cout << “myThread Completed\n”;
return 0;
}
- package com.company;
public class Main
{
final static class MyThread extends Thread
{
public void run()
{
System.out.println(“MyThread running”);
}
}
public static void main(String[] args)
throws InterruptedException
{
MyThread myThread = new MyThread();
myThread.join();
System.out.println(“myThread Completed”);
}
} #include <iostream>
#include <thread>
using namespace std;
void MyThread()
{
cout << “MyThread running” << endl;
}
int main()
{
thread myThread (MyThread);
myThread.start();
myThread.join();
cout << “myThread Completed\n”;
return 0;
}
- package com.company;
public class Main
{
final static class MyThread extends Thread
{
public void run()
{
System.out.println(“MyThread running”);
}
}
public static void main(String[] args)
throws InterruptedException
{
MyThread myThread = new MyThread();
myThread.start();
myThread.join();
System.out.println(“myThread Completed”);
}
} #include <iostream>
#include <thread>
using namespace std;
void MyThread()
{
cout << “MyThread running” << endl;
}
int main()
{
MyThread();
cout << “myThread Completed\n”;
return 0;
}
Question 12: What is a major difference in the way C++ passes data to functions and methods compared to Java?
- C++ is completely unable to interact with processes not written in C++, while Java has the ability to interact with processes written in other languages
- In C++, pointers, references, and pass-by-value are supported only for primitive data types, while in Java primitive data types are always passed by value
- In C++, pointers, references, and pass-by-value are supported for all primitive and user-defined data types, while in Java all data types are always passed by value
- In C++, there is no way at all to access data not resident in the program’s shared memory, while in Java functionality can be created to access data not residing in the program’s shared memory
Question 13: What is an important difference between Java and C++ when it comes to numeric variable types?
- Java does not enable integer variables, only floating-point; C++ enables both integer and floating point
- Java does not have native floating-point variables; C++ has several different floating point variable types
- Java does not support native unsigned arithmetic data types; C++ has native unsigned arithmetic support
- Java supports certain native variable types which have class-based equivalents; C++ is only beginning to implement such capability in beta releases
Question 14: What important feature do C++ templates and Java containers share?
- They are both data-type agnostic
- They are both are written in assembler
- They are both assembled from public libraries
- They are both directly interchangeable from one language to another
Question 15: What important problem-solving capability does generic programming allow us to use?
- The ability to create directly-executable machine code for any computer platform
- The freedom from having to consider the details of a given language, especially data-types
- Robust documentation tools that can be used to make any code completely understandable
- The ability to easily merge components from any language seamlessly into a single application
Question 16: What language feature does C++ employ as a foundation for its Standard Template Library?
- Well-documented type-specific subroutines and functions, which enables efficient runtime
- Remote-calling capability that allows for taking advantage of any collection’s or library’s capability
- Expansion of the C language to include object-orientation as a native programming language feature
- Expansion of the C language to include object-orientation as a native programming language feature
Question 17: How are the C++ Standard Template Library and the Java Container Library similar?
- They both collect language-specific public libraries in a common catalog that provides documentation
- They both result in directly-executable machine code that can be accessed by other language modules
- Both use the same syntax, which means they are interpretable by either language’s compilation process
- Both provide language-standard libraries of data structures and functionality that are data-type agnostic
Question 18: You have been tasked with creating a key/record retrieval capability. You want to avoid implementing a formal database and concentrate on data-use capability. Which of the following code prototypes adds entries to this database using C++’ Standard Template Library, and does not require sequential searching?
- #include <iostream>
using namespace std;
typedef struct {string elements [10];} Record, *pRecord;
struct key_value {string first; pRecord second = NULL; key_value *next = NULL; };
pRecord thisRecord = NULL;
key_value *Database = NULL;
key_value* lastEntry = NULL;
void Add_Entry(string key, pRecord thisRecord)
{
if (Database != NULL)
{
lastEntry->next = new key_value;
lastEntry = lastEntry->next;;
}
else
{
Database = new key_value;
lastEntry = Database;
}
lastEntry->first = key;
lastEntry->second = thisRecord;
}
int main()
{
thisRecord = new Record;
thisRecord->elements[0] = “Step 1”;
Add_Entry(“Study”, thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Step 2”;
Add_Entry(“Learn”, thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Step 3”;
Add_Entry(“Work”, thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Step 4”;
Add_Entry(“Produce”, thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Cycle Through Steps”;
Add_Entry(“Repeat”, thisRecord);
key_value* thisEntry = Database;
while (thisEntry != NULL)
{
cout << thisEntry->first << ” : ” << thisEntry->second->elements[0] << endl;
thisEntry = thisEntry->next;
}
}
- #include <iostream>
#include <unordered_map>
using namespace std;
typedef struct { string elements[10]; } Record, *pRecord;
pRecord thisRecord = NULL;
unordered_map<string, pRecord> Database;
int main()
{
thisRecord = new Record;
thisRecord->elements[0] = “Step 1”;
Database[“Study”] = thisRecord;
thisRecord = new Record;
thisRecord->elements[0] = “Step 2”;
Database[“Learn”] = thisRecord;
thisRecord = new Record;
thisRecord->elements[0] = “Step 3”;
Database[“Work”] = thisRecord;
thisRecord = new Record;
thisRecord->elements[0] = “Step 4”;
Database[“Produce”] = thisRecord;
thisRecord = new Record;
thisRecord->elements[0] = “Cycle Through Steps”;
Database[“Repeat”] = thisRecord;
for (auto key_value : Database)
cout << key_value.first << ” : ” << key_value.second->elements[0] << endl;
}
- #include
#include
using namespace std;
typedef struct { string key; string elements[10]; } Record, * pRecord;
pRecord thisRecord;
list Database;
int main()
{
thisRecord = new Record;
thisRecord->elements[0] = “Step 1”;
thisRecord->key = “Study”;
Database.push_back(thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Step 2”;
thisRecord->key = “Learn”;
Database.push_back(thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Step 3”;
thisRecord->key = “Work”;
Database.push_back(thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Step 4”;
thisRecord->key = “Produce”;
Database.push_back(thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Cycle Through Steps”;
thisRecord->key = “Repeat”;
Database.push_back(thisRecord);
for (auto key_value : Database)
cout << key_value->key << ” : ” << key_value->elements[0] << endl;
}
- #include <iostream>
#include <set>
using namespace std;
typedef struct { string key; string elements[10]; } Record, * pRecord;
pRecord thisRecord;
set<pRecord> Database;
int main()
{
thisRecord = new Record;
thisRecord->elements[0] = “Step 1”;
thisRecord->key = “Study”;
Database.insert(thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Step 2”;
thisRecord->key = “Learn”;
Database.insert(thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Step 3”;
thisRecord->key = “Work”;
Database.insert(thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Step 4”;
thisRecord->key = “Produce”;
Database.insert(thisRecord);
thisRecord = new Record;
thisRecord->elements[0] = “Cycle Through Steps”;
thisRecord->key = “Repeat”;
Database.insert(thisRecord);
for (auto key_value : Database)
cout << key_value->key << ” : ” << key_value->elements[0] << endl;
}
Question 19: What are the two major categories in the C++ Standard Template Library?
- Data structures that are linear and associative
- Local and remote hosting of program modules
- Shared and non-shared memory for storing data structures
- Compiled/linked and interpreted code for runtime implementation
Question 20: Which of the following best outlines how data collections are used in C++ and Java?
- In both Java and C++, collections can only be written to store class objects
- In both Java and C++, collections are not generic since they can only hold primitive types
- In Java, any collection can be written to store any class, while collections in C++ can only deal with primitive types
- In Java, any collection can be written to store any class, while C++ collections hold primitive types in addition to classes
Question 21: What are the three generic types of data collections?
- Stacks, queues, and arrays
- Ordered lists, arrays, and vectors
- Trees, dictionaries/maps, and vectors
- Ordered lists, dictionaries/maps, and sets
Question 22: What is the main reason for employing exception handling?
- To trigger threads when specific program conditions are met
- To prevent sudden program termination due to abnormal conditions
- To provide an expanded if/then/else capability that is more expressive
- To instantiate loops with unusual conditions for ending a cycle of code execution
Question 23: Which of the following lists three reasons to use exception handling?
- Increases operating system portability, increases hardware portability, and increases language portability
- Expands the conditions for terminating loops, improves thread control, and provides access other-language components
- Creates a system of hardware interrupts, expands conditionals, and acts as an alternative to if/then/else logic structures
- Improves error recovery, eases the creation of robust program components, and minimizes the chance of unrecoverable errors
Question 24: There are many reasons why specific exceptions should be handled according to their type. However, during concept development, you may want to explicitly catch whatever exceptions are generated, report them, and provide code-location information. How might you do this in Java and C++?
- package com.company;
public class Main
{
public static void main
(String[] args)
{
try { int i = 5 / 0; }
catch (Exception e)
{
System.out.println
(e.toString());
e.printStackTrace();
System.out.println
(“Program Abended”);
System.exit(-1);
}
System.out.println
(“Program Ended Normally”);
}
} #include <iostream>
#include <typeinfo>
#include <exception>
using namespace std;
class Polymorphic
{ virtual void Member() {} };
int main()
{
try
{
Polymorphic* pb = 0;
cout << typeid(*pb).name();
}
catch (exception &e)
{
cout <<
“An exception occurred: ” <<
endl << e.what() << ‘\n’;
cout <<
“*** Location: Module Main: ” <<
Catch Statement: 001″ << endl;
cout << “Program Abended” << endl;
return -1;
}
cout << “Program Ended Normally” <<
endl;
return 0;
}
- package com.company;
public class Main
{
public static void main
(String[] args) throws Exception
{
int i = 5 / 0;
System.out.println
(“Program Ended Normally”);
}
} #include <iostream>
#include <typeinfo>
#include <exception>
using namespace std;
class Polymorphic
{ virtual void Member() {} };
int main()
{
Polymorphic* pb = 0;
cout << typeid(*pb).name();
cout << “Program Ended Normally” <<
endl;
return 0;
}
- package com.company;
public class Main
{
public static void main
(String[] args)
{
try { int i = 5 / 0; }
catch (Exception e) { }
System.out.println
(“Program Ended Normally”);
}
} #include <iostream>
#include <typeinfo>
#include <exception>
using namespace std;
class Polymorphic
{ virtual void Member() {} };
int main()
{
try
{
Polymorphic* pb = 0;
cout << typeid(*pb).name();
}
catch (…) { }
cout << “Program Ended Normally” <<
endl;
return 0;
}
- package com.company;
public class Main
{
public static void main
(String[] args)
{
try { int i = 5 / 0; }
catch (Exception e)
{
System.out.println
(“Caught an Exception);
}
System.out.println
(“Program Ended Normally”);
}
} #include <iostream>
#include <typeinfo>
#include <exception>
using namespace std;
class Polymorphic
{ virtual void Member() {} };
int main()
{
try
{
Polymorphic* pb = 0;
cout << typeid(*pb).name();
}
catch (exception &e)
{
cout <<
“An exception occurred.” <<
endl;
}
cout << “Program Ended Normally” <<
endl;
return 0;
}
Question 25: The standard exceptions generated by Java sometimes require more processing than would be appropriate for a simple catch statement. Which of the following is a rudimentary way of blending this kind of processing with a try/catch paradigm?
- package com.company;
class Exception_NullInteger
{
public String feedback;
public Integer newValue;
Exception_NullInteger(String feedback, Integer I)
{
// some processing on constructor input values
I = 0; // result of that processing
this.newValue = I;
this.feedback = feedback;
}
}
public class Main
{
public static void main(String[] args)
{
Integer I = null;
Exception_NullInteger myException = null;
try { System.out.println(I.toString()); }
catch (Exception_NullInteger e)
{
System.out.println(e.toString());
System.out.println(e.feedback);
I = e.newValue;
System.out.println(“Value confirmed to be ” + I.toString());
System.out.println(“StackTrace: “);
StackTraceElement[] thisStackTrace = e.getStackTrace();
for (int L = 0; L < thisStackTrace.length; L++)
System.out.println(“\t” + thisStackTrace[L].toString());
}
finally { System.out.println(“Main Continues”); }
}
}
- package com.company;
class Exception_NullInteger extends Exception
{
public String feedback;
public Integer newValue;
Exception_NullInteger(String feedback, Integer I)
{
// some processing on constructor input values
I = 0; // result of that processing
this.newValue = I;
this.feedback = feedback;
}
}
public class Main
{
public static void main(String[] args)
{
Integer I = null;
Exception_NullInteger myException = null;
try { System.out.println(I.toString()); }
catch (NullPointerException e)
{
System.out.println(e.toString());
System.out.println(“StackTrace: “);
StackTraceElement[] thisStackTrace = e.getStackTrace();
for (int L = 0; L < thisStackTrace.length; L++)
System.out.println(“\t” + thisStackTrace[L].toString());
}
finally { System.out.println(“Main Continues”); }
}
}
- package com.company;
class Exception_NullInteger extends Exception
{
public String feedback;
public Integer newValue;
Exception_NullInteger(String feedback, Integer I)
{
// some processing on constructor input values
I = 0; // result of that processing
this.newValue = I;
this.feedback = feedback;
}
}
public class Main
{
public static void main(String[] args)
{
Integer I = null;
Exception_NullInteger myException = null;
try
{
if (I == null)
throw new Exception_NullInteger(“Exception: Integer is null.”, I);
}
catch (Exception_NullInteger e)
{
System.out.println(e.toString());
System.out.println(e.feedback);
I = e.newValue;
System.out.println(“Value confirmed to be ” + I.toString());
System.out.println(“StackTrace: “);
StackTraceElement[] thisStackTrace = e.getStackTrace();
for (int L = 0; L < thisStackTrace.length; L++)
System.out.println(“\t” + thisStackTrace[L].toString());
}
finally { System.out.println(“Main Continues”); }
}
}
- package com.company;
class Exception_NullInteger extends Exception
{
public String feedback;
public Integer newValue;
Exception_NullInteger(String feedback, Integer I)
{
// some processing on constructor input values
I = 0; // result of that processing
this.newValue = I;
this.feedback = feedback;
}
}
public class Main
{
public static void main(String[] args)
{
Integer I = null;
Exception_NullInteger myException = null;
if (I == null)
{
I = 0;
System.out.println(“Value confirmed to be ” + I.toString());
}
System.out.println(“Main Continues”);
}
}
Question 26: You are writing code for a project in C++, and the program keeps crashing. The IDE’s debugger consistently shows that the crash occurs in various places but always during memory allocation. Which of the following code snippets uses exceptions to resolve this situation?
- #include <iostream>
using namespace std;
int main()
{
while (true)
{
try
{
char* c = new char[9999999];
}
catch (bad_alloc &e)
{
cout << “*** Out of memory at Point A.” << endl;
cout << e.what() << endl;
cout << “Program Abended.” << endl;
return -1;
}
}
cout << “Program Ended Normally.” << endl;
return 0;
}
- #include <iostream>
using namespace std;
int main()
{
while (true)
{
char* c = new char[9999999];
if (c == NULL) cout << “Out of memory” << endl;
}
return 0;
}
- #include <iostream>
using namespace std;
int main()
{
char* c = NULL;
while (true)
{
try
{
c = new char[9999999];
}
catch (bad_alloc &e)
{
cout << e.what() << ” Point A.” << endl;
c = new char[9999999];
}
}
cout << “Program Ended Normally.” << endl;
return 0;
}
- using namespace std;
int main()
{
while (true)
{
try
{
char* c = new char[9999999];
}
catch (bad_alloc &e)
{
c = NULL;
}
}
cout << “Program Ended Normally.” << endl;
return 0;
}
Question 27: You are writing a C++ program in a distributed-processing/same-memory situation, and the program keeps crashing. The IDE indicates that the crash is happening when new threads are spawned. Which of the following code snippets uses exceptions to catch issues like this, and to indicate what might be happening?
- #include <iostream>
#include <thread>
#include <list>
using namespace std;
#define length 9999
void anotherThread(int n)
{
char thisCharSeq[length];
while (true) { int i = n; }
}
int main()
{
list<thread> theseThreads;
int n = 0;
while (true)
{
theseThreads.push_back(thread(anotherThread, ++n));
}
std::cout << “Program Ended Normally.\n”;
return 0;
}
- #include <iostream>
#include <thread>
#include <list>
using namespace std;
#define length 9999
void anotherThread(int n)
{
char thisCharSeq[length];
while (true) { int i = n; }
}
int main()
{
list<thread> theseThreads;
int n = 0;
while (true)
{
try
{
theseThreads.push_back(thread(anotherThread, ++n));
}
catch (exception& e)
{
cout << “Exception: Point A.” << endl;
cout << “Thread Count: ” << n << endl;
cout << e.what() << endl;
cout << “Program Abended.” << endl;
return -1;
}
}
std::cout << “Program Ended Normally.\n”;
return 0;
}
- #include <iostream>
#include <thread>
#include <list>
using namespace std;
#define length 9999
void anotherThread(int n)
{
char thisCharSeq[length];
while (true) { int i = n; }
}
int main()
{
list<thread> theseThreads;
int n = 0;
while (true)
{
try
{
theseThreads.push_back(thread(anotherThread, ++n));
}
catch (…) {}
}
std::cout << “Program Ended Normally.\n”;
return 0;
}
- #include <iostream>
#include <thread>
#include <list>
using namespace std;
#define length 9999
void anotherThread(int n)
{
char thisCharSeq[length];
while (true) { int i = n; }
}
int main()
{
list<thread> theseThreads;
int n = 0;
while (true)
{
try
{
theseThreads.push_back(thread(anotherThread, ++n));
}
catch (stack_overflow& e)
{
cout << “Exception: Point A.” << endl;
cout << “Thread Count: ” << n << endl;
cout << e.what() << endl;
cout << “Program Abended.” << endl;
return -1;
}
}
std::cout << “Program Ended Normally.\n”;
return 0;
}
Question 28: At their most fundamental level, what are recursive algorithms, and how do they relate to solution design?
- They use the results of multiple independent processes to build and populate data structures. Analyzing them enables objective conclusions to be reached about complex problems. They are serendipitous and only possible in large networked systems.
- They reduce a complex problem into simpler problems, and combine those problems to form the solution to a complex problem. They are composed of a base case (where a direct solution exists) and an inductive case (where additional reduction is required).
- They spawn threads to handle components of an extensive calculation or data manipulation so that time-to-completion is reduced. They combine the threads’ results to form the overall solution. They can also be created via processes in non-shared memory running on geographically-dispersed computers.
- They combine solutions to random simpler problems to provide insight into more-complex problems. The solution to simpler problems leads to solutions of problems at a higher and higher level of generality. They can then be used to provide solutions to different specific cases than the ones originally encountered.
Question 29: QuickSort is a recursive sorting method that generally takes the following steps:
- Pick one element of the list to be the “pivot element”.
- Break the list one list of elements less than the pivot element, and one of elements greater than the pivot element.
- Sort each of the smaller lists recursively.
- Make one big list: the list of items smaller than the pivot element, then the pivot element, and then the list of elements bigger than the pivot element.
Which of the following implements this general paradigm in C++?
- #include <iostream>
using namespace std;
const int arraySize = 6;
int Partition_ChosePivot(double (&A)[arraySize], int beginRange, int endRange)
{
double hold;
double pivot = A[beginRange];
int left = beginRange;
for (int i = beginRange + 1; i <= endRange; i++)
{
if (A[i] < pivot)
{
left++;
hold = A[i];
A[i] = A[left];
A[left] = hold;
}
}
return left;
}
void QUICKSORT(double (&A)[arraySize], int beginRange, int endRange)
{
if (beginRange < endRange)
{
int pivot = Partition_ChosePivot(A, beginRange, endRange);
QUICKSORT(A, beginRange, pivot – 1);
QUICKSORT(A, pivot + 1, endRange);
}
}
int main()
{
double array[arraySize] = { 20, 2, 0, 1, 1, 10 };
QUICKSORT(array, 0, arraySize – 1);
for(int i = 0; i < arraySize; i++) cout << array[i] << “\n”;
return 0;
}
- #include <iostream>
using namespace std;
const int arraySize = 6;
int Partition_ChosePivot(double (&A)[arraySize], int beginRange, int endRange)
{
double hold;
double pivot = A[beginRange];
int left = beginRange;
for (int i = beginRange + 1; i <= endRange; i++)
{
if (A[i] < pivot)
{
left++;
hold = A[i];
A[i] = A[left];
A[left] = hold;
}
}
hold = A[beginRange];
A[beginRange] = A[left];
A[left] = hold;
return left;
}
void QUICKSORT(double (&A)[arraySize], int beginRange, int endRange)
{
if (beginRange < endRange)
{
int pivot = Partition_ChosePivot(A, beginRange, endRange);
QUICKSORT(A, beginRange, pivot – 1);
}
}
int main()
{
double array[arraySize] = { 20, 2, 0, 1, 1, 10 };
QUICKSORT(array, 0, arraySize – 1);
for(int i = 0; i < arraySize; i++) cout << array[i] << “\n”;
return 0;
}
- #include <iostream>
using namespace std;
const int arraySize = 6;
int Partition_ChoosePivot(double (&A)[arraySize], int beginRange, int endRange)
{
double hold;
double pivot = A[beginRange];
int left = beginRange;
for (int i = beginRange + 1; i <= endRange; i++)
{
if (A[i] < pivot)
{
left++;
hold = A[i];
A[i] = A[left];
A[left] = hold;
}
}
hold = A[beginRange];
A[beginRange] = A[left];
A[left] = hold;
return left;
}
void QUICKSORT(double (&A)[arraySize], int beginRange, int endRange)
{
if (beginRange < endRange)
{
int pivot = Partition_ChoosePivot(A, beginRange, endRange);
QUICKSORT(A, beginRange, pivot – 1);
QUICKSORT(A, pivot + 1, endRange);
}
}
int main()
{
double array[arraySize] = { 20, 2, 0, 1, 1, 10 };
QUICKSORT(array, 0, arraySize – 1);
for(int i = 0; i < arraySize; i++) cout << array[i] << “\n”;
return 0;
}
- #include <iostream>
using namespace std;
const int arraySize = 6;
int Partition_ChosePivot(double (&A)[arraySize], int beginRange, int endRange)
{
double hold;
double pivot = A[beginRange];
int left = beginRange;
for (int i = beginRange + 1; i <= endRange; i++)
{
if (A[i] < pivot)
{
left++;
hold = A[i];
A[i] = A[left];
A[left] = hold;
}
}
hold = A[beginRange];
A[beginRange] = A[left];
A[left] = hold;
return left;
}
void QUICKSORT(double (&A)[arraySize], int beginRange, int endRange)
{
if (beginRange < endRange)
{
int pivot = Partition_ChosePivot(A, beginRange, endRange);
QUICKSORT(A, beginRange, pivot – 1);
QUICKSORT(A, pivot + 1, endRange);
}
}
int main()
{
double array[arraySize] = { 20, 2, 0, 1, 1, 10 };
int pivot = 3;
QUICKSORT(array, pivot, arraySize – 1);
for(int i = 0; i < arraySize; i++) cout << array[i] << “\n”;
return 0;
}
Question 30: What is the most important consideration when selecting a sorting or searching algorithm?
- Using only one language rather than mixed languages
- Being able to self-implement rather than using established modules
- The average complexity of both time and memory for the expected data sizes
- Implementing so that as few machine or byte codes are executed during runtime as possible
Question 31: A very basic recursive formula in mathematics is fn+1=fn+fn−1��+1=��+��−1. Would this always work in computer science? Why or why not?
- Yes: any calculation expressed in mathematics can be expressed in the target computer language; the code simply has to be written and tested
- Yes: many modern languages in computer science contain the syntax to exactly translate the notation of mathematics into the notation of the language in question
- No: many modern languages in computer science are incapable of recursive operation; instead, recursive mathematics must be translated into non-recursive (explicit/iterative) procedures
- No: mathematics rests on the infinity theory, while computer science depends on finite machines; computers can realistically represent numbers of only limited size and accuracy, even with special software
Question 32: What can be an important difference in the implementation of list and tree search-and-sort algorithms?
- List search and sort cannot be implemented as in-pace algorithms
- Lists have only one link from one data-element’s memory to another
- Data organized for list search and sort often occupies contiguous memory
- List search and sort generally require twice the amount of memory as occupied by the dataset
Question 33: Data has been organized in this binary tree for searching. What traversal method would you use to find the exact target-value match?
- Depth-first
- Breadth-first
- Sequential memory locations
- Either row-first or column-first
Question 34: What are basic approaches to analyzing the time complexity of a search or sort algorithm’s implementation?
- Count the number of lines in the pre-compiled source code, and add a factor for loops
- Count the number of assembler tokens or byte codes generated from the source code
- Count lines of executable code, run timing experiments, and add time for sorting data
- Add a multiplier for each memory access required during operations when the language requires it
Question 35: This chart illustrates the memory complexity of two different designs for accomplishing a given task. The vertical axis is the amount of memory involved. The horizontal axis is the size of the dataset. What conclusion can be drawn from the chart?
- The algorithm in red is always better
- The algorithm in blue is always better
- Either algorithm works when there is sufficient memory
- The algorithm in blue is better for datasets of size 45 or less
Question 36: Which of the following best describes how programming languages have broadly progressed to lead up to the object-oriented approach used today?
- From functional, to modular, to object-oriented
- From abstractions of the computer to abstractions of the problem to be solved
- From binary, to assembler, to imperative languages, to higher-level languages
- From large volumes of hard-to-read code to smaller volumes of easy-to-read code
Question 37: How did programming languages change as generic programming was developed?
- It became more common to use reusable trusted code instead of writing everything from scratch
- The classes within object-oriented programming languages started to be seen as new data types
- They evolved from personal and open-access programming libraries to language-standard libraries
- They evolved from type-specific functions and subroutines to type-inspecific functions and subroutines
Question 38: What is it about iterators that is so important to generic programming?
- They enable visiting all elements of a data structure without regard for the type of a structure’s elements
- They point to generic data elements regardless of their physical location; they are host-location agnostic
- They are a direct replacement for the index of for loops; one simply defines the iterator type appropriately
- They reference all duplicative records within main and backup databases, they are record-length agnostic
Question 39: Computers execute programs that are stored as a sequence of low-level machine language instructions in the computer’s memory. They do this by repeatedly reading (fetching) an instruction from memory and then carrying out (executing) that instruction. This process is called the fetch-and-execute cycle. But neither C++ nor Java language code is directly executable, and these languages are not the same as machine language. How does the computer get its machine-language instructions?
- Both C++ and Java go through a compile-then-link process that produces machine code that runs directly on the compute
- Both C++ and Java generate pseudo-code that is interpreted by a separate low-level program that is written specifically for a given type of CPU
- The C++ compiler creates bytecodes that are interpreted by an operating system process, while the Java compiler creates machine language, and a linker ties code modules together into a directly-executable program
- C++ uses a compiler to create machine language and a linker to tie code modules together into a directly-executable program, while Java’s compiler creates bytecodes that are interpreted by the Java Virtual Machine
Question 40: How does the overall focus of C++ compare to the overall focus of Java?
- C++ has an embedded library of functionality that is part of the language standard, while Java requires the use of third-party libraries if one wishes to employ common functions and data structures
- C++ targets systems and applications programming, and efficient direct execution, while Java is a general-purpose language with enhanced portability that operates through a virtual machine
- C++ completely replaces the C language with object-oriented and data-generic programming and Java’s syntax similar to C++; both languages can implement functionality implemented in the other language
- C++ does not enable direct object-oriented programming and requires defined data structures and separate functions for manipulating those structures, while Java directly supports full object-oriented programming
Question 41: Programmer-defined data-types are very interesting, since they can be composed of subtypes defined by programmers, languages, and even native primitive types. Why is this important for generic programming?
- Optimal runtime modules are created thereby, which minimizes memory and time consumption
- Linkers and interpreters can readily interpret such variables, which minimizes program build time
- Machine-code is more-easily generated under such circumstances, which minimizes compile time
- No data-type has to be defined until compile-time, which makes top-level data-types flexible and reusable
Question 42: C++, its object orientation, and its Standard Template Library enable a fundamental transition in thought as a project proceeds. What transition might that be?
- Abstract during conceptualization and design, to specific in implementation and programming
- Geographic agnosticity is maintained until runtime, when specific modules are remotely called
- Memory utilization is not an issue since virtual memory is always available or swapping is used
- Runtime timing requirements can be left to the compiler/linker to satisfy via its optimization capabilities
Question 43: In order to better manage submitted computer jobs, it is sometimes good to let very long jobs run while allowing short jobs to also be satisfied (assuming for now that the memory capacity of the computer is sufficient). Which C++ Standard Template Library component could be used best to demonstrate how the longest-waiting jobs in those two categories would be run first?
- Graph
- List
- Queue
- Set
Question 44: Which of the following code snippets uses the C++ Standard Template Library to show how to display local time and Coordinated Universal Time?
- #include <iostream>
#include <time.h>
using namespace std;
int main()
{
time_t result = time(NULL);
cout << “Local Time: ” << result << endl;
cout << “Coordinated Universal Time: ” << result + (7*60*60) << endl;
return 0;
}
- #include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t result = time(nullptr);
cout << “Local Time: ” << asctime(localtime(&result)) << endl;
cout << “Coordinated Universal Time: ” << asctime(gmtime(&result)) << endl;
return 0;
}
- #include <iostream>
#include <ctime>
using namespace std;
int main()
{
time_t result = time(nullptr);
cout << “Local Time: ” << asctime(localtime(&result)) << endl;
cout << “Coordinated Universal Time: ” << asctime(system_clock(&result))<<endl;
return 0;
}
- #include <iostream>
#include <time.h>
using namespace std;
int main()
{
time_t result = time(NULL);
cout << “Local Time: ” << result << endl;
cout << “Coordinated Universal Time: ” << result + (60*60) << endl;
return 0;
}
Question 45: You are writing a program, but you notice that many of the C++ processes spawned by the program place messages on the console. These messages come out as gibberish, since they overlap and interfere with each other, which means that nothing is legible. Which of the following Standard Template Library approaches could help to overcome this problem?
- #include <iostream>
#include <thread>
#include <mutex>
using namespace std;
mutex consoleMutex;
void workingThread (int id)
{
int myID = id;
consoleMutex.lock();
std::cout << “Thread # ” << myID << ‘\n’;
consoleMutex.unlock();
}
int main ()
{
std::thread threads[10];
for (int i = 0; i < 10; ++i)
threads[i] = thread(workingThread, i + 1);
for (auto& th : threads) th.join();
return 0;
}
- #include <iostream>
#include <thread>
#include <mutex>
using namespace std;
mutex consoleMutex;
void workingThread (int id)
{
int myID = id;
std::cout << “Thread # ” << myID << ‘\n’ << flush;
}
int main ()
{
std::thread threads[10];
for (int i = 0; i < 10; ++i)
threads[i] = thread(workingThread, i + 1);
for (auto& th : threads) th.join();
return 0;
}
- #include <iostream>
#include <thread>
#include <mutex>
using namespace std;
mutex consoleMutex;
void workingThread (int id)
{
int myID = id;
consoleMutex.lock();
std::cout << “Thread # ” << myID << ‘\n’ << flush;
consoleMutex.unlock();
}
int main ()
{
std::thread threads[10];
for (int i = 0; i < 10; ++i)
threads[i] = thread(workingThread, i + 1);
for (auto& th : threads) th.join();
return 0;
}
- #include <iostream>
#include <thread>
#include <mutex>
using namespace std;
mutex consoleMutex;
void workingThread (int id)
{
int myID = id;
this_thread::sleep_for(std::chrono::seconds(2));
std::cout << “Thread # ” << myID << ‘\n’ << flush;
}
int main ()
{
std::thread threads[10];
for (int i = 0; i < 10; ++i)
threads[i] = thread(workingThread, i + 1);
for (auto& th : threads) th.join();
return 0;
}
Question 46: Data collections and arrays of data both hold references to objects and can be managed as a group. Which of the following are the major differences between data collections and arrays of data?
- Arrays hold primitive types such as int, long, or double, while collections hold wrapper classes such as Integer, Long, or Double
- Collections hold primitive types such as int, long, or double, while arrays hold wrapper classes such as Integer, Long, or Double
- Arrays need to be assigned a static capacity when created, while collections vary in size automatically when objects are added or removed
- Collections need to be assigned a static capacity when created, while arrays vary in size automatically when objects are added or removed
Question 47: In Java, lists are implemented in the collections framework via the java.util.List interface. Which of the following best describes lists in Java?
- They are a more flexible version of an array, since elements have a specific order, duplicate elements are allowed, and elements can be placed in a specific position or searched for within the list
- They are a more flexible version of a set, since elements do not have a specific order and duplicate elements are not allowed, but elements can be placed in a specific position and be searched for within the list
- They are a more flexible version of a map, since elements are a key/data pair, duplicate elements are allowed, and elements cannot be placed in a specific position but can be searched for within the list using the key
- They are a more flexible version of a queue, since elements are pushed onto the queue, duplicate elements are allowed, and elements cannot be placed in a specific position but are referenced only at the front or back of the queue
Question 48: Binary Search is known to have time complexity O(Clog10(n))�(�log10(�)). After implementation and testing, It was found that a variable was constantly redefined within a loop. Moving the definition outside the loop made the code run faster. How would the time complexity of the algorithm and its implementation be restated? C�, X�, and E� refer to numeric constants whose values are greater than 00. n� refers to the size of the data block. The value of X� is less than C�.
- O(C×n−−√)�(�×�)
- O(E×ln(n))�(�×ln(�))
- O(C×log2(n))�(�×log2(�))
- O((C−X)log10(n))�((�−�)log10(�))
Question 49: What is the most important consideration during QuickSort?
- Choosing the pivot point
- Ensuring there is pre-sorted data
- Implementing in the right language
- Choosing between recursive or explicit implementation
Question 50: In what cases is linear search faster than binary search?
- When you have a large dataset
- When you have a pre-sorted dataset
- When you have a very small dataset
- When you have a dataset managed by a SQL DBMS
Question 51: From what two perspectives can memory and time complexity be analyzed?
- Language and symbology
- Algorithm and implementation
- Source and assembler or byte code
- Lines of source code and lines of executable code
Question 52: Why did software design practice evolve to object-orientation?
- To increase the quality of final software products
- To help people naturally focus on the problem to be solved
- To provide excellent support for CMMI software project requirements
- To enable languages to be human-focused instead of machine-focused
Question 53: Which of the following is an important difference in numerical representation in C++ as compared to Java?
- C++ has no standardized byte-size limits for any primitive numeric types, while Java has standardized limits and sizes of all primitive numeric types on all platforms
- In C++, primitive operations on numerical data always yield the same result from platform-to-platform, while in Java results from primitive operations on numerical data can vary from platform to platform
- In C++, programs involving numeric data are not portable from platform to platform, while in Java all programs are fully portable from platform to platform as long as a JVM exists for the target platform
- C++ has standardized minimum byte-size limits for all primitive numeric types and maximum byte sizes are platform-defined, while Java has standardized limits and sizes of all primitive numeric types on all platforms
Question 54: Why do object orientation and generic programming go together so naturally?
- They lead directly to efficient networked systems
- They are specifically designed for shared and non-shared memory environments
- They lead to a common language syntax that works well with most compilers and interpreters
- They enable a disassociation of the computer and its languages from the problem to be solve
Question 55: What are the two major categories in the C++ Standard Template Library?
- Data structures that are linear and associative
- Local and remote hosting of program modules
- Shared and non-shared memory for storing data structures
- Compiled/linked and interpreted code for runtime implementation
Question 56: Historically, what was used before automatic exceptions were added to languages?
- Hardware interrupts that stopped programs
- Flags that were set for programmers to check
- Error messages that were sent to the console
- Operating system interrupts that stopped programs
Question 57: Which of the following is a benefit of exception handling?
- It is a way to check flags set by program components
- It tends to reduce the complexity of error-handling code
- It automatically expands lines of code to improve programmer productivity
- It meets all international standards in code project administrative requirements
Question 58: A recursive Java process is known to run out of stackspace for certain user parameters. Extending stackspace has not proven to provide a useful solution for all user requirements. Which of the following code snippets prototypes a temporary fix to this issue that keeps the program from crashing, while providing useful information?
- // File: Utilities.java
package com.company;
public class Utilities
{
private boolean continueTask = true;
public boolean get_continueTask() { return continueTask;}
public void CallNext()
{
Integer[] theseIntegers = new Integer[99999];
try
{
if(continueTask) CallNext(); else return;
}
catch (Exception e)
{
System.out.println(“*** Caught StackOverflowError. Point A.”);
System.out.println(” Unable to continue with this task.”);
e.printStackTrace();
continueTask = false;
return;
}
}
}
// File: Main.java
package com.company;
public class Main
{
public static void main(String[] args)
{
Utilities U = new Utilities();
U.CallNext();
if( ! U.get_continueTask())
System.out.println
(“\n… message to client … Unable to fulfill request.”);
}
}
- // File: Utilities.java
package com.company;
public class Utilities
{
private boolean continueTask = true;
public boolean get_continueTask() { return continueTask;}
public void CallNext()
{
Integer[] theseIntegers = new Integer[99999];
continueTask = false;
CallNext();
continueTask = true;
}
}
// File: Main.java
package com.company;
public class Main
{
public static void main(String[] args)
{
Utilities U = new Utilities();
U.CallNext();
if( ! U.get_continueTask())
System.out.println
(“\n… message to client … Unable to fulfill request.”);
}
}
- // File: Utilities.java
package com.company;
public class Utilities
{
public void CallNext()
{
Integer[] theseIntegers = new Integer[99999];
try
{
CallNext()
}
catch (StackOverflowError e) { }
}
}
// File: Main.java
package com.company;
public class Main
{
public static void main(String[] args)
{
Utilities U = new Utilities();
U.CallNext();
}
}
- // File: Utilities.java
package com.company;
public class Utilities
{
public void CallNext()
{
Integer[] theseIntegers = new Integer[99999];
try
{
if(continueTask) CallNext(); else return;
}
catch (StackOverflowError e)
{
System.out.println(“*** Caught StackOverflowError. Point A.”);
System.out.println(” Unable to continue with this task.”);
e.printStackTrace();
continueTask = false;
return;
}
}
}
// File: Main.java
package com.company;
public class Main
{
public static void main(String[] args)
{
Utilities U = new Utilities();
U.CallNext();
if( ! U.get_continueTask())
System.out.println
(“\n… message to client … Unable to fulfill request.\n”);
}
}
Question 59: A server responds to a large number of client requests that arrive continuously. These requests employ extensive calculations over large blocks of data. Two Java functions have been shown to perform this function well and within reasonable amounts of time. However, one of the functions is recursive and keeps throwing StackOverflowError. This error is caught, the client is informed that the server cannot perform the required processing, and the server goes on to the next client request. What should be done about this situation?
- Recursive processes are far easier to understand and maintain. The server’s memory should be increased so that additional recursive steps can be taken by all processes.
- The recursive process should be replaced by the explicit process. Documentation of the algorithm and its implementation should be brought up to date so that the code can be understood and maintained.
- Java has compiler options to increase stackspace. This option should be employed. If memory continues to be a problem, additional memory should be added to the server since memory is cheap.
- The server’s process documentation should be updated to show the limits of data-block size. A list of other servers that perform the required processing for larger data blocks should be made available in a help file.
Question 60: What is one of the commonly-accepted goals of binary search, and how can it be expanded?
- You usually search for an exact match, but it might be better to allow for some cases where a close-enough match would bring satisfactory results
- You usually assume that the target value is present, but it might be better to modify the basic algorithm so that “target not present” can be recognized
- You usually want to start the search at one end or the other of the dataset, but it might be better to spawn two threads, each of which starts their search from different ends to search through the middle index
- You usually have SQL databases that are readily segmented and are accessible via networked computers; rather than have one distributed process search the database, it might be better to have several computers engaged in the search
Question 61: Which of the following indicates a fundamental problem with binary search, and describes something that can be done about it?
- It returns any index whose element is equal to the target value, even if there are duplicate elements in the dataset; a solution is to reinitialize the search using a different “middle” index
- It may return no indexes even if the target value is present; a solution is to search for pseudo-target values that are near to the target value, which ensures the target value will be found if present
- It returns any index whose element is equal to the target value, even if there are duplicate elements in the dataset; a solution is to linearly search left and right of the index for all elements equal to the target value
- It returns only the left-most index whose element is equal to the target value; a solution to ensure there are no elements in the dataset is to linearly search to the right of the index for all elements equal to the target value
Question 62: Within the object-oriented approach to providing solutions, what is the programmer’s real job?
- To write and test classes and instances that represent the objects within the program design
- To write correct, well-commented, and well-tested code that meets all specified project requirements
- To establish an association between the machine model and a model of the problem that is being solved
- To begin with a flowchart to show the flow of logic and then construct modules to enable that flowchart
Question 63: Some earlier programming languages choose a particular view of the world. What was wrong with these language-based approaches to problem-solving?
- Earlier languages were oriented toward the bits and bytes of computers, which meant that they did not enable writing portable code
- Earlier languages enabled good solutions to particular types of problems, but they became awkward to use to solve problems outside of that domain
- Earlier languages, like functional and modular languages, were insufficiently general in nature and do not support modern problem-solving techniques
- Earlier programs were written with limited memory as the most critical resource, which did not let them generalize the way they implemented algorithms
Question 64: What is the difference between objects’ methods and subroutines?
- Objects are independent, but subroutines are dependent and part of the codebase
- Subroutines can be made re-entrant, but care is needed in managing accessed memory
- There can be only one copy of a subroutine, but multiple objects can be created from a single class
- Threads can always call subroutines multiple times at once, but there can be only one class instance
Question 65: What are three fundamental features of generic programming?
- Primary use-cases, involvement of sponsors in projects, and classes instantiated by objects
- Remote procedure calls, memory that can be shared or independent, and remote memory access
- Language independence, functionality independent of data type, and programmer-defined data types
- Mixed-language systems, geographical independence of functionality, and inter-module communication
Question 66: Which of the following is a difference between Java and C++, in regard to how they handle objects or instances of classes?
- Java does not allow direct memory access; C++ allows direct memory access.
- Everything, every variable type, is an object in Java; such is not the case in C++.
- Java has automatic consolidation of released memory; C++ does not automatically consolidate memory.
- One can never cause memory to be orphaned in Java; it is possible to create orphaned memory in C++.
Question 67: Many industrial applications are hard-realtime (that is, they have strict timing requirements), whereas most business applications are soft-realtime (that is, they have loose timing requirements). Between C++ and Java, which language would you choose for hard-realtime industrial applications, and why?
- C++, since its Standard Template Library is far superior to Java’s Collection Library
- C++, since it executes directly while Java requires the use of intermediate execution software
- Java, since C++ takes much longer to write and test because it enables direct memory manipulation
- Java, since its internal testing and documentation capability enables assurance of timing requirements
Question 68: What does an ordered list let programmers do?
- Store references to objects with a lookup key for accessing the object’s values
- Insert items in a certain sequence and retrieve those items in the same sequence
- Create a fixed-size vector that objects can be placed into for later indexed referencing
- Create unordered collections that can be iterated and that contain each element at most once
Question 69: What happens when an exception is thrown in either Java or C++?
- A flag is set when it is not possible to continue processing because the information necessary to deal with the problem in the current context is not available
- Hardware interrupts are automatically thrown when it is not possible for the CPU to continue processing because the information necessary to deal with the problem is not available
- Software interrupts are automatically thrown when it is not possible to continue processing because the information necessary to deal with the problem in the current context is not available
- if/else statements are used to detect situations where it is not possible to continue processing because the information necessary to deal with the problem in the current context is not available
Question 70: Consider this logic flow. What is true about the reliability of the program?
- Mutex is essential because of the use of shared memory by the recursive functions; otherwise, the results will be incorrect
- The program will run faster because of the use of simultaneous threads, and the computer will remain as reliable as it was before
- The computer will not be able to handle simultaneous threads cast in this manner, but it would work if each thread were a process on a separate computer
- The program will run faster for smaller problems, but it will be unable to cope with larger problems because the stack will fill up faster as it is used by simultaneous threads
Question 71: What type of data structure are linear and binary search meant to use?
- List
- Tree
- Graph
- Network
Question 72: Which of the following correctly labels this graph to show the growth of time or memory for O(n), O(log(n)), O (1), O(n), O(log(n)), O (1), and O(n−−√) O (�)?
A.
B.
C.
D.
Question 73: What is a fundamental difference between objects and modules?
- Modules are always re-entrant, while objects are not
- Multiple objects of the same class can be created and exist independently, while modules cannot be
- Objects can be created and destroyed by threads, while modules can only be called from the main thread
- Modules execute when encountered in the logic-flow of a program, while objects can be called from anywhere
Question 74: What is the relationship between object-orientation and traditional approaches to software design?
- Machine-focused evolved to solution-focused and finally to object-orientation
- Languages evolved from those that few could work with to languages that many could work with
- Object-orientation is an evolution of modular, which is itself an evolution of functional approaches
- Machine-oriented languages evolved to human-oriented languages and then to object-oriented languages
Question 75: How have type-generic programming languages improved?
- It became impossible to call a class’ object method using an incorrect data type
- They started to fully support functional, modular, and object-oriented approaches
- It became unnecessary to write subroutines in the assembler to achieve timely execution
- Their compilers and linkers have decreased the amount of memory and processing time consumed
Question 76: Classes instantiated as objects are central to object-oriented programming. Which of the following Java code snippets puts a native object into a list and uses an explicit iterator to visit each element in the list?
- package com. company;
import java.util.*;
public class ListExample
{
public static void main (String args [])
{
List<String> list = new ArrayList<String> ();
Iterator it = list. iterator ();
list.add(“Dog”);
list.add(“Cat”);
list.add(“Horse”);
list.add(“Cow”);
while (it. hasNext ())
{
String obj = (String)it. next ();
System.out.println(obj);
}
}
}
- package com. company;
import java.util.*;
public class ListExample
{
public static void main (String args [])
{
List<String> list = new ArrayList<String> ();
Iterator it = list. iterator ();
list.add(“Dog”);
list.add(“Cat”);
list.add(“Horse”);
list.add(“Cow”);
for (String animal: list) System.out.println(animal);
}
}
- package com. company;
import java.util.*;
public class ListExample
{
public static void main (String args [])
{
List<String> list = new ArrayList<String> ();
Iterator it = list. iterator ();
list.add(“Dog”);
list.add(“Cat”);
list.add(“Horse”);
list.add(“Cow”);
int length = list. size ();
for (int i = 0; i < length; i++)
{
String obj = (String)list.get(i);
System.out.println(obj);
}
}
}
- package com. company;
import java.util.*;
public class ListExample
{
public static void main (String args [])
{
List<String> list = new ArrayList<String> ();
Iterator it = list. iterator ();
list.add(“Dog”);
list.add(“Cat”);
list.add(“Horse”);
list.add(“Cow”);
int length = list. size ();
for (int i = length – 1; i >= 0; i–)
{
String obj = (String)list.get(i);
System.out.println(obj);
}
}
}
Question 77: Which of the following uses the C++ “set” object from the Standard Template Library to ensure only one record pointer can be stored at a time, but also shows how duplicate record pointers can be identified?
- #include <iostream>
#include <set>
using namespace std;
typedef struct {string key; string elements [10];} Record, * pRecord;
pRecord thisRecord;
set<pRecord> Database;
pair<set<pRecord>: iterator, bool> checkForDuplicateRecord;
int main ()
{
thisRecord = new Record;
thisRecord->key = “One Key to Career Development:”;
thisRecord->elements [0] = “Study”;
thisRecord->elements [1] = “Learn”;
thisRecord->elements [2] = “Work”;
thisRecord->elements [3] = “Produce”;
thisRecord->elements [4] = “Cycle Repeatedly”;
Database.insert(thisRecord);
for (auto key_value: Database)
{
cout << key_value->key << endl;
for (int i = 0; i < 5; i++) cout << key_value->elements[i] << endl;
}
checkForDuplicateRecord = Database.insert(thisRecord);
return 0;
}
- #include <iostream>
#include <set>
using namespace std;
typedef struct {string key; string elements [10];} Record, * pRecord;
pRecord thisRecord;
set<pRecord> Database;
pair<set<pRecord>: iterator, bool> checkForDuplicateRecord;
int main ()
{
thisRecord = new Record;
thisRecord->key = “One Key to Career Development:”;
thisRecord->elements [0] = “Study”;
thisRecord->elements [1] = “Learn”;
thisRecord->elements [2] = “Work”;
thisRecord->elements [3] = “Produce”;
thisRecord->elements [4] = “Cycle Repeatedly”;
Database.insert(thisRecord);
for (auto key_value: Database)
{
cout << key_value->key << endl;
for (int i = 0; i < 5; i++) cout << key_value->elements[i] << endl;
}
checkForDuplicateRecord = Database.insert(thisRecord);
if (checkForDuplicateRecord.second)
cout << endl << “Duplicate record not inserted” << endl;
return 0;
}
- #include <iostream>
#include <set>
using namespace std;
typedef struct {string key; string elements [10];} Record, * pRecord;
pRecord thisRecord;
set<pRecord> Database;
pair<set<pRecord>: iterator, bool> checkForDuplicateRecord;
int main ()
{
thisRecord = new Record;
thisRecord->key = “One Key to Career Development:”;
thisRecord->elements [0] = “Study”;
thisRecord->elements [1] = “Learn”;
thisRecord->elements [2] = “Work”;
thisRecord->elements [3] = “Produce”;
thisRecord->elements [4] = “Cycle Repeatedly”;
Database.insert(thisRecord);
for (auto key_value: Database)
{
cout << key_value->key << endl;
for (int i = 0; i < 5; i++) cout << key_value->elements[i] << endl;
}
checkForDuplicateRecord = Database.insert(thisRecord);
if (checkForDuplicateRecord.second == false)
cout << endl << “Duplicate record not inserted” << endl;
return 0;
}
- #include <iostream>
#include <list>
using namespace std;
typedef struct {string key; string elements [10];} Record, * pRecord;
pRecord thisRecord;
list<pRecord> Database;
bool checkForDuplicateRecord;
int main ()
{
thisRecord = new Record;
thisRecord->key = “One Key to Career Development:”;
thisRecord->elements [0] = “Study”;
thisRecord->elements [1] = “Learn”;
thisRecord->elements [2] = “Work”;
thisRecord->elements [3] = “Produce”;
thisRecord->elements [4] = “Cycle Repeatedly”;
Database.push_back(thisRecord);
for (auto key_value: Database)
{
cout << key_value->key << endl;
for (int i = 0; i < 5; i++) cout << key_value->elements[i] << endl;
}
checkForDuplicateRecord = Database.push_back(thisRecord);
if (checkForDuplicateRecord == false)
cout << endl << “Duplicate record not inserted” << endl;
return 0;
}
Question 78: Which of the following code snippets uses the C++ Standard Template Library to demonstrate basic keyboard input and basic console output?
- #include <iostream>
using namespace std;
int main ()
{
int i;
do
{
cout << “Please enter an integer value (0 means quit): “;
cin << i;
if (i! = 0)
{
cout << “The value you entered is ” << i;
cout << ” and its double is ” << i * 2 << “.\n”;
}
} while (i! = 0);
return 0;
}
- #include <iostream>
using namespace std;
int main ()
{
int i;
do
{
cout << “Please enter an integer value (0 means quit): “;
scanf (“%d”, &i);
if (i! = 0)
{
cout << “The value you entered is ” << i;
cout << ” and its double is ” << i * 2 << “.\n”;
}
} while (i! = 0);
return 0;
}
- #include <iostream>
using namespace std;
int main ()
{
int i;
do
{
cout << “Please enter an integer value (0 means quit): “;
cin >> i;
if (i! = 0)
{
printf (“The value you entered is %d”, i;
printf (” and its double is %d.\n “, i * 2)”;
}
} while (i! = 0);
return 0;
}
- #include <iostream>
using namespace std;
int main ()
{
int i;
do
{
cout << “Please enter an integer value (0 means quit): “;
cin >> i;
if (i! = 0)
{
cout << “The value you entered is ” << i;
cout << ” and its double is ” << i * 2 << “.\n”;
}
} while (i! = 0);
return 0;
}
Question 79: Which of the following code snippets demonstrates how a Java List can be used as if it were a Java Set?
- package com. company;
import java.util.*;
class AnObject
{
public String objectName = “NotSpecified”;
public AnObject (String specification) {objectName = specification;}
public void GiveSpecification ()
{System.out.println(“Object’s Name is ” + objectName);}
}
public class Main
{
private static void AddObject (List<AnObject> objectList, AnObject thisObject)
{
if (objectList.contains(thisObject)! = true)
{
objectList.add(thisObject);
System.out.println(thisObject.objectName + ” added”);
}
else System.out.println(thisObject.objectName + ” not added”);
}
public static void main (String [] args)
{
List<AnObject> Objects = new LinkedList<AnObject> ();
AnObject thisObject = new AnObject (“First Object”);
Objects.add(thisObject);
Objects.add(thisObject);
System.out.println(Objects.size());
System.out.println(Objects.get (0). objectName);
}
}
- package com. company;
import java.util.*;
class AnObject
{
public String objectName = “NotSpecified”;
public AnObject (String specification) {objectName = specification;}
public void GiveSpecification ()
{System.out.println(“Object’s Name is ” + objectName);}
}
public class Main
{
private static void AddObject (List<AnObject> objectList, AnObject thisObject)
{
objectList.add(thisObject);
}
public static void main (String [] args)
{
List<AnObject> Objects = new LinkedList<AnObject> ();
AnObject thisObject = new AnObject (“First Object”);
AddObject (Objects, thisObject);
AddObject (Objects, thisObject);
System.out.println(Objects.size());
System.out.println(Objects.get (0). objectName);
}
}
- package com. company;
import java.util.*;
class AnObject
{
public String objectName = “NotSpecified”;
public AnObject (String specification) {objectName = specification;}
public void GiveSpecification ()
{System.out.println(“Object’s Name is ” + objectName);}
}
public class Main
{
private static void AddObject (List<AnObject> objectList, AnObject thisObject)
{
if (objectList.contains(thisObject) == true)
{
objectList.add(thisObject);
System.out.println(thisObject.objectName + ” added”);
}
else System.out.println(thisObject.objectName + ” not added”);
}
public static void main (String [] args)
{
List<AnObject> Objects = new LinkedList<AnObject> ();
AnObject thisObject = new AnObject (“First Object”);
AddObject (Objects, thisObject);
AddObject (Objects, thisObject);
System.out.println(Objects.size());
System.out.println(Objects.get (0). objectName);
}
}
- package com. company;
import java.util.*;
class AnObject
{
public String objectName = “NotSpecified”;
public AnObject (String specification) {objectName = specification;}
public void GiveSpecification ()
{System.out.println(“Object’s Name is ” + objectName);}
}
public class Main
{
private static void AddObject (List<AnObject> objectList, AnObject thisObject)
{
if (objectList.contains(thisObject)! = true)
{
objectList.add(thisObject);
System.out.println(thisObject.objectName + ” added”);
}
else System.out.println(thisObject.objectName + ” not added”);
}
public static void main (String [] args)
{
List<AnObject> Objects = new LinkedList<AnObject> ();
AnObject thisObject = new AnObject (“First Object”);
AddObject (Objects, thisObject);
AddObject (Objects, thisObject);
System.out.println(Objects.size());
System.out.println(Objects.get (0). objectName);
}
}
Question 80: Which of the following code snippets demonstrates how Java threads are allowed to run while other things are going on?
- package com. company;
class SampleThread extends Thread
{
private volatile String threadName;
SampleThread (String name)
{
threadName = name;
System.out.println(“Creating ” + threadName);
}
public void run ()
{
System.out.println(“Running ” + threadName);
for (int i = 4; i > 0; i–)
{
System.out.println(“Thread: ” + threadName + “, ” + i);
try {Thread.sleep(5);}
catch (InterruptedException e) {e. printStackTrace ();}
}
System.out.println(“Thread ” + threadName + ” exiting.”);
threadName = threadName + ” | Finished”;
}
public String getReturnValue () {return threadName;}
}
public class Main
{
public static void main (String args []) throws InterruptedException
{
SampleThread R1 = new SampleThread(“Thread-1″);
R1. start ();
while (R1. isAlive ()) {System.out.println(“Thread is alive”);};
System.out.println(“Have departed thread: ” + R1. getReturnValue ());
}
}
- package com. company;
class SampleThread extends Thread
{
private volatile String threadName;
SampleThread (String name)
{
threadName = name;
System.out.println(“Creating ” + threadName);
}
public void run ()
{
System.out.println(“Running ” + threadName);
for (int i = 4; i > 0; i–)
{
System.out.println(“Thread: ” + threadName + “, ” + i);
try {Thread.sleep(5);}
catch (InterruptedException e) {e. printStackTrace ();}
}
System.out.println(“Thread ” + threadName + ” exiting.”);
threadName = threadName + ” | Finished”;
}
public void start () {System.out.println(“Starting ” + threadName);}
public String getReturnValue () {return threadName;}
}
public class Main
{
public static void main (String args []) throws InterruptedException
{
SampleThread R1 = new SampleThread(“Thread-1″);
R1. start ();
while (R1. isAlive ()) {System.out.println(“Thread is alive”);};
System.out.println(“Have departed thread: ” + R1. getReturnValue ());
}
}
- package com. company;
class SampleThread extends Thread
{
private volatile String threadName;
SampleThread (String name)
{
threadName = name;
System.out.println(“Creating ” + threadName);
}
public void run ()
{
System.out.println(“Running ” + threadName);
for (int i = 4; i > 0; i–)
{
System.out.println(“Thread: ” + threadName + “, ” + i);
try {Thread.sleep(5);}
catch (InterruptedException e) {e. printStackTrace ();}
}
System.out.println(“Thread ” + threadName + ” exiting.”);
threadName = threadName + ” | Finished”;
}
public String getReturnValue () {return threadName;}
}
public class Main
{
public static void main (String args []) throws InterruptedException
{
SampleThread R1 = new SampleThread(“Thread-1″);
R1.run ();
while (R1. isAlive ()) {System.out.println(“Thread is alive”);};
System.out.println(“Have departed thread: ” + R1. getReturnValue ());
}
}
- package com. company;
class SampleThread extends Thread
{
private volatile String threadName;
SampleThread (String name)
{
threadName = name;
System.out.println(“Creating ” + threadName);
}
public void run ()
{
System.out.println(“Running ” + threadName);
for (int i = 4; i > 0; i–)
{
System.out.println(“Thread: ” + threadName + “, ” + i);
try {Thread.sleep(5);}
catch (InterruptedException e) {e. printStackTrace ();}
}
System.out.println(“Thread ” + threadName + ” exiting.”);
threadName = threadName + ” | Finished”;
}
//public void start () {System.out.println(“Starting ” + threadName);}
public String getReturnValue () {return threadName;}
}
public class Main
{
public static void main (String args []) throws InterruptedException
{
SampleThread R1 = new SampleThread(“Thread-1″);
R1. start ();
R1. join ();
System.out.println(“Have departed thread: ” + R1. getReturnValue ());
}
}
Question 81: Java can create various connection architectures between processes across geographically-disconnected machines. Which of the following code snippets uses Java’s Collections Library to demonstrate a rudimentary SERVER within a client/server architecture?
- public class Server
{
public static void main (String [] args) throws IOException
{
boolean Continue = true;
Integer port = 5000;
ServerSocket serverSocket = new ServerSocket(port);
serverSocket.setSoTimeout(10000);
while (Continue)
{
try
{
System.out.println(“Waiting for client on port ” +
serverSocket.getLocalPort());
Socket server = serverSocket.accept();
System.out.println(“Connected to client at address ” +
server. getRemoteSocketAddress ());
DataInputStream in = new DataInputStream (server. getInputStream ());
System.out.println(in. readUTF ());
DataOutputStream out = new DataOutputStream (server. getOutputStream ());
out. writeUTF (“Thank you for connecting to ” +
server. getLocalSocketAddress () + “\nGoodbye!”);
server. close ();
Continue = false;
}
catch (SocketTimeoutException s) {System.out.println(“Socket timeout”);}
catch (IOException e) {e. printStackTrace ();}
}
}
}
- import java.net. *;
import java.io. *;
public class Server
{
public static void main (String [] args) throws IOException
{
boolean Continue = true;
Integer port = 5000;
ServerSocket serverSocket = new ServerSocket(port);
serverSocket.setSoTimeout(10000);
while (Continue)
{
serverSocket.getLocalPort());
Socket server = serverSocket.accept();
System.out.println(“Connected to client at address ” +
server. getRemoteSocketAddress ());
DataInputStream in = new DataInputStream (server. getInputStream ());
System.out.println(in. readUTF ());
DataOutputStream out = new DataOutputStream (server. getOutputStream ());
out. writeUTF (“Thank you for connecting to ” +
server. getLocalSocketAddress () + “\nGoodbye!”);
server. close ();
Continue = false;
}
}
}
- import java.net. *;
import java.io. *;
public class Server
{
public static void main (String [] args) throws IOException
{
boolean Continue = true;
Integer port = 5000;
ServerSocket serverSocket = new ServerSocket(port);
serverSocket.setSoTimeout(10000);
while (Continue)
{
try
{
System.out.println(“Waiting for client on port ” +
serverSocket.getLocalPort());
Socket server = serverSocket.accept();
System.out.println(“Connected to client at address ” +
server. getRemoteSocketAddress ());
DataInputStream in = new DataInputStream (server. getInputStream ());
System.out.println(in. readUTF ());
DataOutputStream out = new DataOutputStream (server. getOutputStream ());
out. writeUTF (“Thank you for connecting to ” +
server. getLocalSocketAddress () + “\nGoodbye!”);
server. close ();
Continue = false;
}
catch (SocketTimeoutException s) {System.out.println(“Socket timeout”);}
catch (IOException e) {e. printStackTrace ();}
}
}
}
- import java.net. *;
import java.io. *;
public class Server
{
public static void main (String [] args) throws IOException
{
boolean Continue = true;
Integer port = -1;
ServerSocket serverSocket = new ServerSocket(port);
serverSocket.setSoTimeout(10000);
while (Continue)
{
try
{
System.out.println(“Waiting for client on port ” +
serverSocket.getLocalPort());
Socket server = serverSocket.accept();
System.out.println(“Connected to client at address ” +
server. getRemoteSocketAddress ());
DataInputStream in = new DataInputStream (server. getInputStream ());
System.out.println(in. readUTF ());
DataOutputStream out = new DataOutputStream (server. getOutputStream ());
out. writeUTF (“Thank you for connecting to ” +
server. getLocalSocketAddress () + “\nGoodbye!”);
server. close ();
Continue = false;
}
catch (SocketTimeoutException s) {System.out.println(“Socket timeout”);}
catch (IOException e) {e. printStackTrace ();}
}
}
}
Question 82: What is an important difference between Java and C++ regarding exception handling?
- Java’s exception handling includes standard exceptions, while C++ does not
- Java enforces handling exceptions thrown by its components, while C++ does not
- Java’s exception handling allows for programmer expressiveness, while C++ does not
- Java is has a comparatively limited way of handling exceptions, while C++ is more robust
Question 83: Which of the following is an important difference between the way “exceptions” were handled historically as compared to how they are handled today?
- Historically they were passive; now they are active, and must be handled in both C++ and Java
- Historically they had weak conditionals; now, expanded conditionals exist in both C++ and Java
- Historically they were passive; now they are active, and automatically handled at some level in both C++ and Java
- Historically they caused code bloat; now, this is still true, and both C++ and Java require writing a tremendous volume of code
Question 84: Which of the following is an exception that exists in Java, but not C++?
- Divide by zero
- Out of memory
- Custom exceptions
- Square-root of negative number
Question 85: When a divide-by-zero error happens, Java generates an exception. However, C++ does not. This is because C++ produces directly-executable machine-code, whereas Java interprets bytecode for execution by the JVM. If you wanted to use exceptions in C++ to catch errors that C++ does not generate exceptions for, which of the following would do that?
- #include <iostream>
using namespace std;
int main ()
{
try
{
int i = 5;
if (i == 5) throw “Division by zero.”;
int j = i / (i – 5);
}
catch (char* E)
{
cout << “*** Main: Exception. Point A. Type: ” << E << endl;
cout << “Program Abended” << endl;
return -1;
}
cout << “Program Ended Normally”;
return 0;
}
- #include <iostream>
using namespace std;
int main ()
{
try
{
int i = 5;
if (i == 5) throw “Division by zero.”;
int j = i / (i – 5);
}
catch (const char* E)
{
cout << “*** Main: Exception. Point A. Type: ” << E << endl;
cout << “Program Abended” << endl;
return -1;
}
cout << “Program Ended Normally”;
return 0;
}
- #include <iostream>
using namespace std;
int main ()
{
int i = 5;
int j = i / (i – 5);
cout << “Program Ended Normally”;
return 0;
}
- #include <iostream>
using namespace std;
int main ()
{
try
{
int i = 5;
int j = i / (i – 5);
}
catch (Exception &E)
{
cout << “*** Main: Exception. Point A. Type: ” << E. what () << endl;
cout << “Program Abended” << endl;
return -1;
}
cout << “Program Ended Normally”;
return 0;
}
Question 86: The standard exceptions generated by C++ sometimes require more processing than would be appropriate for a simple catch statement. Which of the following is a rudimentary way of blending this kind of processing with a try/catch paradigm?
- #include <iostream>
using namespace std;
class Polymorphic {public: void Member () {cout << “my member” << endl;}};
class NullPolymorphic: public exception
{
private: string feedback;
public: Polymorphic *newPolymorphic;
public:
NullPolymorphic (string feedback, Polymorphic *thisPolymorphic)
{
// some processing on constructor input values
thisPolymorphic = new Polymorphic (); // result of that processing
this->newPolymorphic = thisPolymorphic;
this->feedback = feedback;
}
const char* what () const throw () {return feedback.c_str ();}
};
int main ()
{
Polymorphic* pb = NULL;
try
{
pb = NULL;
if (pb == NULL)
throw NullPolymorphic
(“Exception: pb = NULL at Point A. New Polymorphic created.”, pb);
else pb->Member ();
}
catch (const NullPolymorphic &e)
{
cout << “An exception occurred: ” << endl << e. what () << ‘\n’;
cout << “*** Location: Module Main: Catch Statement: 001” << endl;
pb = e. newPolymorphic;
cout << “New pb value = ” << pb << endl;
}
cout << “Processing continues” << endl;
cout << “Program Ended Normally” << endl;
return 0;
}
- #include <iostream>
#include <exception>
using namespace std;
class Polymorphic {public: void Member () {cout << “my member” << endl;}};
class NullPolymorphic: public exception
{
private: string feedback;
public: Polymorphic *newPolymorphic;
public:
NullPolymorphic (string feedback, Polymorphic *thisPolymorphic)
{
// some processing on constructor input values
thisPolymorphic = new Polymorphic (); // result of that processing
this->newPolymorphic = thisPolymorphic;
this->feedback = feedback;
}
const char* what () const throw () {return feedback.c_str ();}
};
int main ()
{
Polymorphic* pb = NULL;
try
{
pb = NULL;
if (pb == NULL)
throw NullPolymorphic
(“Exception: pb = NULL at Point A. New Polymorphic created.”, pb);
else pb->Member ();
}
catch (NullPointerException &e)
{
cout << “An exception occurred: ” << endl << e. what () << ‘\n’;
cout << “*** Location: Module Main: Catch Statement: 001” << endl;
pb = e. newPolymorphic;
cout << “New pb value = ” << pb << endl;
}
cout << “Processing continues” << endl;
cout << “Program Ended Normally” << endl;
return 0;
}
- #include <iostream>
#include <exception>
using namespace std;
class Polymorphic {public: void Member () {cout << “my member” << endl;}};
class NullPolymorphic: public exception
{
private: string feedback;
public: Polymorphic *newPolymorphic;
public:
NullPolymorphic (string feedback, Polymorphic *thisPolymorphic)
{
// some processing on constructor input values
thisPolymorphic = new Polymorphic (); // result of that processing
this->newPolymorphic = thisPolymorphic;
this->feedback = feedback;
}
const char* what () const throw () {return feedback.c_str ();}
};
int main ()
{
Polymorphic* pb = NULL;
try
{
pb = NULL;
if (pb == NULL)
throw NullPolymorphic
(“Exception: pb = NULL at Point A. New Polymorphic created.”, pb);
else pb->Member ();
}
catch (const NullPolymorphic &e)
{
cout << “An exception occurred: ” << endl << e. what () << ‘\n’;
cout << “*** Location: Module Main: Catch Statement: 001” << endl;
pb = e. newPolymorphic;
cout << “New pb value = ” << pb << endl;
}
cout << “Processing continues” << endl;
cout << “Program Ended Normally” << endl;
return 0;
}
- #include <iostream>
#include <exception>
using namespace std;
class Polymorphic {public: void Member () {cout << “my member” << endl;}};
class NullPolymorphic: public exception
{
private: string feedback;
public: Polymorphic *newPolymorphic;
public:
NullPolymorphic (string feedback, Polymorphic *thisPolymorphic)
{
// some processing on constructor input values
thisPolymorphic = new Polymorphic (); // result of that processing
this->newPolymorphic = thisPolymorphic;
this->feedback = feedback;
}
const char* what () const throw () {return feedback.c_str ();}
};
int main ()
{
Polymorphic* pb = NULL;
try
{
pb = NULL;
if (pb == NULL)
throw NullPolymorphic
(“Exception: pb = NULL at Point A. New Polymorphic created.”, pb);
else pb->Member ();
}
catch (const NullPolymorphic &e)
{
cout << “An exception occurred: ” << endl << e. what () << ‘\n’;
cout << “*** Location: Module Main: Catch Statement: 001” << endl;
pb = e. newPolymorphic;
cout << “New pb value = ” << pb << endl;
}
cout << “Processing continues” << endl;
cout << “Program Ended Normally” << endl;
return 0;
}
Question 87: Numerous clients connect to a server written in Java. The server allocates memory as needed to store client messages and data for processing. The same server code runs on several different machines. As the server runs, it uses memory but it is unknown how much memory each machine has. Which of the following code snippets uses exceptions to demonstrate how you could deal with this situation while continuing to run the server as new clients arrive?
- package com. company;
import java.util.*;
public class Main
{
public static void main (String [] args)
{
Map<Integer, String> clientData = new HashMap<Integer, String> ();
long messageSize = 999999;
long requiredMemory = 2 * messageSize;
String data = “”;
String messageData;
for (long i = 0; i < messageSize; i++) data = data + ” “;
System.out.println(data. length ());
Integer messageID = 0;
while(true)
{
try
{
messageData = new String ();
messageData = data; // receiving client data
clientData.put (messageID++, messageData);
// retrieving and processing stored client data
// removing client data when response generated
}
catch (java. lang. OutOfMemoryException e)
{
System.out.println(e. getMessage ());
System.out.println(“MessageID: ” + messageID.toString());
// retrieving and processing stored client data
// removing client data when response generated
for (int i = 0; i < 5; i++)
{
messageData = clientData.get (–messageID);
// process message data
clientData.remove(messageID, messageData);
}
}
}
}
}
- package com. company;
import java.util.*;
public class Main
{
public static void main (String [] args)
{
Map<Integer, String> clientData = new HashMap<Integer, String> ();
long messageSize = 999999;
long requiredMemory = 2 * messageSize;
String data = “”;
String messageData;
for (long i = 0; i < messageSize; i++) data = data + ” “;
System.out.println(data. length ());
Boolean Continue = true;
Integer messageID = 0;
while(true)
{
try
{
if (Runtime.getRuntime(). freeMemory () <= requiredMemory)
throw new OutOfMemoryException
(“Insufficient memory for new client data.”);
messageData = new String ();
messageData = data; // receiving client data
clientData.put (messageID++, messageData);
// retrieving and processing stored client data
// removing client data when response generated
}
catch (Exception e)
{
System.out.println(e. getMessage ());
System.out.println(“MessageID: ” + messageID.toString());
// retrieving and processing stored client data
// removing client data when response generated
for (int i = 0; i < 5; i++)
{
messageData = clientData.get (–messageID);
// process message data
clientData.remove(messageID, messageData);
}
}
}
}
}
- package com. company;
import java.util.*;
class OutOfMemoryException extends Exception
{
public OutOfMemoryException (String message)
{
super (“Custom Exception: ” + message);
}
}
public class Main
{
public static void main (String [] args)
{
Map<Integer, String> clientData = new HashMap<Integer, String> ();
long messageSize = 999999;
long requiredMemory = 2 * messageSize;
String data = “”;
String messageData;
for (long i = 0; i < messageSize; i++) data = data + ” “;
System.out.println(data. length ());
Boolean Continue = true;
Integer messageID = 0;
while(true)
{
try
{
if (Runtime.getRuntime(). freeMemory () <= requiredMemory)
throw new OutOfMemoryException
(“Insufficient memory for new client data.”);
messageData = new String ();
messageData = data; // receiving client data
clientData.put (messageID++, messageData);
// retrieving and processing stored client data
// removing client data when response generated
}
catch (OutOfMemoryException e)
{
System.out.println(e. getMessage ());
System.out.println(“MessageID: ” + messageID.toString());
// retrieving and processing stored client data
// removing client data when response generated
for (int i = 0; i < 5; i++)
{
messageData = clientData.get (–messageID);
// process message data
clientData.remove(messageID, messageData);
}
}
}
}
}
- package com. company;
import java.util.*;
public class Main
{
public static void main (String [] args)
{
Map<Integer, String> clientData = new HashMap<Integer, String> ();
long messageSize = 999999;
long requiredMemory = 2 * messageSize;
String data = “”;
String messageData;
for (long i = 0; i < messageSize; i++) data = data + ” “;
System.out.println(data. length ());
Boolean Continue = true;
Integer messageID = 0;
while(true)
{
try
{
if (Runtime.getRuntime(). freeMemory () <= requiredMemory)
throw new OutOfMemoryException
(“Insufficient memory for new client data.”);
messageData = new String ();
messageData = data; // receiving client data
clientData.put (messageID++, messageData);
// retrieving and processing stored client data
// removing client data when response generated
}
catch (Error e)
{
System.out.println(e. getMessage ());
System.out.println(“MessageID: ” + messageID.toString());
// retrieving and processing stored client data
// removing client data when response generated
for (int i = 0; i < 5; i++)
{
messageData = clientData.get (–messageID);
// process message data
clientData.remove(messageID, messageData);
}
}
}
}
}
Question 88: During various calculations in a Java program, invalid results are being generated. You suspect that one reason might be an equation that could potentially take the square root of a negative number. How might you use exceptions to catch this kind of problem?
- package com. company;
public class Main
{
public static void main (String [] args)
{
try
{
Double result = java. lang. StrictMath.sqrt(-1);
System.out.println(result);
}
catch (ArithmeticException e)
{
System.out.println(e. getMessage ());
e. printStackTrace ();
System.out.println(“Program Abended”);
System.exit(-1);
}
System.out.println(“Program Ended Normally”);
}
}
- package com. company;
public class Main
{
public static void main (String [] args)
{
Double result = java. lang. StrictMath.sqrt(-1);
System.out.println(result);
System.out.println(“Program Ended Normally”);
}
}
- package com. company;
public class Main
{
public static void main (String [] args)
{
try
{
Double result = sqrt (-1);
System.out.println(result);
}
catch (ArithmeticException e)
{
System.out.println(e. getMessage ());
e. printStackTrace ();
System.out.println(“Program Abended”);
System.exit(-1);
}
System.out.println(“Program Ended Normally”);
}
}
- package com. company;
public class Main
{
public static void main (String [] args)
{
try
{
Double result = java. lang. StrictMath.sqrt(-1);
System.out.println(result);
if (result. isNaN ()) throw
new ArithmeticException (“Cannot take square root of negative number”);
}
catch (ArithmeticException e)
{
System.out.println(e. getMessage ());
e. printStackTrace ();
System.out.println(“Program Abended”);
System.exit(-1);
}
System.out.println(“Program Ended Normally”);
}
}
Question 89: The number of nodes in a binary tree is equal to 2h+1−1, where h is the height of the tree. How would you write that as a recursive formula?
- Let h+1=n.(2(2n−1)) −1
- Let h+1=n.(2(2n)) −1,20=1
- Let h+1=n.(2(2n−1)) −1,20=1
- Let h+1=n.(2(2n+1)) −1,20=1
Question 90: Viruses spread according to the equation It=∑tj=0Nj, where I am the maximum number of people infected at time t, and N is the maximum number of people infected by each carrier. Such is the reasoning behind social distancing. Write Java and C++ programs that implement this model recursively. Test for t=3 and N=3. As time advances, report the number of people infected.
- package com. company;
import java. lang. Math;
public class Main
{
public static Double clock (Double infectedPerPerson, Double clockTime)
{
Double peopleInfected;
if (clockTime == 0)
{
peopleInfected = 1.0;
System.out.println(“Time = ” + clockTime.toString() +
” | Number of people infected = ” +
peopleInfected.toString());
}
else
{
peopleInfected = clock (infectedPerPerson, clockTime – 1.0) +
Math.pow (infectedPerPerson, clockTime);
System.out.println(“Time = ” + clockTime.toString() +
” | Number of people infected = ” +
peopleInfected.toString());
}
}
public static void main (String [] args)
{
Double infectedPerPerson = 3.0;
Double totalTime = 3.0;
Double totalInfected = clock (infectedPerPerson, totalTime);
}
}
#include <iostream>
using namespace std;
double clock (double infectedPerPerson, double clockTime)
{
double peopleInfected;
if (clockTime == 0)
{
peopleInfected = 1.0;
cout << “Time = ” << clockTime <<
” | Number of people infected = ” <<
peopleInfected << endl;
}
else
{
peopleInfected = clock (infectedPerPerson, clockTime – 1) +
pow (infectedPerPerson, clockTime);
cout << “Time = ” << clockTime <<
” | Number of people infected = ” <<
peopleInfected << endl;
}
}
int main ()
{
double infectedPerPerson = 3.0;
double totalTime = 3.0;
double totalInfected = clock (infectedPerPerson, totalTime);
return 0;
}
- package com. company;
public class Main
{
public static Double clock (Double infectedPerPerson, Double clockTime)
{
Double peopleInfected;
if (clockTime == 0)
{
peopleInfected = 1.0;
System.out.println(“Time = ” + clockTime.toString() +
” | Number of people infected = ” +
peopleInfected.toString());
}
else
{
peopleInfected = clock (infectedPerPerson, clockTime – 1.0) +
Math.pow (infectedPerPerson, clockTime);
System.out.println(“Time = ” + clockTime.toString() +
” | Number of people infected = ” +
peopleInfected.toString());
}
return peopleInfected;
}
public static void main (String [] args)
{
Double infectedPerPerson = 3.0;
Double totalTime = 3.0;
Double totalInfected = clock (infectedPerPerson, totalTime);
}
}
#include <iostream>
double clock (double infectedPerPerson, double clockTime)
{
double peopleInfected;
if (clockTime == 0)
{
peopleInfected = 1.0;
cout << “Time = ” << clockTime <<
” | Number of people infected = ” <<
peopleInfected << endl;
}
else
{
peopleInfected = clock (infectedPerPerson, clockTime – 1) +
pow (infectedPerPerson, clockTime);
cout << “Time = ” << clockTime <<
” | Number of people infected = ” <<
peopleInfected << endl;
}
return peopleInfected;
}
int main ()
{
double infectedPerPerson = 3.0;
double totalTime = 3.0;
double totalInfected = clock (infectedPerPerson, totalTime);
return 0;
}
- package com. company;
import java. lang. Math;
public class Main
{
public static Double clock (Double infectedPerPerson, Double clockTime)
{
Double peopleInfected;
if (clockTime == 0)
{
System.out.println(“Time = ” + clockTime.toString() +
” | Number of people infected = ” +
peopleInfected.toString());
peopleInfected = 1.0;
}
else
{
System.out.println(“Time = ” + clockTime.toString() +
” | Number of people infected = ” +
peopleInfected.toString());
peopleInfected = clock (infectedPerPerson, clockTime – 1.0) +
Math.pow (infectedPerPerson, clockTime);
}
return peopleInfected;
}
public static void main (String [] args)
{
Double infectedPerPerson = 3.0;
Double totalTime = 3.0;
Double totalInfected = clock (infectedPerPerson, totalTime);
}
}
#include <iostream>
using namespace std;
double clock (double infectedPerPerson, double clockTime)
{
double peopleInfected;
if (clockTime == 0)
{
cout << “Time = ” << clockTime <<
” | Number of people infected = ” <<
peopleInfected << endl;
peopleInfected = 1.0;
}
else
{
cout << “Time = ” << clockTime <<
” | Number of people infected = ” <<
peopleInfected << endl;
peopleInfected = clock (infectedPerPerson, clockTime – 1) +
pow (infectedPerPerson, clockTime);
}
return peopleInfected;
}
int main ()
{
double infectedPerPerson = 3.0;
double totalTime = 3.0;
double totalInfected = clock (infectedPerPerson, totalTime);
return 0;
}
- package com. company;
import java. lang. Math;
public class Main
{
public static Double clock (Double infectedPerPerson, Double clockTime)
{
Double peopleInfected;
if (clockTime == 0)
{
peopleInfected = 1.0;
System.out.println(“Time = ” + clockTime.toString() +
” | Number of people infected = ” +
peopleInfected.toString());
}
else
{
peopleInfected = clock (infectedPerPerson, clockTime – 1.0) +
Math.pow (infectedPerPerson, clockTime);
System.out.println(“Time = ” + clockTime.toString() +
” | Number of people infected = ” +
peopleInfected.toString());
}
return peopleInfected;
}
public static void main (String [] args)
{
Double infectedPerPerson = 3.0;
Double totalTime = 3.0;
Double totalInfected = clock (infectedPerPerson, totalTime);
}
}
#include <iostream>
using namespace std;
double clock (double infectedPerPerson, double clockTime)
{
double peopleInfected;
if (clockTime == 0)
{
peopleInfected = 1.0;
cout << “Time = ” << clockTime <<
” | Number of people infected = ” <<
peopleInfected << endl;
}
else
{
peopleInfected = clock (infectedPerPerson, clockTime – 1) +
pow (infectedPerPerson, clockTime);
cout << “Time = ” << clockTime <<
” | Number of people infected = ” <<
peopleInfected << endl;
}
return peopleInfected;
}
int main ()
{
double infectedPerPerson = 3.0;
double totalTime = 3.0;
double totalInfected = clock (infectedPerPerson, totalTime);
return 0;
}
Question 91: Merge-Sort can be implemented as a recursive process that follows this general algorithm:
MergeSort (arr [], l, r)
If r > l
1. Find the middle point to divide the array into two halves:
middle m = (l+r)/2
2. Call mergeSort for first half:
Call mergeSort (arr, l, m)
3. Call mergeSort for second half:
Call mergeSort (arr, m+1, r)
4. Merge the two halves sorted in step 2 and 3:
Call merge (arr, l, m, r)
The activity of the algorithm can be depicted as a tree of operations that takes place in steps. Consider the set of unsorted data {38, 27, 43, 3, 9, 82, 10}. Which of the following labels this tree to show the sequence of operations as the data is sorted, and puts sequence numbers between data-splits as shown?
Binary Search is known to have time complexity O(Clog10(n)). After implementation and testing, It was found that a variable was constantly redefined within a loop. Moving the definition outside the loop made the code run faster. How would the time complexity of the algorithm and its implementation be restated? C, X, and E refer to numeric constants whose values are greater than 0. n refers to the size of the data block. The value of X is less than C.
- O(C×n−−√)
- O(E×ln(n))
- O(C×log2(n))
- O((C−X) log10(n))
Question 92: What are the two basic means of organizing data for tree search?
- Rectangular array and triangular array
- Depth-first and breadth-first in an n-ary tree
- List and queue with highest and lowest at opposite ends
- Circular nodes with the largest and smallest values adjacent and sequential values linked one by one
Question 93: What is the C++ Standard Template Library composed of?
- Interfaces to public libraries of data structures and functions
- A collection of common functions that spawn threads as needed
- Insertable code modules that lend themselves easily to copy-and-paste
- Data structures and associated functionality that are a formal part of the language.
Question 94: A server that has to respond to a large number of client requests has to, as part of its activities, access a function with this timing table that compares the recursive version of the function to the explicit version. What conclusions might be drawn from this situation?
- The explicit and recursive versions provide comparable throughput; they use essentially the same code and so should be retained within the system
- Computers and their maintenance are so cheap in this modern era that a computer with appropriate memory and high-speed cpu should be purchased to replace the existing server hardware
- The explicit version provides far-better throughput, especially as data sizes grow, and since it is expensive to maintain two blocks of code that do the same thing, the recursive version should be discarded
- A study should be made of the memory utilization of the two routines before a decision is made on which one to use; typically, recursive implementations employ far less memory than explicit implementations