Data Structures Quiz 1

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

Which method is well behaved when the given position is valid for the current list? a. add b. remove c. replace d. all of the above

C ??? ASKED NIC ABOUT

Which method is not meaningful for use on an empty list? a. remove b. replace c. getEntry d. all of the above

D

You can add a new entry in a list a. at the beginning b. at the end c. in between items d. all of the above

D

In the interface ListInterface, the method public void add(int newPosition, T newEntry); describes which of the following behaviors? a. adds a new entry at the specified position in the list b. increases the list size by 1 c. moves entries originally at or above the specified position one position higher d. all of the above

D ??? ASKED ABOUT FOR A

In the interface ListInterface, the method public void add(T newEntry); describes which of the following behaviors? a. adds a new entry to the end of the list b. increases the list size by 1 c. does not affect any other entries on the list d. all of the above

D ??? ASKED NIC ABOUT

A fundamental operation of a list is a traversal.

False

A linked implementation of a list grows and shrinks dynamically as nodes are added and deleted.

False

A list is an object whose data consists of unordered entries.

False

In a linked implementation of a list, the replace method replaces the entire node.

False

In an array-based implementation of the ADT list, entries must be ordered alphabetically.

False

In an array-based implementation of the ADT list, entries must be ordered numerically

False

In an array-based implementation of the ADT list, the makeRoom method does the most work when newPosition is n

False

Methods in a vector based implementation of the ADT list have different specifications than methods in an array based implementation of the ADT list

False

Replacing a list entry using an array implementation is faster than using a linked representation.

False

Replacing a node in a linked implementation of a list only requires locating the node and replacing the data portion of the node.

False

The ADT list only works for entries that are strings.

False

The Java Class Library implementation of the interface list return null when an index is out of range.

False

The efficiency of the displayList method is directly related to the efficiency of the getEntry method.

False

The entries of a list are numbered from 0 to n.

False

The first entry is a list is at position 0.

False

When you use a vector to implement the ADT list, retrieving an entry at a given position is slow.

False

When you use an array to implement the ADT list, retrieving an entry at a given position is slow

False

You need a temporary variable to reference nodes as you traverse a list.

False ??? ?ASKED NIC

Adding a node to an empty chain is the same as adding a node to the beginning of a chain.

True

Adding entries to the end of a list does not change the positions of entries already in the list

True

Each entry is a list ADT is uniquely identified by its position within the list.

True

In a linked implementation of a list, you only call the method getNodeAt when we remove an entry other than the first one.

True

In the makeRoom method of the array-based implementation of the ADT list, it is possible that no items will be shifted.

True

Retrieving a list entry using a linked implementation is faster than using an array representation.

True

The ADT list is more general than common lists and has entries that are objects of the same type.

True

The ADT list specifies the order of the entries

True

The Java Class Library contains an implementation of the ADT list that uses a resizable array instead of a linked chain.

True

When a programmer implements an ADT list, clients can use the ADT's operations in a program without knowing how the programmer implemented the list to be able to use it.

True

When you use a vector to implement the ADT list, adding an entry at a the end of the list is fast.

True

When you use an array to implement the ADT list, adding an entry at a the end of the list is fast

True

You cannot use an assert statement to determine of a list is empty.

True

You may replace an entry at any given position in a list.

True

You must know how much memory to allocate before creating a linked implementation of a list.

True

Adding a node at the end of a chain of n nodes is the same as adding a node at position n.

True ??? ASKED NIC

Methods in a vector based implementation of the ADT list are functionally similar to methods in an array based implementation of the ADT list.

Trye

In an array-based implementation of the ADT list, the getEntry method locates the entry by a. going directly to the appropriate array element b. searching for the entry starting at the beginning of the array working to the end c. searching for the entry starting at the end of the array working to the beginning d. none of the above

a. going directly to the appropriate array element

In the LList implementation of a list, the constructor and the clear method a. have the same functionality b. do completely different things c. unnecessary d. none of the above

a. have the same functionality

A new entry is added to an array-based implementation of the ADT list a. immediately after the last occupied position b. immediately before the first occupied position c. in the last array position d. in the location returned by the new operator

