1. Home
  2. Explore
  3. Computer Science
  4. Stacks and Queues

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Stacks and Queues

  • 61Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Language Tradeoffs
Python is described as a
programming language compared with C.

61 questions

  1. 1
    Python is described as a
    _____
    programming language compared with C.
    Hint

    Think about which language hides more low-level implementation details.

    Answer

    higher level

  2. 2
    Compared with C, Python can often solve the same problems more quickly for
    _____
    , although the resulting code may not run as quickly.
    Hint

    Think about who benefits from writing fewer low-level instructions.

    Answer

    Humans

  3. 3
    The general theme involving choices such as speed, memory use, and programming effort is called
    _____
    .
    Hint

    A gain in one resource often requires sacrificing another.

    Answer

    trade-offs

  4. 4
    A data type defined by its operations and behavior rather than by its implementation details is an
    _____
    .
    Hint

    Focus on what a structure does, not how it is built internally.

    Answer

    abstract data type

  5. 5
    Stacks and queues can each be implemented in multiple ways because they are
    _____
    data types.
    Hint

    Their behavior is specified separately from their concrete memory layout.

    Answer

    abstract

  6. 6
    A concrete definition of how a program uses computer memory to lay out data is called a
    _____
    .
    Hint

    This term refers to an implementation rather than an abstract behavior.

    Answer

    data structure

  7. 7
    When programmers use a feature of Python, Java, or C++ that implements a familiar structure, they are usually benefiting from code written by
    _____
    .
    Hint

    High-level languages commonly provide prewritten implementations.

    Answer

    someone else

  8. 8
    The amount of memory used by a program is commonly called its
    _____
    cost.
    Hint

    This contrasts with the time required to run an algorithm.

    Answer

    space

  9. 9
    A queue is intended to provide a fairness property in which the person who enters first is served
    _____
    .
    Hint

    Think about ordinary lines at stores or events.

    Answer

    first

  10. 10
    The ordering property of a queue is abbreviated
    _____
    .
    Hint

    Expand the phrase as first in, first out.

    Answer

    FIFO

  11. 11
    The queue operation that adds an item to the line is called
    _____
    .
    Hint

    This is the operation analogous to getting in line.

    Answer

    NQ

  12. 12
    The queue operation that removes an item from the front of the line is called
    _____
    .
    Hint

    This is the operation analogous to getting out of line.

    Answer

    DQ

  13. 13
    A stack removes the item that was added most recently, giving it a
    _____
    property.
    Hint

    Expand the phrase as last in, first out.

    Answer

    LIFO

  14. 14
    The stack operation that places an item on the top is called
    _____
    .
    Hint

    Think of pushing a tray onto the top of a stack.

    Answer

    push

  15. 15
    The stack operation that removes an item from the top is called
    _____
    .
    Hint

    Think of taking the uppermost tray away.

    Answer

    pop

  16. 16
    A stack is convenient for objects such as cafeteria trays because gravity makes the
    _____
    item easiest to remove.
    Hint

    The bottom tray would require disturbing the trays above it.

    Answer

    top

  17. 17
    New email commonly appears at the
    _____
    of an inbox, illustrating LIFO behavior.
    Hint

    Recent messages are displayed before older messages by default.

    Answer

    top

  18. 18
    A fixed-size array requires its total size to be decided at
    _____
    time.
    Hint

    The size is hard-coded before the program runs.

    Answer

    compilation

  19. 19
    An array stores its values
    _____
    in memory.
    Hint

    The values are placed back to back.

    Answer

    contiguous

  20. 20
    The first element of a C array is located at index
    _____
    .
    Hint

    C arrays are zero indexed.

    Answer

    0

  21. 21
    The main limitation of a fixed-size array is that its capacity must be chosen
    _____
    .
    Hint

    This phrase means before the program runs or before compilation.

    Answer

    a priori

  22. 22
    Allocating too much unused array space wastes
    _____
    .
    Hint

    The unused locations still occupy computer storage.

    Answer

    memory

  23. 23
    The C function used to request a dynamically sized block of memory is
    _____
    .
    Hint

    Its name abbreviates memory allocation.

    Answer

    malloc

  24. 24
    The C function used to return dynamically allocated memory to the operating system is
    _____
    .
    Hint

    It reverses the ownership obtained through malloc.

    Answer

    free

  25. 25
    When malloc or realloc fails to allocate memory, it returns
    _____
    .
    Hint

    This value indicates that no valid address was returned.

    Answer

    NULL

  26. 26
    The function that can resize an existing dynamically allocated block is
    _____
    .
    Hint

    Its name combines reallocation with memory allocation.

    Answer

    realloc

  27. 27
    A temporary pointer is needed when using realloc so that a failure does not cause the program to lose the address of the
    _____
    block.
    Hint

    The old allocation must remain reachable if resizing fails.

    Answer

    original

  28. 28
    A memory leak occurs when a program loses track of an allocated block before calling
    _____
    on it.
    Hint

    The operating system cannot reclaim a block through the program if its address is lost.

    Answer

    free

  29. 29
    A linked list avoids the requirement that all values be
    _____
    in memory.
    Hint

    Its nodes may be located in separate regions of memory.

    Answer

    contiguous

  30. 30
    The extra information stored alongside a linked-list value to help connect nodes is called
    _____
    .
    Hint

    It is data that helps maintain the data of interest.

    Answer

    metadata

  31. 31
    A linked-list node usually contains data and a pointer to the
    _____
    node.
    Hint

    The pointer creates the path through the list.

    Answer

    next

  32. 32
    The pointer value used to mark the end of a linked list is
    _____
    .
    Hint

    It indicates that there is no subsequent node.

    Answer

    NULL

  33. 33
    A linked list can be represented by storing a pointer to its first node, commonly called
    _____
    .
    Hint

    This pointer serves as the entry point to the entire structure.

    Answer

    list

  34. 34
    The C operator that combines dereferencing a pointer with accessing a structure field is the
    _____
    operator.
    Hint

    It is written using two characters that visually resemble an arrow.

    Answer

    arrow

  35. 35
    Adding a new node to the beginning of a linked list is called
    _____
    the node.
    Hint

    The new node becomes the first node.

    Answer

    prepending

  36. 36
    Inserting a node at the end of a linked list is called
    _____
    it.
    Hint

    The new node follows the current final node.

    Answer

    appending

  37. 37
    With a linked list implementation that always prepends, insertion takes
    _____
    time.
    Hint

    The number of existing nodes does not affect the pointer updates at the front.

    Answer

    big O of 1

  38. 38
    Searching, traversing, and deleting in the discussed linked-list implementation each take
    _____
    time in the worst case.
    Hint

    The operation may need to examine every node.

    Answer

    big O of N

  39. 39
    A linked list with pointers in both directions is called a
    _____
    linked list.
    Hint

    The name contrasts with a singly linked list.

    Answer

    doubly

  40. 40
    A tree is a data structure with
    _____
    dimensions, unlike an array or linked list in the discussion.
    Hint

    It branches rather than forming one linear sequence.

    Answer

    two

  41. 41
    The top node of a tree is called the
    _____
    .
    Hint

    It is analogous to the top of a family tree.

    Answer

    root

  42. 42
    A node in a binary search tree has at most
    _____
    child pointers.
    Hint

    The structure distinguishes left and right children.

    Answer

    two

  43. 43
    In a binary search tree, every node is greater than its
    _____
    child and less than its right child.
    Hint

    Smaller values are placed on one particular side.

    Answer

    left

  44. 44
    The nodes at the edge of a tree that have no children are called
    _____
    .
    Hint

    The term is borrowed from real-world trees.

    Answer

    leaves

  45. 45
    Searching a balanced binary search tree takes
    _____
    time.
    Hint

    Each comparison approximately halves the remaining search space.

    Answer

    big O of log N

  46. 46
    If values are inserted into a binary search tree in an unfortunate order, the tree can degenerate into a
    _____
    .
    Hint

    Each node may end up with only one child.

    Answer

    linked list

  47. 47
    A binary search tree can be kept efficient by
    _____
    the tree after insertions or deletions.
    Hint

    The goal is to preserve logarithmic height.

    Answer

    rebalancing

  48. 48
    The recursive search function returns false immediately when the tree pointer is
    _____
    .
    Hint

    This represents an empty tree or a missing subtree.

    Answer

    NULL

  49. 49
    The theoretical goal of a search that takes the same number of steps regardless of data-set size is
    _____
    time.
    Hint

    This is represented by a flat running-time line.

    Answer

    constant

  50. 50
    Hashing maps values from an infinite domain to a
    _____
    range.
    Hint

    The outputs correspond to a limited number of buckets.

    Answer

    finite

  51. 51
    The function that maps an input key to a bucket is called a
    _____
    function.
    Hint

    It produces the location used by a hash table.

    Answer

    hash

  52. 52
    When different keys map to the same hash-table location, the situation is called a
    _____
    .
    Hint

    Multiple values are competing for one bucket.

    Answer

    collision

  53. 53
    A hash table combines an array with linked lists to handle multiple values in one bucket; this arrangement is called an array of
    _____
    .
    Hint

    Each array position points to a chain of nodes.

    Answer

    linked lists

  54. 54
    Using only the first letter of a name as a hash function produces
    _____
    possible buckets for the English alphabet.
    Hint

    Count the letters from A through Z.

    Answer

    26

  55. 55
    A hash function that uses the first three letters of names reduces collisions but requires
    _____
    memory.
    Hint

    There are many more possible combinations of three letters than single letters.

    Answer

    more

  56. 56
    A hash table with uniformly distributed keys can reduce a linked list of N items to chains averaging roughly N divided by K items, where K is the number of
    _____
    .
    Hint

    K represents the number of available hash locations.

    Answer

    buckets

  57. 57
    A trie is a tree made out of
    _____
    .
    Hint

    Each node contains one position for each possible next character.

    Answer

    arrays

  58. 58
    In a trie for English names, each node's character array has
    _____
    positions.
    Hint

    There is one position for each letter of the alphabet.

    Answer

    26

  59. 59
    A boolean marker in a trie indicates that a stored name
    _____
    at that node.
    Hint

    It distinguishes a complete word from merely a prefix.

    Answer

    ends

  60. 60
    Searching for a name in a trie takes a number of steps determined primarily by the name's
    _____
    rather than by the number of stored names.
    Hint

    The search follows one pointer for each character.

    Answer

    length

  61. 61
    The main trade-off of a trie is that it achieves fast lookup by using a large amount of
    _____
    .
    Hint

    Most character pointers in trie arrays may remain unused.

    Answer

    memory

1 of 61
Question 1 of 61

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent