CSF

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is needed to implement recursion? a) A for loop within the function to continue calling itself. b) A "base case" to terminate further function calls when a condition is met. c) An additional data structure to store data within the function. d) None of the above.

b) A "base case" to terminate further function calls when a condition is met. A recursive solution needs a minimum of two cases, a base and a recursive case. When none of the base cases are applicable, the recursive solution executes the recursive case. The recursive case is the one that calls the procedure again.

squint test

The method of squinting your eyes to gauge the quality of your code. a test you perform visually on your code to observe patterns in the code structure. If you observe your code as you squint your eyes are there any patterns in the code structure or coloring that may indicate that some refactoring is needed?

Single Responsibility Principle SRP

The practice of making sure each function or class only does one thing states that every function and class should have only one responsibility.

LIKE

Used in a WHERE clause to search for a specified pattern in a column.

What will the following query select? SELECT * FROM shipping_address NATURAL JOIN user; a) All rows and the columns that appear in both tables. b) All rows and the columns that do not appear in both tables. c) One row with a list of the columns that appear in both tables. d) Nothing, it's invalid syntax.

a) All rows and the columns that appear in both tables. NATURAL is a shorthand form of USING. It forms a USING list consisting of only the column names that appear in both input tables. These columns appear only once in the output table.

Which of the following is not a valid type of join? a) BETWEEN JOIN b) INNER JOIN c) RIGHT JOIN d) OUTER JOIN

a) BETWEEN JOIN Valid types of JOINS include: INNER, RIGHT, LEFT, OUTER, NATURAL, CROSS, and SELF JOINS.

Is a base case required to write a recursive algorithm? a) No, the base case is only suggested and not b) Yes, if there is no base case, the algorithm will continue to run forever. c) No, the base case is only required if there is more than one exit to the algorithm. d) Yes, but multiple base cases must be defined.

b) Yes, if there is no base case, the algorithm will continue to run forever. A base case is required in order to write a recursive algorithm. It doesn't matter how many there are, although there are usually just one or two. If there is no base case defined, the algorithm will keep calling itself over and over with no exit.

Which of the following is a characteristic of a queue? a) a data structure that can only contain numbers b) the first item inserted is the first to be removed c) the last item is pushed onto the top and also removed from the top. d) none of the above

b) the first item inserted is the first to be removed The queue data structure uses the FIFO priority. Therefore, items inserted first will also be removed first.

Suppose we no longer need the customers table below. What is the correct way to delete the entire table? customer_id first_name last_name 00001 Shinichi Mochizuki 00002 Pierre Fermat 00003 Vesselin Dimitrov a) ALTER TABLE customers DROP COLUMN customer_id; b) TRUNCATE TABLE customers; c) DROP TABLE customers; d) DELETE ALL;

c) DROP TABLE customers; The SQL DROP TABLE statement is used to remove a table definition and all the data for that table. Using this command destroys all the information available in the table forever. We use the TRUNCATE TABLE statement to delete the data inside a table but not the table itself. The ALTER TABLE DROP COLUMN statement deletes only a specific column in a table. DELETE ALL does not exist.

Referring to the relational schema below, which query will return the serial_number and model of any computer that has not been purchased? computer(serial_number, manufacturer, model, color) purchase(serial_number, ssn) person(ssn, first_name, last_name, address) a) SELECT * FROM computer; b) SELECT c.serial_number, c.model FROM computer c; c) SELECT c.serial_number, c.model FROM computer c LEFT JOIN purchase p ON p.serial_number = c.serial_number WHERE p.ssn IS NULL; d) SELECT c.serial_number, c.manufacturer FROM computer c, purchase p WHERE c.serial_number = p.serial_number;

c) SELECT c.serial_number, c.model FROM computer c LEFT JOIN purchase p ON p.serial_number = c.serial_number WHERE p.ssn IS NULL; The first step is to select serial_number and model from the computer table. Start with SELECT c.serial_number, c.model FROM computer c. Next, we need a JOIN to see if the computer has been purchased. LEFT JOIN purchase p ON p.serial_number = c.serial_number will match computers with their purchases if they have been purchased. If they have not been purchased, the columns from purchase will be NULL, which is where the WHERE p.ssn IS NULL comes in. If the ssn from purchase is NULL, no one has purchased the computer.

Which of the following statements is false: a) classes belong to object-oriented languages b) classes are a type of data structure c) data structures must be implemented using classes d) all of the above

c) data structures must be implemented using classes Although classes are a type of data structure, they are not necessary. Classes belong to object-oriented languages. Although not all languages are object-oriented, most are still able to support the creation of abstract data structures.

Which of the following is a difference between a primary key and a foreign key? a) A primary key can be null, while a foreign key cannot. b) A primary key can be a duplicate, while a foreign key must always be unique. c) A primary key must always be unique, while a foreign key can be a duplicate. d) None of the above.

c) A primary key must always be unique, while a foreign key can be a duplicate. One main difference between a primary key and a foreign key is that a foreign key can be a duplicate, while a primary key must always be unique. We do not have to explicitly define a primary key as UNIQUE.

