CIS 212 Final Exam

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the runtime complexity for inserting a node before the current first node in a linked list? a) O(n^2) b) O(1) c) O(log2n) d) O(n) e) O(n(log2n))

b

Which of the following is not a legal statement using pointers? Assume the following declarations: #include <stdlib.h> int x = 1, y = 2, z[10]; int *p, *q; a) p = &x; b) q = NULL; c) p += q; d) q = z; e) p = q;

c

How does make determine that a target is out of date with respect to a file upon which it depends? a) make does not determine that a target is out of date b) The creation date of the target is older than the creation date of the file upon which it depends c) The modification date of the target is newer than the modification date of the file upon which it depends d) The modification date of the target is older than the modification date of the file upon which it depends e) make knows nothing about dependencies between files

d

What is a sentinel when discussing a doubly-linked list? a) An indication of a broken doubly-linked list b) The tail of the list c) The head of the list d) A node that is used to represent the head and tail of the list e) A guard over the doubly-linked list

d

What is the runtime complexity for inserting an element with priority P into a priority queue constructed using a set of linked-lists? a) O(n^2) b) O(log2n) c) O(n) d) O(1) e) O(n(log2n))

--d

% is the modulus operator in C; given the program on the right hand side, what value will be printed on stdout if foo(23) is called? #include <stdio.h> void foo(int x) { int y = x; y %= 3; printf("%d\n", y); } a) 2 b) 23 c) 5 d) 0 e) 1

a

Both the for and while looping constructs support the continue statement--how does their behavior differ when encountering a continue statement? a) They do exactly the same thing--a control passes to the conditional test b) In a while loop, continue causes control to pass to the conditional test; in a for loop, continue causes control to pass to the reinitialization statement c) The while construct does not support the continue statement d) In a while loop, continue causes the loop body to be executed without checking the conditional test; in a for loop, continue causes control to pass to the conditional test e) The for construct does not support the continue statement

a

Consider the normal "less than" comparator between integers; why is it not a total order? a) It is not reflexive b) It is not transitive c) It is not a comparator d) It is not associative e) It is not idempotent

a

If you invoke the split() method on a String ADT instance, what type of return value do you receive? a) An ArrayList instance b) A C string with '\n' characters separating each of the words c) An array of char * pointers d) The String ADT does not support a split() method e) A C string with '\0' characters separating each of the words

a

What does gcc stand for? a) GNU Compiler Collection b) Generic C Compiler c) Grandiose Compilation of C d) Génial C Compilateur (it's French) e) Großartig C Compiler (it's German)

a

What does the following code do in the push() implementation for StackLong? if (! status) { size_t nbytes = (std->capacity + std->increment) * sizeof(long); long *tmp = (long *)realloc(std->theArray, nbytes); if (tmp != NULL) { status = 1; std->theArray = tmp; std->capacity += std->increment; } } a) It increases the capacity of the stack b) It increments each value in the stack by 1 c) This is illegal C code d) It computes the number of items in the stack e) It initializes each value to NULL

a

What does the following code do? const Deque *dq = Dequeue_create(); /* later in the code; after a number of insertions */ void *v; dq->removeLast(dq, &v); dq->insertFirst(dq, v); a) The tail node of the deque becomes the head node. b) The head node of the deque becomes the tail node. c) This is illegal C code d) The deque has one fewer node e) The deque has one more node

a

What does the following code do? struct node { struct node *next; char *value; }; struct node *head = NULL; /* later in the code */ struct node *new = (struct node *)malloc(sizeof(struct node)); new->value = strdup("another string"); new->next = head; head = new; a) It inserts a new node at the beginning of the linked list b) It inserts a new node at the end of the linked list c) This is illegal C code d) It creates a new linked list e) It removes the node at the beginning of the linked list.

a

What does the following function declaration mean? def euclid_distance(p1: 'list of float', p2: 'list of float') -> float: a) Given a pair of coordinates in n-dimensional space, compute the Euclidean distance between the points b) This is illegal Python c) Chooses the best value from the two lists of floats to return d) Has something to do with floats used by fishermen e) Computes the distance from the current location to Euclid, Ohio, returning the distance in km

a

What is the O() complexity for the code shown below: void bubble(int theArray[], long size) { long i, j; for (i = 0; i < size - 1; i++) for (j = 0; j < size - i - 1; j++) if (theArray[j] > theArray[j+1]) { int t = theArray[j]; theArray[j] = theArray[j+1]; theArray[j+1] = t; } } a) O(n^2) b) O(n) c) O(1) d) O(log2n) e) O(n(log2n))

