Final Exam CSCI-2540

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What are the operations of an ADT list?

- Create an empty list - Determine a list is empty - Determine number of items of a list - Add an item - Remove the item - Remove all items - Retrieve (get) the item

What are the ADT stack operations?

- Create an empty stack - Determine whether a stack is empty - Add an item - Remove from stack - Remove all items - Retrieve from stack

Data items to be sorted can be

- Integers - Character strings - Objects

Encapsulation

- a principle of OOP - used to enforce walls of an ADT - combines ADT's data with its method to form an object - hides implementation details from a programmer

The ADT stack is implemented by using

- an array - ADT list - linked list

Properties of growth rates

- ignore low-order terms - ignore a mulitplicative constant - O(f(n)) + O(g(n)) = O(f(n) + O(g(n))

What is the strategy of a sequential search?

- look at each item in a data collection in turn, beginning with the first one. - Stop when the desired item is found, and reach the end of the data collection

The strategy of insert sort is

- partitioned array into two regions: sorted and unsorted - take each item from unsorted region and insert into the correct order in the sorted region.

If the item in position 1 of a list represents the top of the stack

- push(newItem) implemented as add(1, newItem) - pop() implemented as get(1), remove(1) - peek() operation is implemented as get(1)

Collection.sort() method

- sort a given list - in order to sort, the items must be able to compare orders (with compareTo method)

Average case analysis

A determination of the average amount of time that an algorithm requires to solve problems of size n

worst-case analysis

A determination of the maximum amount of time that an algorithm requires to solve problems of size n

Growth-rate function

A mathematical function used to specify an algorithm's order in terms of the size of the problem

Big O Notation

A notation that uses the capital letter O to specify an algorithm's order Example: O(f(n))

Order of an algorithm

Algorithm A is order f(n) - denoted O(f(n)) - if k and n0 exists that A required no more than k * f(n) time units to solve of size n ≥ n0.

What else about an ADT list?

All items are referenced by their position within the list.

What is the difference between an Iterator and a ListIterator?

An Iterator can be used on Collection types and only go forward, while an ListIterator can be used on list and it go forward and backward

Worst-case and average-case analyses

An algorithm requires different times to solve problems of the same size

What are the private data fields of a stack?

An array Objects called items, and the index top

Options for implementing an ADT is

Array and Linked list

What are the three classes of an ADT List

ArrayList by using arrays, LinkedList by using linked lists, and Vector is by using arrays.

What is an example of a data structure?

Arrays

In an ADT list

Each item has a unique predecessor and a unique successor. While the head or front does not have a unique predecessor and the tail or end does not have a unique successor.

Order of growth of some common functions

O(1) < O(log2n) < O(n) < O(log2n) < O(n2) < O(n3) < O(2n)

The worst case of a merge sort is

O(n log2 n)

The best case of bubble sort is

O(n)

The analysis of selection sort is

O(n2)

The worst case of bubble sort is

O(n2)

The worst case of insertion sort is

O(n2)

Analysis of algorithms

Provides tools for contrasting the efficiency of different methods of solution

What is a reference-based implementation of the stack?

Requires when as stack grows and shrink dynamically.

JCF contains an implementation of a stack class is called?

Stack (generic)

What is an implementation of StackArrayBased class?

StackInterface

What are the instances of a stack?

Stacks

What are the specifications of ADT operations?

They defined contract for the list and doesn't specify how to store lists or how to perform the operations.

A stack class is derived from what?

Vector

The efficiency of a sequential search is

Worst case: O(n) Average case: O(n) Best case: O(1)

external sort

a collection will not fit in the main memory all at once but reside in secondary storage

Data structure

a construct defined with a language that stores collection of data.

An array-based implementation is

a list's items stored in an array and a natural choice

Implementation details should be hidden behind a wall of ADT operations which

a program ability to access data structure using ADT operations.

Top

a reference to the head of a linked list of items

Typical operations on data includes:

add data, remove data, and ask questions in a data collection.

Three difficulties with comparing programs

algorithm coded, computer should use, and data should programs use.

For small arrays, the insertion sort is

appropriate due to its simplicity

The disadvantage of selection sort

appropriate for small n

Data abstraction

asks to thinks what can do to a collection of data independently of how to do it and allows to develop each data structure in relative isolation from the rest of the solution.

ADT operations

can be used in an application without knowledge of how operator will be implemented.

An ADT is composed of

collection of data, and a set of operations on that data

The strategy of a bubble sort is

comparing adjacent elements and exchange if out of order -By comparing the first two, the second and third, so on, and move the largest(or smallest) elements to the end of an array -Repeated the process will sort the array into descending or ascending order.

A module specification should....

detail how module behaves and identify details that hidden with the module

Choosing data structures to represent data is a part of implementation which leads of a data structure depends on

details of the ADT operations and context in which operations will be used.

The strategy of a mergesort is

dividing array into halves, sort each half, and merge the sorted ones into an sorted array

The advantage of selection sort

does not depend on the arrangement of the data

A reference-based implementation of a stack

does not put a limit on the size of the stack

An algorithm growth rate

enables comparison of one algorithm with another, which led algorithm A leds to n^2 and B leds to n

An array-based implementation of a stack uses

fixed-size arrays, that prevents the PUSH operation from adding an item to the stack if the limit has been reached

Iterator

gives ability to cycle through items in a collection and accesses next item by using ITER.NEXT()

Information hiding

hide implementation details within the module and make details accessible from outside module

StackReferenceBased

implements StackInterace

JCF

implements many of commonly used ADTs.

Implement of an ADT

includes choosing a particular data structure.

What are the categories of sorting algorithms?

internal and external sort

Search

is a 1-based position of an object of the stack

An array-based implementation

is a list's items are stored in an array ITEMS, a natural choice that includes both an array and a list identify items by a number, and a list's kth item will be store in ITEMS[K-1]

Sorting

is a process that organizes a collection of data into either ascending or descending order

List interface supports an order collection

is also known as a sequence.

Stack

is an Last-In, First-Out (LIFO) is the last item placed on as stack will be the first one removed

Resizable array

is an array that grows and shrinks as the program executes and an illusion created by using allocate and copy strategy with fixed-size arrays

What is a mergesort?

it is a recursive sorting algorithm that gives the same performance, regardless of the initial order of the array items.

JCF provides two iterator interfaces

java.util.Iterator and java.util.ListIterator

What are the important divide-and-conquer sorting algorithms?

mergesort and quicksort

What are the iterator methods?

next() and hasNext()

For large arrays, the insertion sort is

prohibitively inefficient.

StackInterface

provides a specification for the three implementations such as array, ADT list, and linked list

Stack includes methods like

push, pop, peek, and search

internal sort

requires the collection of data fit entirely in the computer's main memory

Data abstraction also

results in a wall between data structures and a program that accesses data with these data structures

The strategy of selection sort

select the largest item and put it in a correct place

Procedural abstraction

separates the purpose and use of a module from its implementation

A comparison of algorithms

should focus of significant difference in efficieny and not consider reductions in computing due to clever coding tricks.

The isolation of modules is not total when

specficiations, or contracts, govern how they interact with each other.

Sort key

the part of a record that determines the sorted order of the entire record within a collection records

The efficiency of a binary search is

the worst case of O(log2n)

The strategy of a binary search is

to search a sorted array for a item, which repeatedly divide the array in half, and determining which half must be, if it is indeed present, and discard the other half

Examples of an algorithm are

traversal of a linked list, Towers of Hanoi, and nested loops.

Collections framework are

unified architecture for representing and manipulating collections and includes interfaces, implementations, and algorithms.

StackException

used by StackInterface and extends java.lang.runtime

Specifications of an ADT indicates

what operations do, not implementing them.

Counting an algorithm operations in a way to access its efficieny is to...

which an algorithm's execution time is related to the number of operations it requires.


Set pelajaran terkait

Part 3: Text Structure in an Informational Text

View Set

SY0-410:2 TS Quiz Compliance and Operational Security

View Set

Everfi Marketing Unit Study Guide

View Set