How is data added to and removed from a stack? a) Data is stored in the order it is added and can be removed from anywhere. b) Data is added to one side and removed from the other. c) Data is stored in an undefined order and can be removed from either side. d) Data is added and removed from the same side.

d) Data is added and removed from the same side. Stacks implement a LIFO (last-in, first-out) order, which means the most recently added (pushed) item on the stack will be the first item retrieved (popped). So, when you add the numbers 1, 2, and 3 to the right side of a stack in that order, you get the structure like [1,2,3]. For the stack to be LIFO, the items should be retrieved in the order 3, 2, and 1. That means items must be removed from the right side.

schema

a collection of logical structures of data. The schema is owned by a database user and has the same name as the database user.

map

a data structure that holds a collection of key/value pairs. each key can only exist once in a map.

hash code

a deterministic value resulting from calling a hashing function on arbitrary data.

What best describes recursion? a) A procedure (i.e., a function) that calls itself. b) A piece of code that uses a "for" or "while" loop. c) A technique used to search data structures. d) None of the above.

a) A procedure (i.e., a function) that calls itself. Recursion is a technique in which a procedure (i.e., a function) calls itself with parameters incrementally moving toward one of the base cases.

Why are data types required? a) They optimize performance. b) They optimize storage. c) They provide consistent formatting within columns of a database. d) All of the above.

d) All of the above Data types are important because they store data in the database in a consistent format. Knowing the data type that is used in a particular column allows for the optimization of calculations and operations done on that column. Data types also affect storage and performance of the database so it is important to consider which data types are best for a given situation. Some commonly used data types are: INT, VARCHAR, DATETIME, DECIMAL, FLOAT, and B

Which of the following are valid comparison operators? a) > b) LIKE c) != d) All of the above.

d) All of the above. Comparison operators are used to compare values in relation to each other. The > operator checks of the first operand to the left of the ">" is greater than the second operand to the right. The LIKE operator is used with the wildcard * symbol to compare for matching values. The != operator checks if two values are not equal to each other.

Which of the following are algorithms commonly implemented using recursion? a) Factorial operations. b) Quicksort. c) Binary search. d) All of the above.

d) All of the above. Recursion is used in many popular algorithms, especially searching and sorting algorithms. Some mathematical operations, such as the factorial operation and the Fibonacci sequence, are defined recursively and thus can be easily implemented as recursive functions.

Given a sorted collection of a million items, which algorithm would you choose between linear search and binary search? Explain your reasoning

i would choose binary because it would be faster and cost less

Given an unsorted collection of a million items, which algorithm would you choose between linear search and binary search? Explain your reasoning.

i would choose linear because binary searches need a sorted collection

What is a real-life scenario that uses binary search?

looking through a list of contacts in my phone. I'll scroll to the letter I need then search through the names in that letter sorted alphabetically.

Hash Table Steps

1. take the key 2. convert the key to a hash code using a hashing function 3. mod the hash code to get an array index 4. store the value in the array index

Query

A request for data or information from a database.

recursive function in pseudocode

FUNCTION recursiveProcedure IF base case 1 THEN Handle case 1 ELSE IF base case 2 THEN Handle case 2 ... ELSE CALL recursiveProcedure END IF END FUNCTION

SQL

Structured Query Language. SQL is used to communicate with a database.

Self-Documenting Code

The method of writing readable, maintainable code that does not need comments to be understood.

Clean Code

The philosophy behind writing maintainable and readable code

key/value pair

a piece of data paired with a key

what is an algorithm?

a sequence of steps taken to yield a result in a set amount of time.

how to determine time complexity

add up how many instructions the algorithm will execute as a function of the size of its input, then simplify the expression to largest term and drop any constants.

Key

an identifier for a piece of data

BFS

breadth-first search - An algorithm for traversing or searching tree or graph data structures. Start at the tree root and explore the neighbor nodes first, before moving to the next level neighbors. -searches an entire row of Nodes before moving to the next.

What is runtime? a) The physical time duration of an algorithm. b) A function that estimates the time it takes for an algorithm to run. c) Both of these. d) Neither of these.

c) Both of these. Runtime can be the physical time duration of an algorithm, or it can be a function that estimates the time it takes for an algorithm to run, also known as time complexity.

Which of the following is not a valid logical operator in SQL? a) OR b) NOT c) LIKE d) AND

c) LIKE The valid logical operators are AND, OR and NOT whereas LIKE is a comparison operator. AND and OR can be conditions chained together, and NOT is for negating them.

What is the correct way to run a SQL command from a file? a) postgres -f=FILENAME b) pg --file=FILENAME c) postgres --file=FILENAME d) postgres_exec FILENAME

c) postgres --file=FILENAME The postgres command can execute a file as if you had typed the SQL into its console directly. You can specify the file to execute using postgres --file=FILENAME. If you want to use the shorthand flag, type postgres -f FILENAME. Notice the single dash - before the flag and a space instead of an equals sign between it and the filename.

runtime

can refer to the physical time duration of an algorithm but is often used synonymously with time complexity

