Data Structures and Algorithms

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

What is the sorting process in selection sort?

1. Making a pass through all the elements and selecting the smallest one 2. Swap the smallest element with the the element at index 0 3. Repete until all the elements are sorted

Use the postal analogy to describe stacks.

...

What are stacks allowed access to?

...

What is insertion sort?

...

Why are stacks, queues and priority queues more abstract than arrays?

...

What is the sorting process in bubble sort?

1. Compare first two elements 2. If the one on the left is bigger, swap 3. Move attention one position to the right. Repeat until largest element is on the right.

What is the difference between a triangular number and a factorial?

A triangular number is the sum of a number plus each number smaller than it to zero. A factorial of a number is a number * each number smaller than it to zero.

How is finding an element in a list different than finding an element in an array?

An item in an array can be accessed by directly accessing it's index. In a list an item can't be accessed directly; you must use the relationship between the items to access it.

How can you fix a broken sequence? What is created?

Delete enough items so that the Fron arrow wraps around. This creates a single contiguous sequence.

How is "peek" different in a queue?

It "peeks" at the value of the item at the front of the queue without removing it as opposed to the last value in a stack.

What is "peek"?

It allows the user to read the value at the top of the stack with out removing it.

What is the median-of-three partitioning method?

It allows us to find the pivot point by taking the median of the left, center and right elements.

What is the advantage of using a doubly linked list?

It allows you to transverse forward and backward in a list. Each list links to the next link (just like in reg. lists) and to the previous link.

How is the constructor named?

It has the same name as the class it resides in.

Where does the term queue come from?

It is a British reference to waiting in line. Fist in, first out.

object.method(); is and example of

Invoking a method for a specific object.

What is meant by void in public static void main(String args[]) ?

Void indicates that the main() method has no return value.

Explain stacks using the work day analogy.

...

Explain how you would create an algorithm that matches delimiters on the stack. Include errors in your explanation.

1. Read the characters from a string one at a time. 2. Find and place the opening delimiters on the stack one at a time 3. When the program reads a closing delimiter from the input, pop the corresponding opening delimiter from the top of the stack 4. If the delimiters are not of the same type an error will occur, telling us that the string is missing either an opening or closing delimiter. If there is no opening delimiter on the stack an error will occur.

First two steps of object-oriented approach?

1. Separate the data structure storage from the rest of the program(now called the user). 2. Improve the communication between the storage structure and the user.

To create an object in Java you must do two things:

1. Use the keyword "new" 2. Store a reference to the object in a variable that is the same type as the class. So: Object = new ClassReference();

What are the three steps to delete an item in an array?

1.Search for the item 2. Find the item 3. Move the items with a higher index value down to fill the "hole"

What is a double-ended linked list?

A linked list that has reference to the last link as well as the first.

What is a sorted list?

A list in which the items are in sorted order by key value.

int x; is an example of:

A loop creator.

What is a reference?

A number that refers to an object. It's the objects address in the computers memory.

How is a priority queue different than a queue?

A priority queue items are ordered by key value so that the item with the lowest key ( or in some implementations the highest key) is always at the front. Items are inserted in the proper position to maintain the order.

What is an ADT?

An Abstract Data type is a conceptual tool. It suggests that we describe the fields and methods of a class while excluding how the methods carry out their tasks. Ex I know that I need to use push() and pop() but don't know how the code for these methods are written.

What is an iterator?

An Object containing references to items in a data structure, used to traverse through the structure.

What is a data structure?

An arrangement of data inside a computers memory or a disk.

An object is often referred to as:

An instance of a class.

What is real-world modeling?

Data structures that directly model real-world situations...think graphs.

Why is Quicksort so popular?

Its the fastest of the sorting algorithms.

Explain LIFO

Last-In-First-Out. A stack is a LIFO storage mechanism because the last item inserted is the first one to be removed.

What are the steps to creating an array?

MRCNL: Main(), Reference, Create an Array, Number of Items, Loop.

Breaking up the program into classes does what?

Makes it easier to design, understand, modify and maintain the program.

What do algorithms do?

Manipulate the data in data structures in various ways such as sorting.

What size arrays is Shellsort good for?

Medium-sized arrays of a few thousand items depending on the implementation.

A field of method that is private can only be accessed by

Methods that are apart of the same class.

Whatever you can do to manipulate the data storage structure becomes our:

Methods.

Each Link object contains a reference called:

Next.

What is the "push"?

Placing a data item on top of the stack.

What are the two types of data in java?

Primitive types (int, char, boolean,long, double etc) and objects.

What are the pros and cons of using a priority queue implemented by a simple array?

Pro: Simple and appropriate when the # of items isn't high or insertion speed isn't critical. Con: Suffers from slow insertion

What are the steps to setting up an array class with a constructor?

RCCSGE: Reference the array, Constructor, Create an Array, Set Value, Get Value, End Class.

long [] arr is; an example of:

Referencing an array.

private long[] a; is an example of:

Referencing an array.

What is "popping"?

Removing a data item from the top of the stack.

What does the charAt() method do?

Returns a character at the specific position in the string object.

What are the benefits to using Shellsort?

The code is short and simple.

A field in the list itself contains a reference to:

The first link.

What is wrapping around? When is it useful? What is created that must be fixed?

Wrapping around allows the user to fill in new items in the queue at index zero, assuming that the queue is empty at index zero. This creates a broken sequence (the items in the queue are in two different sequences in the array).

How does the mail sorting analogy apply to the priority queue?

You insert a letter from the postman into your pile of pending letters according to priority. The higher the priority the higher the position in the pile.