a

What is the main reason for using the tar command with the -z flag? a) it enables us to collect a number of files into a single file, taking up minimum space in the single file, for sharing with other users and systems b) it enables us to create a zombie avatar for a game c) it enables us to glue two files together using the Zanzibar method d) tar is an illegal command, so it does nothing e) it converts a time specification into the military 24-hour system

a

What is the order in which the elements of a stack are visited by an iterator?a) Top to bottom b) Middle out c) Random d) Bottom to top e) Odd then even

a

Which of the following functions, defined in <stdio.h>, provides essentially the same functionality as the readline() method for the Python build-in File class? a) fgets() b) fscanf() c) fprintf() d) getc() e) sscanf()

a

Which of the following is definitely true after this code executes? const Map *m .= Map_create() /* some time later, after several put()'s */ long value; if (! m->get(m, "joe", (void **)&value)) value = 1; else value++; m->put(m, "joe", (void *)value); a) "joe" is associated with a long integer in the Map b) "joe" is associated with a string in the Map c) This is illegal C code d) "ulrich" is associated with a string in the Map e) ("joe", 1) is an entry in the Map

a

Which of the following statements is not true? a) There is exactly one implementation of an ADT defined by the header file. b) The header file for an ADT acts as a contract between the user and the implementation. c) Data elements of an ADT instance are hidden from the user. d) Methods of an ADT instance are public. e) An ADT acts like an abstract base class in object-oriented languages.

a

Which of these basic data types cannot be used in a generic Queue? a) long double b) int c) float d) long int e) double

a

How is the load factor of a hash table computed? a) number of (key, value) pairs in the table b) number of (key, value) pairs in the table / number of buckets c) number of unique keys in the table d) number of unique values in the table e) a threshold at which new code should be loaded into the processor

b

If FOO is a macro in a Makefile, how do we extract the value of FOO? a) <FOO b) $(FOO) c) !FOO d) extract(FOO) e) $FOO

b

Under which circumstances should the 2nd argument to the clear() method of a generic Queue be non-NULL? a) It should always be NULL b) Each element being enqueue'd points to heap-allocated memory c) It should always be free d) Each element being enqueue'd is the value of a basic data type e) There is no 2nd argument to the clear() method

b

What does the ## argument mean in the function signature below? int al_get(const ArrayList *al, long ndx, ##void **element##); a) void ** is a type used for passing something that is empty b) It is the address of a void * pointer in which an address will be written c) It should be int **, not void ** d) This is not a legal function signature since the ';' should be replaced by a block of statements enclosed in {}. e) It is a typographical error, and not a legal C expression.

b

What does the following code do? struct node { struct node *next; struct node *prev; void *value; } *p; p->prev->next = p->next; p->next->prev = p->prev; a) It creates a circular, doubly-linked list b) It removes the node pointed to by p from the doubly-linked list with a sentinel c) This is illegal C code d) It removes the node pointed to by p from a doubly-linked list without a sentinel e) This is an example of pointer chasing

b

What is the runtime complexity for the "big 5" methods [containsKey(), get(), put(), putUnique(), and remove()] for a Map implemented as a linked list? a) O(n^2) b) O(n) c) O(1) d) O(log2n) e) O(n(log2n))

b

What should we do if we insert an element into a linked-list priority queue with priority P and there is already an element there with priority P? a) Indicate an error, only one element with a particular priority is allowed b) Place the new element after the other element c) Place the new element before the other element d) Place the new element at the head of the list e) Place the new element at the tail of the list

b

When would a switch statement be preferred over an if...else construct? a) Never b) When one is attempting to compare the result of an expression against a set of constant values, taking different actions based upon the result. c) switch is preferred when processing textual data, if...else is preferred when processing numeric data d) There is no if...else construct in C; it is if...elif...else e) There is no switch statement in C; it is called case

b

Which aspect of Python classes allows them to be used similarly to the use of records or structs in languages like C? a) Python does not support classes b) all members of a Python class are public c) the inheritance capability of Python classes allows them to be used in this way d) Python classes cannot be used similarly to the use of record or structs in languages like C e) C's inheritance mechanism is superior to Python's, so they can be used this way only rarely

b

Which flag to gcc is required to prepare an executable image for use with gdb? a) -c b) -g c) --deb d) -l e) No special flag is required

b

Which of the following programs are not typically used to display the current contents of a file? a) more b) sort c) cat d) your chosen editor e) less

b

Which of these basic data types cannot be used in a generic Stack? a) int b) long double c) float d) long int e) double

b