What is time complexity? a) The number of loops that an algorithm contains. b) The method of finding an algorithm's efficiency. c) The physical time duration of an algorithm. d) A function that estimates the time an algorithm takes to run.

d) A function that estimates the time an algorithm takes to run. We write time complexity as a function which approximates the time duration of an algorithm given an input of size n. This way, the behavior of the function can be determined when given a close to infinite input.

How is a hash table different than an array? a) A hash table stores its data in consecutive order while an array chooses specific locations in which to place its data. b) A hash table cannot have numeric keys like an array has numeric indices. c) A hash table has string keys while an array has numeric indices. d) A hash table holds key/value pairs while an array only holds values.

d) A hash table holds key/value pairs while an array only holds values. Hash tables hold key/value pairs, applying a hashing function to the key to determine where in an internal array to store the pair. While keys are commonly strings, they can be of any type, including numeric values.

Which of the following is true about the = operator? a) It checks the values on either side of it for equality. b) It works on numbers and strings. c) It is case sensitive. d) All of the above

d) All of the above SQL uses a single = symbol to mean equal to instead of ==. = can be used on both strings and numbers. In the case of strings, both the case and characters need to be the same for two strings to be equal; in other words, "Numero uno" does not equal "NuMerO Uno".

What are common tradeoffs between iterative and recursive solutions? a) Recursive solutions can often be more straightforward. b) Iterative solutions have better performance. c) Recursive solutions are more subject to system limitations. d) All of the above.

d) All of the above. Recursive solutions tend to be cleaner and more straightforward than iterative approaches. Recursion tends to perform more slow as it depends on system resources to keep track of repeated function calls in memory.

Which of these is not a step in a binary search? a) Looping until the item is found or low point becomes higher than the high point. b) Checking if the item is less than the high value. c) Setting a new low, mid, and high point. d) Checking if the item is less than the low value.

d) Checking if the item is less than the low value. The comparison against the low value should be greater than, not less than. The item being searched for should always be between the high and low value.

Which of the following does not require a data structure? a) Keeping track of incoming HTTP requests. b) Displaying a news feed. c) Creating an easily searchable list of inventory items. d) None of the above.

d) None of the above. Each of the tasks listed above requires a data structure of some kind. Incoming HTTP requests can be stored in a queue, and inventory items can be stored in a hash table keyed by their serial number. And while rendering a news feed may not require a data structure, the data for that news feed must be stored somewhere such as an array.

If an algorithm has linear growth does it: a) Always takes the same amount of time to run. b) Increase in runtime quickly for small input and taper off. c) Continue to increase at runtime faster than the input size increases. d) None of the above.

d) None of the above. The three answers described here are constant, logarithmic, and quadratic (or possibly exponential) time. Linear growth implies that the runtime grows in direct relation to the size of the input.

What are some ideal application for stacks and queues? a) a queue can be used to in a program to keep track of customers' orders. b) a stack can be used to store a program's function calls in a computer's memory. c) a queue can be used by a server to maintain pending jobs in order d) all of the above

d) all of the above All of the above are ideal applications for stacks and queues. A queue is ideal for any application where there is a need to preserve the ordering of the data. A stack is ideal for any application where the latest piece of data or code snippet is needed first. Once used, the data or code is no longer needed and therefore "popped" off.

Which of the following are necessary to build a linked list? a) a head node that reference the first node in the list b)a reference for each node that points to the next node. c) the data contained in each node d) all of the above

d) all of the above To build a linked list, create a reference to the first node in the list, also known as the head. Each node in the list will contain a piece of data as well as a reference that points to the next node in the list.

Node

data structure consisting of a value and the ability to point to other adjacent members.

FIFO

first in first out - the first element processed is the first to leave

LIFO

last in, first out - the last element is the first to leave

Leaf nodes

nodes without children

binary search tree

orders each node in the tree based on some quantifiable value. nodes increase in value as we travel right and decrease in value towards the left

Aliasing

technique of abbreviation in SQL when using joins

time complexity

the metric used to describe the efficiency of an algorithm. expressed as a function that estimates the time it take to execute a program. we assume the input is infinite when estimating so we know the worst case

why are algorithms important?

used to determine the most efficient solution to a problem. enable a programmer to solve problems efficiently so that programs are fast an accurate.

Which of the following is not a valid SELECT statement? a) SELECT column_name FROM table_name; b) SELECT * FROM table_name; c) SELECT DISTINCT column_name FROM table_name; d) SELECT ONLY column_name FROM table_name;

d) SELECT ONLY column_name FROM table_name; SELECT column_name FROM table_name; will select a specific column from a table and is a valid SQL query. SELECT * FROM table_name will select all the columns from a table and is a valid SQL query. SELECT DISTINCT column_name FROM table_name will select only distinct columns from a table and is a valid SQL query. This type of SELECT statement can be helpful when a column has entries that contain identical values. SELECT ONLY column_name FROM table_name is an invalid SQL query.

