UQUIZ 4 Flashcards CS 300 UW MADISON

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/50

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

51 Terms

1
New cards

We are applying binary search on this specific array to find number 7:

[3,6,7,9,10,12,15,17,19]

What is the second subarray that will be checked

A

[3,6,7,9]

B

[12,15,17,19]

C

[6,7]

D

[7,9]

D

[7,9]

This is because we split array in 2, notice 10 is middle term, 7 < 10 so we discard 10 as well and have 3,6,7,9. Do a binary search on this again giving us our second subarray and then we have {7,9]

2
New cards

In a binary search algorithm, what happens if the middle element is equal to the target value?

A

The algorithm continues searching in the left half of the array.

B

The algorithm continues searching in the right half of the array.

C

The algorithm stops and returns the index of the middle element.

D

The algorithm returns -1.

C

The algorithm stops and returns the index of the middle element.

3
New cards

What is the algorithmic complexity class for selection sort

A

constant

B

linear

C

quadratic

D

logarithmic

C

quadratic

4
New cards

Which of the sorting algorithms below is not stable

A

Selection sort

B

Insertion sort

C

Bubble sort

A

Selection sort

5
New cards

What will be the state of the array after running two iterations of insertion sort?

[5,4,3,1,6]

A

[1,4,5,3,6]

B

[1,3,4,5,6]

C

[3,4,5,1,6]

D

[4,5,3,1,6]

C

[3,4,5,1,6]

6
New cards

What is the worst case complexity of merge sort?

A

O(N)

B

O(N2)

C

O(logN)

D

O(NlogN)

D

O(NlogN)

7
New cards

What is the worst case complexity for quick sort

A

O(N)

B

O(logN)

C

O(NlogN)

D

O(N2)

D

O(N2)

8
New cards

Which methods should be implemented when implementing the iterator interface

next(), hasNext()

9
New cards

Which interface should the collection implement to use the for-each loop

Iterable - for each loops rely on the iterable interface

10
New cards

What is the iterable interface. What is its key method?

Represents collections that can be iterated over

Its key method is iterator()

Iterator iterator()

This is implemented by classes like ArrayList

11
New cards

What is the iterator interface

Provides a way to iterate over elements in a collection

boolean hasNext()

next()

12
New cards

What does the iterator() method return

A reference to an iterator

13
New cards

What is depth in a tree

The distance from the root (the root is 0 so a direct connection would mean a depth of 1)

14
New cards

What is height in a tree

The distance from the leaves to the node specified

15
New cards

What is in order traversal?

Left child, parent, right child (BOTTOM UP)

16
New cards

What is post order traversal?

left child, right child, parent (BOTTOM UP)

17
New cards

What is pre order traversal

Parent, left child, right child

18
New cards

What is a predecessor Node?

The highest value previous node (left)

19
New cards

What is a successor node?

The lowest value next node (right)

20
New cards

How do you remove a node from a Binary Static Tree (BST)

Set the parent reference to null

21
New cards

How do you remove a node in the middle of your BST?

Set the parent reference of that node to reference the child node

22
New cards

How do you removing nodes with two children

Find successor and replace node to be removed with successor

23
New cards

How do you remove a node with two children but the successor is not a leaf (has children)

Replace child node of successor with it's successor

24
New cards

What is a balanced tree?

A tree where the depth of both the left and right subtrees differ by at most one

25
New cards

What is the worst case complexity of an unbalanced binary search tree

O(N)

26
New cards

What is a heap

Binary, nearly complete binary tree

27
New cards

What is a max heap

Root is the highest, each successive node is less than the previous

28
New cards

What is amin heap

Root is the lowest, each successive node is higher than the previous node

Good for priority queues

29
New cards

What is the height of a heap

O(logN)

30
New cards

How are heaps stored in arrays

From top to bottom, left to right - with the root at index 0 as it usually requires less instructions

31
New cards

How do you get a node's right child

2 x index

32
New cards

How do you get a node's left child

2 x index + 1

33
New cards

How do we get a node's parent

Floor index / 2

34
New cards

What is the worst case algorithmic complexity for removing an element from the heap

O(logN)

35
New cards

If we use in order traversal on a max heap, the first element to visit will be the maximum value

False

36
New cards

Given a heap with 6 nodes, what will be the index of the last internal node?

2

37
New cards

Consider a new node at the root of a tree, where would the previous node go

It would take the left child's place

38
New cards

What is the worst case algorithmic complexity for heap sort?

O(NlogN)

39
New cards

How many of these references/return values may be null AND cause a NullPointerException to be thrown?

students[0][1].toUpperCase()

While there can be 4 errors caused, there can only be 3 null pointers b/c toUpperCase()'s error would be a wrong data type

40
New cards

Which sorting algorithm would be the best choice if our array is nearly sorted?

B

insertion sort

41
New cards

What is the worst case complexity of getting an element at certain index i for a doubly linked list?

O(N)

42
New cards

Which sort is unstable

selection

43
New cards

Which sort is not in place

merge

44
New cards

Consider a heap represented with the following array:

[10, 9, 8, 4, 6, 7, 5]

What will be the new state of the array after removing the root?

B

[9, 6, 8, 4, 5, 7]

45
New cards

What has a faster access to O(1) elements - Arrays or LinkedLists?

Arrays O(1) ex - get()

LinkedLists O(N)

46
New cards

Which has faster insertions deletions - Arrays or LinkedLists?

LinkedLists O(1)

Arrays O(1)

47
New cards

Do you extend or implement stacks and queues?

Implement

48
New cards

What is a pointer

A node that has no data but contains a memory address

49
New cards

What is the worst-case runtime complexity of the remove() operation in a binary search tree (NOT necessarily balanced), given problem size N is the total number of elements stored in the tree?

O(N) Think of just a bunch of single branches

50
New cards

What direction do you percolate when inserting

New leaf might be smaller than its parent - HEAPIFY UP

51
New cards

What direction do you percolate when removing

Replace root with last leef, HEAPIFY DOWN