Why do we use /usr/bin/time to measure the runtime for a program using progressively larger inputs? a) To determine if the processor's clock speed is optimized as the size of its input varies b) To determine how the program's running time varies as a function of the size of its inputs c) To determine if the disk optimizes its delivery of data to the program as the size of its input varies d) To determine if the operating system optimizes the file system cache as the size of its inputs varies e) To determine if the operating system optimizes the program's code as the size of its inputs varies

b

Why is the complexity for the push() method on an unbounded stack sometimes O(1) and other times O(n)? a) The code flips a coin each time push() is invoked and changes its runtime based upon heads or tails b) Because we need to visit each of the existing elements when growing the array holding the stack c) Beyond a certain number of elements on the stack, the push()implementation changes to an O(n) implementation d) The complexity is always O(1) e) A stack is a well-known schizophrenic data structure

b

Can you think of a good reason why you would use toArray() method instead of the itCreate() method to access all the elements of a stack? a) You want more experience using free(). b) Accessing through the array is O(1), whereas through an iterator it is O(n) c) You need to randomly access all of the elements of the stack d) The elements of the array are sorted. e) You don't like iterators.

c

In which directory does Linux keep programs accessed by all users? a) /etc b) /usr/local/include c) /usr/bin d) /all/access e) /share/man

c

What is the best hash function to use on strings of characters? a) Fourier transform b) Character summation c) Polynomial d) Cyclic shift e) Legendre evaluation

c

What is the order in which the elements of a Queue are visited by an iterator? a) tail to head b) middle out c) head to tail d) random e) odd then even

c

What is the runtime complexity for inserting an element with priority P into a linked-list priority queue? a) O(n^2) b) O(1) c) O(n) d) O(log2n) e) O(n(log2n))

c

Which of the following comments from valgrind indicate that your program has followed good dynamic memory hygiene? a) Conditional jump or move depends on uninitialized value(s) b) Address 0x4883893 is 0 bytes inside a block of size 17 free'd c) All heap blocks were freed--no leaks are possible d) Address 0x4883893 is 0 bytes after a block of size 16 alloc'd e) LEAK SUMMARY: definitely lost: 17 bytes in 1 blocks

c

Which of the following is not a legal method on the Python built-in File class? a) read() - reads the entire file into a string from a file opened at 'r' access b) write(string) - writes the string to a file opened at 'w' or 'a' access c) readword() - reads the next word from a file opened at 'r' access d) read(size) - reads the next 'size' characters from a file opened at 'r' access e) readline() - reads the next line from a file opened at 'r' access

c

Which of the following is not part of the ECLE cycle? a) link b) compile c) compare d) edit e) execute

c

Which of the following is not required of programs wishing to be good Linux citizens? a) If a program can take its arguments from one or more environment variables, it should process the environment variable[s] first b) If an argument starts with a single hyphen, it should process all characters that follow the hyphen as short flags c) Flags can be interspersed with filenames and other parameters d) If an argument starts with two hyphens, it should process the remainder of the argument as a long flag e) If an argument is a long flag, and the flag requires additional information, that information will be found in the same argument following an equal sign

c

Which of the following is not true for a Map? a) A Map stores (key, value) pairs b) Values can be of any type c) A comparator function for keys is required to keep the elements sorted in the Map d) Only one entry can exist in the map for each key value e) Keys can be of any type

c

Which of the following is true for a bounded stack? a) All methods except isEmpty() are O(1) complexity. b) All methods except push() are O(1) complexity. c) The constructor and all methods are O(1) complexity. d) All methods except pop() are O(1) complexity. e) All methods except clear() are O(1) complexity.

c

Which of these is not a prevalent performance function? a) f(n) = k b) f(n) = n^2 c) f(n) = sin(n) d) f(n) = n(logb)n e) f(n) = logb(n)

c

Why does a linked list not support random access? a) C does not support a syntax for random access b) The inventors of C did not feel that it was important c) The elements of the list are not adjacent in physical memory d) The overhead to support random access is too high e) Random access has no place in computer science

c

Why is the self field of an ADT instance returned by the constructor declared void *? a) It is always empty b) It is not called self, it is called this c) To prevent the user from viewing implementation details of the ADT d) A void * field is needed to align the instances structure properly in memory e) It is not declared void *, it is declared int *

c

Given the program on the right hand size, what value will be printed on stdout if foo() is called? #include <stdio.h> int x = 23; void foo(void) { int i, x = 42; for (i = 0; i < 5; i++) { int x = 3; x += 1; } printf("%d\n", x); } a) 23 b) 28 c) 47 d) 42 e) nothing will be printed, it is illegal C