Which of the following is the correct syntax used to run a SQL query for a column in a table? a) FROM table_name SELECT column_name; b) RETRIEVE column_name FROM table_name; c) IF(column_name = table_name) SELECT column_name; d) SELECT column_name FROM table_name;

d) SELECT column_name FROM table_name; To retrieve data from a table, send a query to the table. Use an SQL SELECT statement to do this. The statement consists of a select list, a table list, and optionally, any qualifications to specify restrictions on the data. The select list lists all the columns we want to return, for example, SELECT column_one, column_two. A table list lists the tables from which to retrieve the data, for example, FROM table_one, table_two.

When evaluating three different functions, you have found that one function has n + 1 instructions, a second has 2n instructions, and a third has n log n instructions. List the functions in order of efficiency. a) Both the n + 1 and 2n functions are equally efficient, and the n log n function is less efficient. b) The n log n function is the most efficient and both the n + 1 and 2n functions are equally but less efficient. c) The function with n + 1 instructions is the most efficient, followed by 2n, and n log n is last. d) The linear function with n + 1 instructions is the most efficient, followed by n log n, and the 2n function is last.

a) Both the n + 1 and 2n functions are equally efficient, and the n log n function is less efficient. The constants represented by n + 1 and 2n do not matter when considering the overall efficiency of the algorithm. They both have linear growth and have equal time complexity, thus they are equally efficient. Log-linear (n log n) time is slower than linear.

What is the primary purpose of hashing? a) Converting arbitrary data into a fixed-length data. b) Generating the index for a key/value pair in a hash table. c) Converting strings to numeric hash codes. d) Finding a value in a hash table.

a) Converting arbitrary data into a fixed-length data. While b and d require a hashing function to accomplish the task, they are not the primary purpose of a hashing function. And while hashing functions can be used to convert strings to numbers, they can do much more than that. A hashing function can take any kind of data, and the resulting hash code can be interpreted in many ways (as a number, for example). The main feature of the resulting hash code is that it is the same bit-length for any data sent into it.

What SQL command is used to delete a database table? a) DROP TABLE b) REMOVE TABLE c) DESTROY TABLE d) DEL TABLE

a) DROP TABLE To delete a table and all of its data, use the DROP TABLE command. All data from that table is permanently lost.

What is the fundamental difference between Merge Sort and Quick Sort? a) Quicksort uses a pivot value to partition the array, and merge sort simply splits the array in half. b) Quicksort builds a max heap to sort the data, and merge sort uses a pivot value to partition the array. c) Quicksort uses a pivot value to partition the array, and merge sort builds a max heap to sort the data. d) Quicksort builds a maximum heap to sort the data, and merge sort simply splits the array in half.

a) Quicksort uses a pivot value to partition the array, and merge sort simply splits the array in half. Quicksort's main feature is to pick a partition value and then organize the groupings on either side of the partition, and perform this recursively on either side of the partition until it is sorted. A merge sort splits the array objectively in the middle recursively until there is only one item in each group, and then merges each group until the entire array is rebuilt.

Which of the following is the correct syntax to query a customers table for customers with the last name "Smith"? a) SELECT * FROM customers WHERE last_name = 'Smith'; b) SELECT * FROM customers WHERE last_name == 'Smith'; c) SELECT * FROM customers WHERE last_name === 'Smith'; d) SELECT * FROM customers WHERE last_name LIKE 'Smith';

a) SELECT * FROM customers WHERE last_name = 'Smith'; In contrast to many programming languages, SQL uses a single = symbol to mean equal to instead of ==. In the query above, the = is used to query the Customers table for customers with the last name equivalent to "Smith." The = symbol may also be used to check the equality of other data types, for instance, numbers. Whenever we check for equality between strings, we must use quotes.

Which query selects ALL fields from the customers table? a) SELECT * FROM customers; b) SELECT first_name FROM customers; c) SELECT customer_id, first_name FROM customers; d) SELECT ALL FROM customers;

a) SELECT * FROM customers; The SELECT clause has a special operator, *, that returns ALL of the columns from the table (or set of tables) being queried. If a WHERE clause is included, the resulting set only returns the rows that satisfy the specified conditions.

Which of the following are valid keywords in a basic select statement? a) SELECT, FROM, and WHERE b) SELECT, EXTRACT, FROM c) SELECT, GET, FROM, and WHERE d) SELECT, IN

a) SELECT, FROM, and WHERE In addition to the SELECT keyword, the statement must also contain the FROM keyword to specify the table or set of tables from which to retrieve data. Select statements may also contain optional clauses such as WHERE, GROUP BY, HAVING, etc.

Which of these do we consider when estimating time complexity? a) The worst-case scenario. b) The average scenario. c) The best case scenario. d) All scenarios.

a) The worst-case scenario. When estimating the time complexity, we take a look at how the algorithm performs as the input grows very large. Also, we must consider what happens if the item is the last in a list. For instance, in a search we assume that the item is found last and not first.

Can you perform a linear search on an unordered list? a) Yes, and the efficiency stays the same. b) Yes, and the efficiency decreases. c) Yes, and the efficiency increases. d) No, to perform a linear search the items must be sorted.

