Midterm 2

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

stack

A ____ can be used to check whether parantheses in an expression are balanced.

linked list object

A _______ holds a reference to the first node, and each node holds a reference to the next node

faster than

A binary search is generally ____ a linear search.

random

A binary search requires ____ access.

Queue

A collection of elements with "first-in, first-out" retrieval

Stack

A collection of elements with "last-in, first-out" retrieval

List

A collection that remembers the order of its elements

list

A collection that remembers the order of its elements

Linked Lists

A data structure used for collecting a sequence of objects. It allows efficient addition and removal of elements in the middle of the sequence. It consists of a number of nodes. Use this when you are concerned about the efficiency of inserting or removing elements. Rarely need element access in random order.

collisions

A good hash function minimizes ______ - identical hash codes for different objects

O(n^2)

A loop with n iterations has _____ running time if each step takes O(n) time

Backtracking

A problem solving technique that builds up partial solutions that get increasingly closer to the goal (Eight Queens Problem)

Mutual Recursion

A set of cooperating methods calling each other repeatedly

Queue

Add items to one end (the tail) and remove them from the other end (the head)

O(1)

Add last element

O(1)

Add/remove at an iterator position.

O(1)

Add/remove first element.

4

After 5 iterations of selection sort working on an array of 10 elements____more iterations are always necessary to complete the sort

O(log(n))

An algorithm that cuts the size of work in half in each step runs in _____ time.

Sorting

An algorithm that places elements in order.

Node

An object that stores an element and references to the neighboring nodes

Set

An unordered collection of unique elements

Set

An unordered collection of unique elements. Arranges its elements so that finding, adding, and removing elements is more efficient. It does not admit duplicates

Priority Queue

An unordered collection, that has an efficient operation for removing the element with the highest priority

sequential

Another name for linear search

mySet.add("apple");

Assume that you have declared a set named mySet to hold String elements. Which of the following statements will correctly insert an element into mySet?

O(log n)

Binary search is an ____ algorithm

Big-oh notation

Describes the growth rate of a function. (ignore the coefficients of the terms and all lower order terms)

I and II

In a linked list data structure, when does the reference to the first node need to be updated? I inserting into an empty list II deleting from a list with one node III deleting an inner node

f(n) = O(g(n))

In general, the expression ____ means that f grows no faster than g

Hash Table

In this, Set elements are grouped into smaller collections of elements that share the same characteristics. It must implement the method Hash Code.

Collection

It groups together elements and allows them to be retrieved later

Binary Search

Locates a value in a sorted array by determining whether the value occurs in the first or second half and then repeating the search in one of the halves, requires O(log(n)) steps

iterator.next

Moves the position and it returns the element that the iterator is passing

Quick Sort

No temporary arrays are required, "Divide and conquer Partition the range, sort each partition. O(n log(n))

nodes

Rather than storing values in an array, a linked list uses a sequence of ____.

Recursive Computation

Solves a problem by using the solution to the same problem with simpler inputs

Selection Sort

Sorts an array by repeatedly finding the smallest element of the unsorted tail region and moving it to the front; slow when running big lists

20

Suppose we are using binary search on an array with approximately 1,000,000 elements. How many visits should we expect to make in the worst case?

O(log_2 n) (base 2)

Suppose we maintain an array A of n int values as follows: A[0] < A[1] < . . . < A[i] > A[i + 1] > A[i + 2] > . . . > A[n - 1] The ith element is the maximum in the array. What would be the lowest big-Oh notation for finding that element? Consider a variation of the binary search.

One element visit

T(n) = T(n / 2) + 1,______ before a recursive call on one half of the array.

HashMap, TreeMap

The _____ and ______ classes but implement the Map interface

Insertion sort

The method where you pick up one card at a time and insert it so that cards stay sorted;

Recursion

The same computation occurs repeatedly

comparable

The sort method of the Arrays class sorts arrays containing objects of classes that implement the ____ interface.

Sets

These collections don't have duplicates

iterator.add

This adds an object after the iterator. Then moves the iterator position past the new element.

Tree set

This can be formed for any class that implements the Comparable interface, such as String or Integer

hash function

This computes an integer value from an object.

List Iterator

This is used to access elements inside a linked list. It encapsulates a position anywhere inside the linked list. (cursor of a word processor)

Map

This keeps associations between key and value objects

Map

This keeps associations between key and value objects. Every key has an associated value. It stores the keys, values, and the associations between them.

Recursive Helper

This method helps the recursive method (Palindrome)

Stack

This remembers the order of elements, but you can only add and remove at the top

iterator.remove

This removes an object that was returned by the last call to next or previous. It can only be called once after calling next or previous.

Remove

To advance an iterator Update the position and remember the old position for the _____ method.

implement the Comparable interface

To create a TreeSet for a class of objects, the object class must ____.

type

What can a generic class be parameterized for?

2

What is the minimum number of node references that are required to be modified to remove a node from the middle of the list? Consider the neighboring nodes.

Total number of element visits

What is the performance of an algorithm closely related to?

O(n)

When the buffer for an array list must be grown, a single reallocation operation takes ____ time.

10,000

When the size of an array increases by a factor of 100, the time required by selection sort increases by a factor of ____?

LinkedList class

When you use the add method, the new element is inserted before the iterator, and the iterator position is advanced by one position.

Removing

When____ an element from a priority queue, the element with the most urgent priority is retrieved.

quicksort and mergesort

Which of the sorts in the textbook are based on the strategy of divide and conquer?

Queue

You need to access values in the order in which they were added (first in, first out), and not randomly. Which collection type should you use?

set

a collection of unique elements organized for efficiency

linked list

a data structure used for collecting a sequence of objects that allows efficient addition and removal of already-located elements in the middle of the sequence

linked list node

a reference to its neighboring nodes and a data element

Linear Search

locates a value in an array in O(n) steps

Merge sort

sorts an array by cutting the array in half , recursively sorting each half, and merging the sorted halves, O(n log(n))

Quadruples

suppose an algorithm requires an order of n3 element visits. How does doubling the number of elements affect the number of visits?

T(n / 2)

the total number of visits to merge sort an array of n / 2 elements

list iterator

use a(n) ____ to access elements inside a linked list.


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

Abstract Classes, Interfaces, Static Variables

View Set

Structure and Function of Cartilaginous Joints

View Set

Second Quarter Exam Review (Survey of the Bible)

View Set

Chapter 35: Assessment of Immune Function

View Set

Chapter 7: Economic Factors, Business Information, Strategies, and Risks

View Set

chapter 21 and 22 test (alcohol and illegal drugs)

View Set