d

How do the semantics of put() and putUnique() differ? a) putUnique() requires that no other pair have the same value b) They have the same semantics, putUnique() is a holdover from a different time c) put() causes multiple entries with the same key to exist in the Map, putUnique() does not d) putUnique() fails if the specified key already exists in the Map, whereas put() simple replaces the value associated with the key e) put() causes multiple entries with the same value to exist in the Map, putUnique() does not

d

How do the semantics of the destroy() method change if the 2nd parameter is not NULL? a) The semantics do not change b) The destroy() method returns a value c) The destroy() method displays the contents of the stack on stderr before the Stack data structures are destroyed d) The function specified as the 2nd parameter is applied to each element of the Stack before the Stack data structures are destroyed e) The function specified as the 2nd parameter is consulted for a list of the elements in the stack to destroy

d

What are the semantics of the clear() method required of all container ADTs? a) It eliminates any opacity associated with the container b) It asserts that the N (an argument to the method call) most recent calls should be undone c) It is requesting permission from the instance to perform a modification on the instance d) It should empty the container, leaving it in the same state as immediately after obtaining the instance from the constructor e) It indicates that the user is going to call the destroy() method soon.

d

What does this code do? N = 2 * md->capacity; array = (MEntry **)malloc(N * sizeof(MEntry *)); for (j = 0; j < N; j++) array[j] = NULL; for(i = 0; i < md->capacity; i++) { for (p = md->buckets[i]; p != NULL; p = q) { q = p->next; j = hash(p->key, N); p->next = array[j]; array[j] = p; } } free(md->buckets); md->buckets = array; md->capacity = N; md->load /= 2.0; md->changes = 0; md->increment = 1.0 / (double)N; a) Applies a new hash function to the elements in a hash table b) Clears the elements from a hash table c) This is illegal C code d) Doubles the number of buckets in a hash table e) Inverts the order of elements in a hash table

d

What is the major difference between the way C and Python manage objects created on the heap? a) Python makes copies of heap objects on the call frame stack b) C does not have a heap c) Python does not have a heap d) Python tracks references to heap objects, while C does not e) Python restricts the types of objects that can be created on the heap

d

What is the runtime complexity for inserting a node in the middle of doubly-linked list? a) O(n^2) b) O(1) c) O(n) d) O(log2n) e) O(n(log2n))

d

What must we do to a linked list to make an addition after the last node in the list be O(1)? a) Sort the list b) Nothing can be done to make it O(1) c) Nothing, it is already O(1) d) Also keep a pointer to the last node e) Invert the list

d

Which of the following characters does not have a special meaning to bash? a) | b) > c) < d) - e) ;

d

Which of the following is NOT true for a "good" hash function? a) When applied to a key, it returns a number b) When applied to keys that are equal, returns the same number for each c) When applied to keys that are unequal, it is very unlikely to return the same number for each d) When applied to a value, it determines the initial place to look for a (key, value) pair e) When applied to a key, it determines the initial place to look for a (key, value) pair

d

Which of the following is not a legal variable name in C? a) _______help_me b) Twas_brillig c) camelCase d) 9Lives e) PearlJam

d

Which of the following is not a method that can be invoked on a StackLong ADT instance? a) void(*clear)(const StackLong *st); b) int(*push)(const StackLong *st, long element); c) int(*pop)(const StackLong *st, long *element); d) int(*invert)(const StackLong *st); e) int(*isEmpty)(const StackLong *st);

d

Which of the following is true for a bounded Queue? a) All methods except isEmpty() are O(1) complexity. b) All methods except enqueue() are O(1) complexity. c) All methods except dequeue() are O(1) complexity. d) The constructor and all methods are O(1) complexity. e) All methods except clear() are O(1) complexity.

d

Which of these methods does not mutate (change) an instance of the String ADT? a) append() b) replace() c) strip() d) endsWith() e) upper()

d

Why do we use /usr/bin/time instead of the time built-in command in bash? a) The time built-in in bash prints the current date and time on stdout b) The time built-in in bash speaks the current time through your machine's speaker c) The time built-in bash is used to time runners at track meets d) /usr/bin/time performs IO redirection correctly, whereas the time built-in in bash does not e) The time built-in in bash provides access to Time Magazine

d

In a stack implemented as an array, the clear() method simply sets the next data structure member to 0L. How would the running time complexity change if it also cleared each of the previously occupied array elements? a) from O(n) to O(1) b) from O(1) to O(log n) c) from O(n) to O(log n) d) from O(log n) to O(1) e) from O(1) to O(n)

e