a) Yes, and the efficiency stays the same. The efficiency of a linear search does not change if the items are sorted or unsorted, but it is preferable to use unsorted collections if there is no predictable way to find the item.

What is a stack? a) a data structure that implements LIFO priority b) a data structure that implements FIFO priority c) a data structure with elements that can be accessed by index d) a data structure with elements that can be accessed by pointers

a) a data structure that implements LIFO priority The stack data structure implements a LIFO priority collection. It provides two functions: push and pop. push adds an element to the top of the stack, and pop removes the top-most element.

Which of the following is an example of a data structure that can be used to store a collection of names? a) array b) string c) number d)all of the above

a) array Arrays are used to store data in a sequence, one element after another. By combining the location of the data and the ability to recover any element by using an index, the array simplifies access to and manipulation of ordered elements. Arrays are a good choice for collections of simple data types such as strings, numbers, etc.

Which kind of sort is the most efficient? a) Bubble sort. b) Merge sort. c) Insertion sort. d) Selection sort.

b) Merge sort Merge sort is the only sort on the list that significantly improves upon other searches. All of the other searches require going through the collection many times to make sure it ends up sorted, and merge sort can minimize that by its divide and conquer nature.

Which of the following is NOT a valid PostgreSQL command? a) generate b) createdb c) dropdb d) psql

a) generate To create a new database, use the command createdb database_name where database_name is the name chosen for the specific database being built. Database names must have an alphabetic first character. If the database is no longer needed, it can be removed with the command dropdb database_name. This will physically remove all the files associated with the database and cannot be reversed. psql database_name will run the PostgreSQL interactive terminal program, which allows users to edit, enter, and execute SQL commands. generate is not a valid command and will throw an error.

What is an ideal scenario for using a linked list? a) when the number of elements is unknown and expected to grow or shrink b) when the number of elements is known and not expected to change dramatically c) when there are only a few elements to store d) none of the above

a) when the number of elements is unknown and expected to grow or shrink Linked lists are ideal data structures for storing data when we do not know the expected size of the data. Nodes can be added or removed dynamically. Since each node is independent in memory, the operating system may efficiently use any available memory location to store it. Linked lists may grow to immense sizes, as opposed to an array, in which elements would need to be rearranged to make room for new data.

What is a real-life scenario that uses linear search?

any time you are looking through something one by one, like when I'm looking for a book on my shelf which isn't in sorted order.

Which of these statements does not describe an algorithm? a) An algorithm is a sequence of steps. b) An algorithm must be efficient. c) An algorithm must complete in a finite amount of time. d) An algorithm is a solution for a specific task.

b) An algorithm must be efficient. An algorithm is a sequence of logical steps designed to complete a particular task in a finite amount of time. It doesn't matter if an algorithm is slow or inefficient as long as it still abides by the other three properties.

What is the time complexity of the following algorithm? FUNCTION FindSmallFactors(n) FOR i in 2 to 7 IF n / i has no remainder THEN PRINT i + " is a factor of " + n END IF END FOR END FUNCTION a) Linear b) Constant c) Logarithmic d) Quadratic

b) Constant Even though this algorithm contains a loop, which often indicates linear growth, the loop itself is not dependent on the input and only runs a set amount of instructions.

Order the following time complexities from the most efficient to the least efficient: quadratic, exponential, linear, constant, logarithmic, and log-linear. a) Constant, logarithmic, log-linear, linear, exponential, quadratic. b) Constant, logarithmic, linear, log-linear, quadratic, exponential. c) Constant, log-linear, linear, logarithmic, quadratic, exponential. d) Constant, logarithmic, log-linear, linear, exponential, quadratic.

b) Constant, logarithmic, linear, log-linear, quadratic, exponential. An algorithm that has constant growth always takes the same amount of time to run. The other types grow as a function of n, the input. For logarithmic, it's log n, for linear its n, and for log-linear, it's n log n. Quadratic is n^2, and exponential is 2^n. If you graph these functions, you will see that logarithmic time complexity grows the slowest, then linear, etc., which indicates the order of efficiency.

Describe a singly-linked list regarding graph properties. a) Directed, unweighted, and cyclic b) Directed, unweighted, and acyclic c)Undirected, unweighted, and acyclic d)Directed, weighted, and, acyclic

b) Directed, unweighted, and acyclic Any kind of linked list is unweighted. Singly-linked lists only allow traveling to the next node, so it is directed. And unlike circularly-linked lists, the tail of a singly-linked list does not travel back to the head making it an acyclic graph.

How does a binary search operate? a) It uses a set of keys that are used to find the target item. b) It uses a divide and conquer approach to find the item it is searching for in a sorted list. c) It iterates through sorted or unsorted list until it finds the target item. d) None of the above.

b) It uses a divide and conquer approach to find the item it is searching for in a sorted list. The binary search algorithm uses a divide and conquer methodology to find what it's searching for in a collection. It only functions properly on a pre-sorted collection.