a. immediately after the last occupied position

If a chain is empty, the head reference a. is null b. is an empty node with the data field not set c. is in an illegal state d. none of the above

a. is null

In the linked implementation of a list, what happens when you try to add a node at an invalid position? a. it throws an IndesOutOfBoundsException b. it throws an InvalidLinkException c. it returns null d. it returns false

a. it throws an IndexOutOfBoundsError

In the array-based implementation of the ADT list, the removeGap method a. moves each entry to its next lower position b. moves each entry to its next higher position c. swaps the first entry with the specified entry to remove d. swaps the last entry with the specified entry to remove

a. moves each entry to its next lower position

Adding a node at the end of a chain of n nodes is the same as adding a node at position a. n + 1 b. n c. n - 1 d. 0

a. n + 1

In an array-based implementation of the ADT list, the makeRoom method does the most work when a. newPosition is 1 b. newPosition is n c. newPosition is n/2 d. newPosition is n-1

a. newPosition is 1

When adding an entry to an array-based implementation of the ADT list at the end of the list a. no shift is necessary b. all of the previous elements must be shifted toward the front of the array c. only one element is shifted toward the end of the array to make room d. only one element is shifted toward the beginning of the array to make room

a. no shift is necessary

When deleting an entry from an array-based implementation of the ADT list at the end of the list a. no shift is necessary b. all of the previous elements must be shifted toward the front of the array c. only one element is shifted toward the end of the array to close the gap d. only one element is shifted toward the beginning of the array to close the gap

a. no shift is necessary

The last node is a list has a reference to a. null b. itself c. the node before it d. none of the above

a. null

In the LList implementation of a list, when a list is empty the firstNode is _____ and the numberOfEntries is _____. a. null, 0 b. null, 1 c. an empty node, 0 d. an empty node, 1

a. null, 0

In the makeRoom method of an array-based implementation of the ADT list no shift is necessary if a new entry is to be placed at a. numberOfEntries + 1 b. numberOfEntries - 1 c. numberOfEntries d. none of the above

a. numberOfEntries + 1

In an array-based implementation of the ADT list, the contains method locates the entry by a. searching for the entry starting at the beginning of the array working to the end b. searching for the entry starting at the end of the array working to the beginning c. going directly to the appropriate array element d. none of the above

a. searching for the entry starting at the beginning of the array working to the end

To locate a node within a chain that is near the end of the list, we must a. start at the first node and traverse the chain b. start at the last node and traverse the chain c. directly access the node d. none of the above

a. start at the first node and traverse the chain

A reference to the last node in a linked implementation of a list is commonly called the a. tail b. end c. final d. none of the above

a. tail

In a linked implementation of a list with a tail reference, removing an entry affects the tail reference if a. the list has multiple entries and the entry to be removed is the last one b. the list has multiple entries and the entry to be removed is the first one c. the list is empty d. all of the above

a. the list has multiple entries and the entry to be removed is the last one

If the reference to the first node is null, this means a. the list is empty b. the list is full c. the garbage collector should be invoked d. the list is in an unstable state

a. the list is empty

In a linked implementation of a list with a tail reference, removing an entry affects the tail reference if a. the list only contains one entry b. the list is empty c. the list is full d. all of the above

a. the list only contains one entry

When inserting a node between adjacent nodes in a chain you must locate a. the node before the insertion position and the node after the insertion position b. the first node and the node before the insertion position c. the first node and the node after the insertion position d. the last node and the node after the insertion position

a. the node before the insertion position and the node after the insertion position

Moving through a linked implementation of a list from one node to another is called a. traversing b. walking c. hopping d. none of the above

a. traversing

A linked implementation of a list a. uses memory only ass need for new entries b. returns unneeded memory to the system when an entry is removed c. avoids moving data when adding or removing entries d. all of the above

d. all of the above

In a chain of linked nodes you can a. add nodes from the beginning of a chain b. add nodes from the end of a chain c. add nodes that are between other nodes d. all of the above

d. all of the above