What is Knuth's interval sequence?

h = (h-1)/3

Execution of the program starts where?

main()

Mergesort requires a workspace equal in size to what?

the original array

What must be added to all input methods for them to work?

throws IOException

What is a class?

A blueprint that defines an objects variables and methods.

What is an array?

A container object that holds multiple values of the same type.

What is a link?

A data item embedded in a linked list. It is an object of a class.

What is a deque?

A double-ended queue. You can insert items and either end & delete items from either end.

What is recursion?

A programming technique in which a method calls itself.

If a recursive approach in inefficient what should we replace it with?

A simple loop or a stack-based approach.

What is an object?

A software bundle of variables and related methods.

What is a constructor?

A special method that is called automatically whenever a new object is created. It prepares the object for use.

Why must you use the key word "new" when creating an array?

Arrays in java are treated as objects.

Name 5 data types

BLASH: binary trees, linked lists, arrays, stacks, hash tables

How do other parts of your program interact with objects?

By interacting with an objects methods

What are invariants?

Conditions that remain unchanged as the algorithm proceeds.

What does the parse.Int() method do?

Converts the string type into an integer.

The keyword "new" is used to do what?

Create a new object in Java.

public LowArray(int size) is an example of what? Note that LowArray is also the name of the class.

Creating a Constructor.

{a = new long [size]; } is an example of what?

Creating an array

arr = new long [100];is an example of:

Creating an array.

"____ is like a queen bee, kept hidden in the middle of the hive, fed and cared for by worker-bee methods"

Data

What is real-world storage data?

Data structure storage that describes physical entities external to the computer. Accessed by a programs user.

What are programmer's tools?

Data structure storage that is accessed by the program itself. Ex - stacks and queues.

What algorithm is Shellsort based on?

Insertion sort.

What is the divide and conquer approach?

Divide one big problem into two smaller ones and solve each separately. Then you divide each solution into an even smaller problem and solve them. Continue this process until you get to the base case which is easily solved.

public long getElem(int index) {return a[index];} is an example of what?

Get value

What does the searchKey variable do?

IT holds the value we are looking for.

Give an example of when partitioning would be useful.

If you want to divide a list of records into two groups s/a employees who sell above or below yearly sales goals.

What is the difference between a stack and a queue?

In a queue the first item inserted is the first to be removed (FIFO). In a stack the last item inserted is the first to be removed (LIFO)

Describe the Quicksort algorithm.

It partitions an array into two subarrays; one left group and one right group. All the items in the left array are smaller than those on the right. Then it calls itself recursively to quicksort each subarray.

How does the partition algorithm work?

It starts with two pointers, one at each end of the array. The pointer on the left end moves to the right and right end moves to the left. When the left pointer encounters a data item smaller than the pivot value (the value used to determine into which of the two groups an item is placed), it keeps going because it is already on the right side of the array. When it encounters an item that is larger than the pivot value, it stops. When the right pointer encounters a data item larger than the pivot value it keeps going because it is already on the correct side of the array. When it comes to a data item smaller than the pivot value it stops. Now the two items which have stopped the pointers are swapped. After the swap, the pointers continue, stopping only to swap items that are on the wrong side of the array. The process continues until the pointer meet, making the partitioning process complete.

What is meant by public in public static void main(String args[]) ?

Public indicates that the main() method can be called by any object.

public void setElement(int index, long value) {a[index] = value; is an example of what?

Set value

Describe Shellsort.

Shellshort is a multi pass algorithm. In each pass the algorithm insertion sorts widely spaced elements. (The spacing of these elements is represented by the letter h.) Next the algorithm shifts over one cell and sorts those elements. This process continues until all elements have been "h-sorted", meaning that all items spaced h cells apart are sorted amongst themselves. Now the array is "almost" sorted. Next we must "diminish the gap". In order to do so, we must calculate the interval/gap sequence. This is the sequence of numbers used to generate the intervals at which we sort.

What is an ADT list?

Sometimes called a linear list, it is a group of items arranged in a linear order.

What is meant by static in public static void main(String args[]) ?

Static indicates that the main() method is a class method.

What does the [] operator tell the compiler?

That we are naming an array object.

How are primitive types like int and double stored in the computers memory?

The actual value is stored in memory.

int nElems = 0; is an example of:

The number of items in the array .

What happens to non delimiter characters?

They are not inserted onto the stack; they are ignored.

What is public static void main(String args[])?

This is a main() method with three modifiers

What is Radix sort?

This sort examines each digit of the key separately, starting with the least significant digit. All the data items are divided into 10 groups. These 10 groups are then reassembled starting with all the keys that end in 0, followed by all keys ending in1 and so on (up to keys ending in 9). These steps are a sub-sort. In the next sub-sort, all is divided into 10 groups again, but in order of their 10s digit. This is done without changing the order of the previous sort. The sub-sorts must be stable. The groups are recombined, those w a 10s digit of 0 first up to 9. This process is repeated.

What is the down side to using a doubly linked list?

To delete or insert a link you must deal with four links instead of two.

What is partitioning?

To divide data into two groups, so that all the items with a key value higher than a specified amount are in one group and all items with a lower key value are in another.

Any outside entity that wants to access data in a class can do so by:

Using a method of that class.

Unlike a stack, the items in a queue don't always:

extend all the way down to index 0.


Conjuntos de estudio relacionados

(PA Regulations) Law Supplement Practice Exam

View Set

Health Assessment Prep U: Chapter 18-Assessing Mouth Throat Nose and Sinuses

View Set

Lesson 1 - Filing a Tax Return *

View Set