Which control flow techniques (e.g., for loops, while loops) would most likely be used to implement selection sort? a) A single FOR loop to iterate through the collection and select the correct next item. b) Nested FOR loops to iterate through the collection and select the correct next item. c) A single FOR loop with IF statements to select the correct next item. d) A WHILE loop to iterate through the collection and select the correct next item.

b) Nested FOR loops to iterate through the collection and select the correct next item. Selection sort requires nested for loops to perform the sort. For each place in the array, it goes through the collection to select the lowest item, so both loops are needed.

What does RDBMS stand for? a) Relational Database Monitoring System b) Relational Database Management System c) Realtime Data Marketing System d) Realtime Dynamic Backend Management System

b) Relational Database Management System RDBMS stands for Relational Database Management System. It is the basis for SQL and many modern database systems such as Microsoft SQL Server and MySQL. The data in an RDBMS is stored in tables, which are a collection of related data entries consisting of columns and rows.

Given a table named users with the columns id, name, and email, how would you query the database to get the information for the user with an ID of 3? a) FETCH id, name, email FROM users WHERE id = 3 b) SELECT id, name, email FROM users WHERE id = 3 correct c) SELECT users.* WHERE id = 3 d) SEL * WHERE users.id = 3

b) SELECT id, name, email FROM users WHERE id = 3 correct To retrieve data from a table, a query is made using an SQL SELECT statement. The statement consists of a select list, a table list, and optionally, any qualifications to specify restrictions on the data. A select list lists all the columns to be returned, for example, SELECT column_one, column_two. A table list lists the tables from which to retrieve the data, for example, FROM table_one, table_two.

Which algorithm uses a heuristic? a) Dijkstra's algorithm for finding the shortest path between two nodes. b) The nearest neighbor solution to the traveling salesman problem. c) A binary search used for locating a specific value in a sorted collection. d) A merge sort used for sorting items in a collection.

b) The nearest neighbor solution to the traveling salesman problem. A heuristic is a best guess at a solution rather than a proven solution. Dijkstra's algorithm, binary search, and merge sort will all give you the exact result you are looking for every time. The nearest neighbor result, however, will vary in terms of how close to the shortest circuit it finds depending on the data given.

Given the table below, what movies would the following query select? SELECT title FROM movies WHERE year > 1970 AND year < 1980 id title year 10103 Willy Wonka & the Chocolate Factory 1971 11049 The Breakfast Club 1985 13877 A New Hope 1977 14327 E.T. the Extra-Terrestrial 1982 15492 The Empire Strikes Back 1980 a) The Breakfast Club, E.T. the Extra-Terrestrial, The Empire Strikes Back. b) Willy Wonka & the Chocolate Factory, A New Hope. c) Willy Wonka & the Chocolate Factory, A New Hope, The Empire Strikes Back. d) All of the movies.

b) Willy Wonka & the Chocolate Factory, A New Hope. SQL contains logical operators for combining or negating conditions. We use AND to combine required filters, OR when just of them is required, and NOT to find columns that don't match the condition. Conditions can be chained together and grouped using parentheses.

Is runtime the same as time complexity? a) Yes, but it can also refer to the number of instructions in an algorithm. b) Yes, but it can also refer to the physical time duration of an algorithm. c) No, it is only the physical time duration of an algorithm. d) No, it is only the number of instructions in an 'algorithm.

b) Yes, but it can also refer to the physical time duration of an algorithm. We often use time complexity and runtime interchangeably. However, the runtime can also refer to the physical duration a particular algorithm takes to run at a given time.

comparing arrays to linked lists, which of the following statements are false? a) array elements can be accessed by index, but linked lists elements cannot b) both array and linked lists entries exist in consecutive memory locations c) linked lists elements may exist anywhere in physical memory d) none of the above

b) both array and linked lists entries exist in consecutive memory locations In contrast to arrays, elements in linked lists are not stored consecutively in memory. Therefore we must start from the beginning of the linked list and search through each element until we find the element we are looking for.

How do you find an item in a linked list? a) Use a hashing function to find the index of the item. b) Starting with the head, check each node following its next until the item is found or the tail is reached. c) Check each item in the list randomly until all the items have been checked. d) Loop through a range of numbers from 0 through the length of the list, using each number as an index to check for the item.

b) startingw ith the head, check each node following its next until the item is found or the tail is reached A linked list is a chain of nodes connected using next properties. The first node in a linked list is called the head, and the last node is called the tail. To traverse the list, you start at head and follow each next property to find the next node all the way to the tail at the end.

Which one of the following does not describe a queue? a) A group of people waiting to go through a security scanner. b) Packaging materials coming off of a conveyor belt. c) A fulfillment system favoring the newest orders first. d) They all describe queues.

c) A fulfillment system favoring the newest orders first. A fulfillment system favoring the newest orders is not a queue, as the last orders to enter (the newest ones) are the first to leave. That describes LIFO ordering (a stack), not FIFO ordering (a queue).

Which of the following analogies best resembles a stack data structure? a) an apartment mailbox consisting of a row of individual mailboxes b) a line of customers at a grocery store c) a pile of plates at a buffet table d) none of the above

