ics46 midterm

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

1/54

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.

55 Terms

1
New cards

What is a collision in the context of hash functions for string keys?

when multiple keys map to the same integer value

2
New cards

What is the worst-case time complexity for searching a key in a chained hash table where ( n ) is the number of keys and ( m ) is the number of slots in the table?

O(n)

3
New cards

Which of the following data structures is often used to implement the chains in a chained hash table?

Linked list

4
New cards

What is a hash function for strings?

A function that maps strings to integers

5
New cards

Which of the following is an advantage of using a chained hash table over an array-only implementation?

No clustering of keys

6
New cards

SELECT ALL: Which of the following is/are disadvantage(s) of using open addressing with linear probing for a hash table compared to using a chained hash table?

degrades with primary clustering

7
New cards

What is special about a chained hash table?

it allows multiple keys stored in a list at each table slot

8
New cards

What is the average time complexity for inserting a key in a chained hash table (given n is the number of keys and m is the table size)?

( O(1) )

9
New cards

Which distribution of keys from a hash function will give the best performance in a hash table?

uniform

10
New cards

Which of the following is a requirement for a good hash function for strings?

It should always map a given string to same integer

11
New cards

Which of the following is an advantage of using a hash table for strings over a sequential search?

none of the other choices

12
New cards

What is the load factor of a chained hash table with n keys and m slots?

( n/m )

13
New cards

Which of the following is an advantage of using a chained hash table over an open-addressed hash table?

none of the other choices

14
New cards

What is the space complexity of a chained hash table with ( n ) keys and ( m ) slots?

( O(n + m) )

15
New cards

Which of the following can cause a chained hash table to degenerate in performance?

hash table too small for the number of keys

16
New cards

SELECT ALL: What is an advantage of using open addressing with linear probing for a hash table compared to using a chained hash table?

uses less memory

17
New cards

Why is a string hash function that multiplies all the ASCII codes together a poor choice?

common factors result in excessive collisions at non-prime table slots

18
New cards

Why are prime number table sizes used for hash table using open addressing?

to avoid bias when wrapping the table size with modulo

19
New cards

What happens when the load factor of a chained hash table increases?

The number of collisions increases

20
New cards

SELECT ALL: Which of the following factors can affect the quality of a hash function for keys that are character strings?

Common prefixes in the strings

21
New cards

Which operations best suit the deque data structure: [\text{enq()

deq()

22
New cards

Which describes the order items are entered and removed from a stack data structure?

Last in First Out (LIFO)

23
New cards

Which describes the order items are entered and removed from a queue data structure?

First In First out (FIFO)

24
New cards

What is the output of the following program? (stack example)

GFEDCBA

25
New cards

If we are using a singly linked list to implement a queue

which end should be the front?

26
New cards

Which operations best suit the stack data structure?

push()

27
New cards

Which data structure is appropriate for storing requests to be processed by a web server?

queue

28
New cards

Which data structure is appropriate for scheduling execution of threads in a real-time kernel?

priority queue

29
New cards

What is the output of the following program? (queue example)

ABCDEFG

30
New cards

Which operations best suit the queue data structure?

enq()

31
New cards

Which data structure is appropriate for implementing a browser back button?

stack

32
New cards

What is the output of the following program? (deque example)

GFEDCBAABCDEFG

33
New cards

What property of the binary search algorithm hints that its performance is ( O(lgN) )?

At each iteration of the loop

34
New cards

What is the time complexity of binary search using an ( O(N) ) operator[]?

( O(NlgN) )

35
New cards

What is the worst-case execution time of bubble sort?

( O(N^2) )

36
New cards

What is the worst-case execution time of binary search?

( O(lgN) )

37
New cards

SELECT ALL: For binary search

which computes the midpoint?

38
New cards

SELECT ALL: True statements about Ordered Linked Lists vs. Unordered Linked Lists

The search method in OLL can stop early

39
New cards

SELECT ALL: True statements about bubble sort

Short bubble is efficient for nearly sorted arrays

40
New cards

What situation might cause binary search to degenerate in performance?

if the keys are all the same value

41
New cards

SELECT ALL: Conditions for using binary search

Data sorted in ascending/descending order

42
New cards

Which improvement does another_bubble() function make?

decreases the window of swapping to the highest value swapped on the previous pass

43
New cards

SELECT ALL: Why avoid binary search on singly linked lists?

Midpoint cannot be found in constant time

44
New cards

Suppose ( f(N) = O(h(N)) ) and ( g(N) = O(h(N)) ). Is ( f(N) \cdot g(N) = O(h(N))? )

no

45
New cards

Time complexity of find() in unordered linked list?

( O(N) )

46
New cards

Time complexity of nested loops (i=0 to N

j=0 to N)?

47
New cards

Time complexity of insert() in unordered array list?

( O(1) )

48
New cards

Time complexity of insert() in unordered linked list?

( O(1) )

49
New cards

Time complexity of remove() in unordered linked list?

( O(N) )

50
New cards

Is ( f(N) + g(N) = O(h(N)) )?

yes

51
New cards

Time complexity of find() in unordered array list?

( O(N) )

52
New cards

Algorithm for find() in unordered linked lists?

sequential search

53
New cards

Where to insert for O(1) time in singly-linked list?

at the head

54
New cards

SELECT ALL: True statements about Unordered Linked List ADT

Requires helper class for list nodes

55
New cards

Best time complexity of remove() in unordered array list?

( O(1) )