The ArrayList abstract data type is most similar in functionality to which Python data type? a) exception b) multi-dimensional array c) dictionary d) set e) list

e

The following code compiles and links successfully; what happens if you execute it? #include <string.h> char *buf = "12345"; int main(int argc, char *argv[]) { strcpy(buf, "1234567890"); return 0; } a) Nothing, runs just fine b) The program terminates with an IO Error exception c) The operating system crashes d) It will not compile correctly e) The program terminates with a segmentation fault

e

Under what circumstances would we need a Dequeue? a) We want the complexity of removal at the tail to be O(n) b) We are required to knock someone to the ground c) We want the complexity of removal at the tail to be O(log2n) d) We need a level surface in our back yard e) We want the complexity of removal at the tail to be O(1)

e

What do we call the pointer to the first node in a linked list? a) Headpoint b) Premier c) Conehead d) Top e) Listhead

e

What does the following code do? /* somewhere before this code is executed, const Queue *q has been successfully created by calling the constructor and one or more elements have been added to the queue */ void *v; (void)q->dequeue(q, &v); (void)q->enqueue(q, v); a) It shortens the length of the queue by 1 b) The element at the tail of the queue becomes the element at the head of the queue c) This is illegal C code d) Nothing e) The element at the head of the queue becomes the element at the tail of the queue.

e

What does the following code do? Node sentinel = {&sentinel, &sentinel, 0, NULL}; Node *p; for (p = sentinel.next; p != &sentinel; p = p->next) /*do something with p */ a) Traverse the linked list from tail to head b) Search the linked list for a particular value c) This is illegal C code d) Guard the list from predators e) Traverse the linked list from head to tail

e

What does the following command do? echo this >>my_file a) overwrites the contents of my_file with a line consisting of 'this' b) converts the arguments to speech and plays them through the speaker c) displays 'this >>my_file' in the terminal window d) echo is not a legal command, so it does nothing e) adds a line consisting of 'this' to the end of my_file

e

What does the gettimeofday() function return? a) One of these values: "time to get up", "lunch time", "nap time", "dinner time", "time to go to bed" b) The number of seconds since 12:00am on 1 January 1970 c) The system acknowledges you as a worthy individual d) The current time of day as the number of seconds and nanoseconds since a fixed time in the past e) The current time of day as the number of seconds and microseconds since a fixed time in the past

e

What is stored in the organizational array for a hash table that uses bucket hashing? a) Each element of the array contains a (key, value) pair as a struct or NULL b) Each element of the array contains an ArrayList, with element 0 being the key and element 1 being the value, or NULL c) Each element of the array is a 5-gallon bucket containing corned-beef hash d) A hash table does not have an organizational array e) Each element of the array contains a listhead pointing to a singly-linked list of nodes; each node contains a (key, value) pair that hashes to that index

e

What is the primary difference between a struct and a union in C? a) union members go on strike occasionally, while struct members do not b) C does not have the concepts of struct and union c) struct's are tougher construction, and can be used to build more complex programs d) union's are easier to assemble into large programs e) struct members are assigned their own memory cells, while all union members are assigned to the same array of memory cells

e

Which Python built-in structured type has a loose equivalence to a C data type? a) dictionary b) set c) Python does not have any built-in structured types d) bag e) list

e

Which built-in type in Python provides Map functionality? a) iterator b) class c) list d) set e) dictionary

e

Which of the following statements about a stack is not true? a) A stack is a linear data structure b) A stack supports the push() and pop() methods c) A stack conforms to the last in, first out (LIFO) discipline d) A stack can have bounded capacity e) The peek(i) method may be used to non-destructively retrieve the value i positions deep in the stack

e

Which of these statements will generate a compiler error, assuming declarations: int m, d, y; and char mon[50];? a) (void)scanf("%d/%d/%d", &m, &d, &y); b) (void)scanf("%d %s %d", &d, mon, &y); c) (void)scanf("%d.%d.%d", &y, &m, &d); d) (void)scanf("%d-%d-%d", &d, &m, &y); e) (void)scanf("%s %d, %d", &mon, &d, &y);

e

Why do we use make to build our executable programs? a) make fabricates executable programs from Python scripts b) construct is used to build our executable programs c) make generates source code from high-level directives d) make cannot be used to build our executable programs e) make determines and executes the minimum amount of work required to bring an executable program up to date

e


संबंधित स्टडी सेट्स

Microbiology Lab CE Post-Analytic Procedures

View Set

Organizace trhů a odvětví pohledem manažerů

View Set

Welding Principles and Applications 7th Chapter 2 Review Questions

View Set