c) a pile of plates at a buffet table A pile of plates at a buffet table resembles the stack in its LIFO ordering. Plates that are stacked last are the first to be removed.

Which of the following describes information best kept in a data structure? a) An online vehicle listing. b) An employee performance review. c) A list of applicants for a job opening. d) The primary and secondary emergency contacts for a patient.

c) A list of applicants for a job opening. Data structures are best used to hold a variable amount of similarly grouped data, such as a list of one's followers on social media. Neither a vehicle listing or a performance review contains such data; each datum held describes a distinct part of the element so classes are more appropriate to model them. And while there is more than one emergency contact, there is a low, finite number of them, making it simpler to hold each datum as a property in a class. The list of applicants is the only information that needs to be kept in a data structure.

In what way might the choice of algorithm make a difference? a) One solution may be more efficient than another. b) One solution may apply to other scenarios more easily. c) Both of these. d) Neither of these.

c) Both of these. All algorithms are not equally fast or useful. There are multiple solutions to most problems, and one algorithm may run faster on a regular basis. In other cases, one algorithm may be applied to multiple situations, like the bow tie example, in which the bow, in addition to the shoelace, may be appropriate to wrap a gift but a surgeon's knot would not be. If a solution may need to be more broadly applied, one algorithm may be more suited to the task than another.