In a chain of linked nodes you can a. remove nodes from the beginning of a chain b. remove nodes from the end of a chain c. remove nodes that are between other nodes d. all of the above

d. all of the above

In a linked-based implementation of the ADT list with a tail reference, which method has a time efficiency of O(1)? a. adding an entry to the end of the list b. adding an entry to the beginning of the list c. clear d. all of the above

d. all of the above

In the linked implementation of a list, the add method public void add(int newPosition, T newEntry) inserts a new entry a. between adjacent nodes of the list b. at the end of the list c. at the beginning of the list d. all of the above

d. all of the above

To determine if a list is empty you can a. check to see if the length of the list is zero b. check to see if the reference to firstNode is null c. use an assertion on firstNode == null d. all of the above

d. all of the above

Given an ADT list called myList that contains 4 items entries in it, which statement will add a new item called x on the front of the list? a. myList.add(1, x) b. myList.add(x) c. myList.addFirst(x) d. myList.addFront(x)

A

Given an ADT list called myList that contains 4 items entries in it, which statement will remove the first item on the list? a. myList.remove(1) b. myList.remove() c. myList.removeFront() d. myList.removeFirst()

A

If myList is a declared ADT list and the front of the list is on the left, what does the list look like after applying the following pseudo code? myList.add("cat") myList.add("dog") mylist.add("fish") a. cat, dog, fish b. fish, dog, cat c. cat, fish, dog d. dog, fish, cat

A

If myList is a declared ADT list and the front of the list is on the left, what does the list look like after applying the following pseudo code? myList.add("horse") myList.add("goat") myList.add(3, "fish") myList.add(1, "dog") myList.add("cat") a. dog, horse, goat, fish, cat b. horse, goat, fish, dog, cat c. cat, horse, goat, fish, dog d. cat, fish, goat, dog, horse

A

If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(3) return after applying the following pseudo code? myList.add("horse") myList.add("goat") myList.add(1, "fish") myList.add("cat") myList.add(2, "dog") myList.remove(4) a. horse b. goat c. dog d. cat

A

If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(3) return after applying the following pseudo code? myList.add("horse") myList.add("goat") myList.add(1, "fish") myList.replace(3, "sheep") myList.add("cat") myList.remove(1) myList.add(2, "dog") a. sheep b. dog c. horse d. cat

A

If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(3) return after applying the following pseudo code? myList.add("horse") myList.add("goat") myList.add(3, "fish") myList.add(1, "dog") myList.add("cat") a. goat b. fish c. cat d. horse

A

If myList is a declared ADT list and the front of the list is on the left, what does the method getEntry(4) return after applying the following pseudo code? myList.add("horse") myList.add("goat") myList.add(1, "fish") myList.add("cat") myList.remove(1) myList.add(2, "dog") a. cat b. dog c. goat d.fish

A

In the ADT list, new entries are typically added a. at the end of the list b. at the beginning of the list in the list c. at a computed place in the list depending on the number of elements

A

In the interface ListInterface, the method public void remove(int givenPosition); describes which of the following behaviors? a. remove the entry at a given position from the list b. increases the list size by 1 c. does not affect any other entries on the list d. all of the above

A

The public ArrayList() constructor in the Java Class Library ArrayList creates an empty list with an initial capacity of a. 10 b. 0 c. 100 d. 1

A

What does the Java Class Library implementation of the interface list do when an index is out of range. a. throw an exception b. return null c. return false d. crash the program

A

In a linked-based implementation of the ADT list with a tail reference, what is the performance of adding an entry at the end of the list? a. O(1) b. O(log n) c. O(n) d. O(n 2 )

a. O(1)

In a linked-based implementation of the ADT list with a tail reference, what is the performance of removing an entry at the beginning of the list? a. O(1) b. O(log n) c. O(n) d. O(n 2 )

a. O(1)

In a linked-based implementation of the ADT list with only a head reference, what is the performance of removing an entry at the beginning of the list? a. O(1) b. O(log n) c. O(n) d. O(n 2 )

a. O(1)

In an array-based implementation of the ADT list, what is the best case performance of the ensureCapacity method? a. O(1) b. O(log n) c. O(n) d. O(n2 )

