Data Structures and Algorithms Quiz
15 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the name of the technique used to resolve collisions in a hash table?

  • Double Hashing
  • Linear Probing (correct)
  • Separate Chaining
  • Quadratic Probing
  • What happens when a collision occurs in a hash table?

  • Sequentially search the table until an empty location is found (correct)
  • The data is stored in a linked list
  • The hash function is re-run to generate a new index
  • The table is resized to accommodate more data
  • What is the primary goal of using a collision resolution technique in a hash table?

  • To optimize the search time for a specific key
  • To reduce the memory usage of the hash table
  • To minimize the number of collisions (correct)
  • To maximize the number of collisions
  • Which of the following is NOT a collision resolution technique used in hash tables?

    <p>Bubble Sort</p> Signup and view all the answers

    What is the name of the technique that uses a sequence of probes to find an empty slot in a hash table?

    <p>Linear Probing</p> Signup and view all the answers

    What is the goal of the greedy algorithm in the coin-changing problem?

    <p>To make change with the minimum number of coins</p> Signup and view all the answers

    What is the condition for adding a coin to the set in the greedy algorithm?

    <p>The coin should not go over the required amount</p> Signup and view all the answers

    What is the running time of a job in the scheduling problem?

    <p>Known</p> Signup and view all the answers

    What is the goal of the scheduling problem?

    <p>To minimize the average completion time</p> Signup and view all the answers

    What is the optimal schedule in the scheduling problem?

    <p>A schedule arranged by shortest job first</p> Signup and view all the answers

    What is the assumption in the nonpreemptive scheduling?

    <p>Once a job is started, it must run to completion</p> Signup and view all the answers

    How many jobs are there in the scheduling problem?

    <p>N</p> Signup and view all the answers

    What is the average completion time of Schedule #1?

    <p>25</p> Signup and view all the answers

    What is the average completion time of Schedule #2?

    <p>17.75</p> Signup and view all the answers

    What is the notation used to represent the jobs in the schedule?

    <p>ji1, ji2, ..., jiN</p> Signup and view all the answers

    Study Notes

    Data Structures and Algorithms

    • Hashing is a technique that uses a key to find or store an item in a data structure.

    Sorting Algorithms

    • Arranging a group of items into a defined order based on a particular criteria is called sorting.

    Hash Table Operations

    • When a collision occurs, sequentially searching the table until an empty location is found is known as Linear Probing.

    Graph Theory

    • In a direct graph, if there is a path from every vertex to every other vertex, the graph is called Strongly Connected.

    Sorting Algorithms

    • Mergesort has a worst-case running time of O(N log N).
    • Insertion sort is a solution that sorts a list of items by repeatedly inserting a new element into a sorted sublist.

    Hash Table Operations

    • Linear Probing is a solution that sequentially searches the table until an empty location is found when a collision occurs.

    Hash Table and Hash Function

    • To insert an object in a hash table, compute its hash code, check if it exists in the appropriate list, and if not, insert it at the front of the list.
    • The need to use linked lists slows down the algorithm, and another data structure is required to be implemented.

    Open Addressing

    • Linear Probing: when a collision occurs, sequentially search the table until an empty location is found.
    • Quadratic Probing: uses a collision resolution technique to avoid primary clustering found with linear probes.
    • Double Hashing: when a collision occurs, a second hash function is used.

    Linear Probing Example

    • When a collision occurs, sequentially search the table until an empty location is found.
    • Example: the hash function hashes the key 343-567 (SEU Dammam Branch) into index #4, which is already occupied by the key 343-567 (SEU Medina Branch).
    • Solution: sequentially search for an empty location (index #5 is occupied!).

    Quicksort

    • Steps to conduct the quicksort algorithm:
      • Select one element in the list to be the partition element (pivot).
      • Move all elements that are less than the partition element to the left, and all elements that are greater than the partition element to the right.
      • Repeat steps 1 to 3 (recursively) on both partitions.
      • Concatenate both partitions and the pivot until concatenating all list items.
    • Quicksort has an advantage over Mergesort, where no temporary array is needed.

    Topological Sort

    • In a directed acyclic graph, a topological sort is an ordering of vertices such that if there is a path from vi to vj, then vj appears after vi in the ordering.
    • If a graph has a cycle, a topological ordering is not possible.
    • To find a topological ordering:
      • Find any vertex with no incoming edges.
      • Print this vertex, and remove it and its edges from the graph.
    • Indegree of a vertex v is the number of edges (u, v).
    • findNewVertexOfIndegreeZero method: searches for a vertex with indegree 0, a vertex that has not already been assigned a topological number.

    Shortest-Path Algorithms

    • Examining various shortest-path problems:
      • Input: a weighted graph with a cost ci,j associated with each edge (vi,vj) to traverse the edge.
      • The cost of a path (v1v2...vN) is called the weighted path length.
    • Input: an unweighted graph:
      • The cost of a path is called the unweighted path length, which is the number of edges on the path.
    • The shortest path is the least number of edges between the two vertices.

    Coin-Changing (Greedy Algorithms)

    • Making the exact change with the minimum number of coins.
    • Procedure to apply greedy algorithms:
      • Add the largest coin possible into an empty set.
      • Condition: the coin should not go over the required amount.
    • To make change of 2.72 SAR, start with the largest coin possible and add it into an empty set.

    Simple Scheduling Problem (Greedy Algorithms)

    • Suppose we are given jobs j1,j2,...,jN, all with known running times t1,t2,...,tN, respectively.
    • Our goal is to find the best way to schedule these jobs in order to minimize the average completion time.
    • Assumption: Once a job is started, it must run to completion (nonpreemptive scheduling).
    • The optimal schedule can be obtained by arranging the jobs in the order of their shortest running times.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    IT245_Final_Review.pdf.pdf

    Description

    Test your knowledge of data structures and algorithms, including hashing, sorting, and graph theory.

    More Like This

    Use Quizgecko on...
    Browser
    Browser