Which of the following is a valid example of how to create a database table? a) create_table albums: id integer, title text, price numeric(5, 2) b) CREATE TABLE albums ( id, title, price ); c) CREATE TABLE albums ( id integer, title text, price numeric(5, 2) ); d) ```sql CREATE(TABLE, 'albums) { id integer, title text, price numeric(5, 2) };

c) CREATE TABLE albums ( id integer, title text, price numeric(5, 2) ); Use the CREATE TABLE statement to add a table to the database. It requires you to specify the name of the table (albums in this example) along with a list of all columns and their data type (integer, text, etc.). This example shows three data types, but there are more data types available.

What is not part of determining the time complexity of an algorithm? a) The size of the input. b) Considering the worst case scenario. c) Counting the number of parameters a function takes. d) Counting the number of instructions in the algorithm.

c) Counting the number of parameters a function takes. The number of parameters doesn't matter when considering the time complexity of an algorithm. Even if there is more than one parameter, complexity is only concerned with how the function acts as all parameters become infinitely large.

How does a linear search operate? a) It searches iteratively only on sorted collections. b) It uses recursion to continuously call a search function until it finds the target item. c) It iterates over each item in a collection until it finds the target item d) None of the above.

c) It iterates over each item in a collection until it finds the target item The linear search algorithm uses a loop to iterate over each item in a collection until it finds the target item. The collection may or may not be sorted.

How are linked lists stored in memory? a) Nodes are placed in reverse order forming a LIFO structure. b) Nodes are placed at constant intervals (i.e., every third chunk of memory). c) Nodes are spread out in memory in whichever spot is open at the time we create the node. d) Nodes are placed end-to-end consecutively in one large line of memory.

c) Nodes are spread out in memory in whichever spot is open at the time we create the node. Linked lists are collections of nodes linked together by the properties of each node. Since each node is a distinct object, where it exists in memory depends solely on where the OS decides to put it and is not dependent on the location of other nodes.

Which of the options below is not a benefit of using iteration over recursion? a) Efficiency. b) Better use of computer resources. c) Simplicity and ease of understanding. d) There is never a benefit to using recursion.

c) Simplicity and ease of understanding. Some algorithms are very hard to visualize iteratively, but can be made much simpler by thinking about the base cases and writing them recursively. Recursive algorithms use more resources but are sometimes much easier to read.

What is the purpose of the psql command? a) To start and stop the Postgres database. b) To check a SQL file for errors. c) To open an interactive interface for executing SQL commands. d) It is an alias for the postgres command.

c) To open an interactive interface for executing SQL commands. Postgres provides an interactive command line interface for executing SQL code called psql. You can use psql to execute SQL files and enter SQL commands directly. psql is launched by typing psql from the command line and hitting enter.

Which of the following would be an ideal scenario in which to use recursion? a) To loop through an array to find the maximum value. b) To search for patterns in a string and perform string manipulation. c) To perform a search through a tree data structure. d) None of the above.

c) To perform a search through a tree data structure. A search algorithm to find an item in a tree data structure would be a natural scenario in which to apply recursion. When an algorithm can be defined as a combination of sub-results starting with known cases, a recursive solution makes the most sense.

Which of the following is a valid SQL data type? a) STRING b) LIST c) VARCHAR d) STACK

c) VARCHAR VARCHAR is a data type that represents a character string of variable length, with maximum length n. You can also declare it as CHARACTER VARYING. CHARACTER is also a valid data type in SQL but represents a character string of fixed length n. Meanwhile, STRING, LIST, and STACK are invalid data types in SQL.

What is the correct syntax for filtering a column that equals the strings A or B? a) WHERE column_name = "A" OR "B" b) WHERE column_name = "A" || column_name = "B" c) WHERE column_name = "A" OR column_name = "B" d) WHERE column_name = OR("A", "B")

c) WHERE column_name = "A" OR column_name = "B" In SQL, use the OR operator between two filters to select rows that match any of the given criteria. Contrasting that is the AND operator which dictates that for the row to be matched it must satisfy all of the criteria.

When is a binary search more efficient than a linear search? a) In all cases b) When the array is not sorted c) When the array is sorted d) Never

c) When the array is sorted A binary search requires a sorted array, but the search is much faster than a linear search. If the array is unsorted, we cannot use binary search.

What is the correct syntax for adding records to a database? a) CREATE (value_1, value_2) INTO table_name; b) ADD INTO table_name VALUES (value_1, value_2); c) INSERT VALUES (value_1, value_2) INTO table_name (column_1, column_2); d) INSERT INTO table_name (column_1, column_2) VALUES (value_1, value_2);

d) INSERT INTO table_name (column_1, column_2) VALUES (value_1, value_2); Create new records in a table by using the INSERT INTO statement, which requires at least the name of the table and the data you want to add. There is an option to specify column names, and if you don't Postgres will assume you are inserting data for each column and in the same order that the columns appear in the table.

What does the UPDATE command do? a) It allows you to update a database's metadata. b) It's used to change the name of a table. c) It adds a record to an existing table. d) It allows you to change the values for one or more columns in a table.

d) It allows you to change the values for one or more columns in a table. The UPDATE command allows you to change the data in a table. When used in conjunction with SET and WHERE you can change one or more columns in one or more rows at a time.

Referring to the listed tables, what does the following query return? SELECT first_name, last_name FROM customers JOIN transactions ON customers.id = transactions.customer_id WHERE transactions.cost > 50; customers: id first_name last_name 00001 Jane Smith 00002 Bob Adams 00003 Mike Johnson 00004 Jenn Nelson transactions: id customer_id cost date 00122 00001 $100.00 07-10-2017 00092 00001 $24.00 04-19-2015 00103 00003 $25.00 07-10-2017 00004 00002 $75.00 03-18-2017 a) The records: "Jane, Smith" and "Jenn, Nelson." b) The records: "Jane, Smith," "Jenn, Nelson," and "Bob Adams." c) The records: "00001, Jane, Smith" and "00004, Jenn, Nelson." d) None of the above.

d) None of the above. This SQL statement joins the customers and transactions tables together by matching the customer_id field in the transactions table to the id field in the customers table. For every matching customer_id in the transactions table, the first and last names of those customers return if they have a transaction with a cost greater than $50.

Which of the following is not a possible SELECT statement? (This does not refer to a specific table, so assume that the column names and table names exist) a) SELECT column_name FROM table_name; b) SELECT * FROM table_name; c) SELECT DISTINCT column_name FROM table_name; d) SELECT ONLY column_name FROM table_name;

d) SELECT ONLY column_name FROM table_name; SELECT column_name FROM table_name; will select a specific column from a table and is a valid SQL query. SELECT * FROM table_name will select all columns from a table and is a valid SQL query. SELECT DISTINCT column_name FROM table_name will select only distinct columns from a table and is a valid SQL query. This can be helpful when a column has entries that contain identical values. SELECT ONLY column_name FROM table_name is an invalid SQL query and no such query exists.

What is the relationship between a database and a schema? a) There is no relationship. b) A database uses SQL that the schema provides. c) If a schema is deleted the database is deleted as well. d) Schemas categorize the objects in a database.

d) Schemas categorize the objects in a database. A database acts as a container and contains data, log files, and schemas within it. Schemas are used to group logical objects together. A schema is a way of categorizing the objects in a database.

Which of the following is a characteristic of a binary search tree? a) Every child under a node is greater than the parent node. b) Every node has a node on its left and its right. c) Deleting a node involves merely moving one of its children in its place. d) The value of a parent node is greater than its left child's value and less than its right child's value (if it has either).

d) The value of a parent node is greater than its left child's value and less than its right child's value (if it has either). The organization of a binary search tree places every left node smaller than its parent and every right node larger than its parent. That means the leftmost node in the entire tree is the smallest. Not every node has to have two children; some nodes only have one, and the leaf nodes have none. Deleting a node from any binary tree involves finding a suitable replacement and ensuring no sub-trees are lost; simply promoting a child does not guarantee both.

Which of the following is not an element of relational database tables? a) table b) row c) column d) loop

d) loop In the context of a database table, a column is a set of data values of a particular type, one for each row of the table. Meanwhile, loops are not an element of relational database tables.

DFS

depth-first search -an algorithm for traversing or searching tree or graph data structures. Start at the root and explore as far as possible along each branch before backtracking. - process of traveling down a single branch in search of the desired element. If not found, move up and repeat the process with unvisited nodes.


Conjuntos de estudio relacionados

Unit 3- Reconstruction Quiz (U.S. History)

View Set

Psych - Ch. 15 Disorders - Prep: Learning Curve

View Set

Systems of Linear Equations Unit Test Review

View Set

Listening Exercise 2.1, Hearing Meters

View Set