a. O(1)

In an array-based implementation of the ADT list, what is the best case performance of the makeRoom method? a. O(1) b. O(log n) c. O(n) d. O(n2 )

a. O(1)

In an array-based implementation of the ADT list, what is the best case performance of the remove method? a. O(1) b. O(log n) c. O(n) d. O(n2 )

a. O(1)

In an array-based implementation of the ADT list, what is the performance of adding an entry at the end of the list if you amortize the cost of resizing the array over all additions to the list? a. O(1) b. O(log n) c. O(n) d. O(n2

a. O(1)

In an array-based implementation of the ADT list, what is the performance of adding an entry at the end of the list when the array is not resized? a. O(1) b. O(log n) c. O(n) d. O(n2 )

a. O(1)

In a linked-based implementation of the ADT list with a tail reference, what is the performance of adding an entry that is not at the beginning of the list? a. O(n) b. O(n 2 ) c. O(log n) d. O(1)

a. O(n)

In a linked-based implementation of the ADT list with a tail reference, what is the performance of removing an entry that is not at the beginning of the list? a. O(n) b. O(n 2 ) c. O(log n) d. O(1)

a. O(n)

In a linked-based implementation of the ADT list with only a head reference, what is the performance of adding an entry at the end of the list? a. O(n) b. O(n 2 ) c. O(log n) d. O(1)

a. O(n)

In a linked-based implementation of the ADT list with only a head reference, what is the performance of removing an entry at the end of the list? a. O(n) b. O(n 2 ) c. O(log n) d. O(1)

a. O(n)

In an array-based implementation of the ADT list, what is the performance of adding an entry at the end of the list when the array is resized? a. O(n) b. O(n 2 ) c. O(log n) d. O(1)

a. O(n)

In an array-based implementation of the ADT list, what is the worst case performance of the ensureCapacity method? a. O(n) b. O(n2 ) c. O(log n) d. O(1)

a. O(n)

In an array-based implementation of the ADT list, what is the worst case performance of the makeRoom method? a. O(n) b. O(n2 ) c. O(log n) d. O(1)

a. O(n)

Including a tail reference to a linked implementation of a list makes which functionality more efficient? a. adding a node to the end of a list b. searching for a node on the list c. removing a node from the list d. all of the above

a. adding a node to the end of a list

In the linked implementation of a list, the add method public void add(T newEntry) inserts a new entry a. at the end of the list b. at the beginning of the list c. between adjacent nodes of the list d. all of the above

a. at the end of the list

In a linked-based implementation of the ADT list with only a head reference, which method has a time efficiency of O(1)? a. clear b. toArray c. contains d. all of the above

a. clear

In the LList implementation of a list, given a node called currentNode, which statement moves the node's reference to the next node? a. currentNode.getNextNode(); b. currentNode.get(); c. currentNode.forward(); d. currentNode.traverse();

a. currentNode.getNextNode();

In the makeRoom method of an array-based implementation of the ADT list a. entries are shifted toward the end of the array beginning with the last entry b. entries are shifted toward the beginning of the array beginning with the last entry c. entries are shifted toward the beginning of the array beginning with the first entry d. entries are shifted toward the end of the array beginning with the first entry

a. entries are shifted toward the end of the array beginning with the last entry

When adding an entry to an array-based implementation of the ADT list at a specified location before the end of the list a. entries must be shifted to vacate a position for the new item b. no shift is necessary c. a new entry must be allocated and linked to attach the new item d. the entry at the specified location will be overwritten by the new item

a. entries must be shifted to vacate a position for the new item


Set pelajaran terkait

AP Macro - Unit 2 - Economic Indicators and the Business Cycle

View Set

MGT340 - reading quiz chapter 2/part 1 - Utilitarianism Jeremy Bentham

View Set

Unit 7: Early Sectionalism of the North, South, and West

View Set

CompTIA Network+ Exam N10-008 - Lesson 3: Deploying Ethernet Switching

View Set

Ch. 14: Communicable and Infectious Disease Risks

View Set

Week 4 Safety in Nursing Practice

View Set