Data Structures Exam Questions and Solutions

Multiple Choice Questions

  1. Computer algorithms refer to:
    A. Calculation methods
    B. Problem-solving steps
    C. Sorting methods
    D. Scheduling methods
    Answer: B
  2. Comparde to linked lists, sequential lists:
    A. Allow easier random access
    B. Have more scatterde physical storage
    C. Enable simpler insertions/deletions
    D. Better fit linear logical structures
    Answer: A
  3. When inserting an element at position i (1≤i≤n+1) in a sequential list of length n, how many elements need to be shifted?
    A. n-i
    B. n-i-1
    C. n-i+1
    D. n+i
    Answer: C
  4. When deleting from a sequential list, all subsequent elements must:
    A. Shift forward from back to front
    B. Shift forward from front to back
    C. Shift backward from back to front
    D. Shift backward from front to back
    Answer: A

True/False Questions

  1. All elements in a linear list have both preedcessor and successor elements.
    Answer: False
  2. Stacks and queues can only be implemented using linked storage.
    Answer: False
  3. Search and modify are basic operations on arrays.
    Answer: True

Algorithm Implementation

1. Linked List Deletion

void delete(LinkList *head, int max, int min) {
    LinkList *p, *q;
    q = head;
    p = head->next;
    while (p != NULL) {
        if (p->data <= min || p->data >= max) {
            q = p;
            p = p->next;
        }
        else {
            q->next = p->next;
            free(p);
            p = q->next;
        }
    }
}

2. Binary Search Tree Minimum Value

ElemType FindMax(BTreeNode *BST) {
    BTreeNode *t;
    if(BST == NULL) {
        printf("Cannot find min in empty tree!\n");
        return;
    }
    t = BST;
    while(t->left != NULL)
        t = t->left;
    return t->data;
}

3. Graph Path Detection

int exist_path_DFS(vexnode ga[], int i, int j) {
    edgenode *p;
    if(i == j) return 1;
    else {
        visited[i] = 1;
        p = ga[i]->link;
        while(p != NULL) {
            if(visited[p->adjvex] == 0 && 
               exist_path_DFS(ga, p->adjvex, j))
                return 1;
            p = p->next;
        }
    }
    return 0;
}

Tags: data-structures algorithms binary-trees linked-lists graph-theory

Posted on Sat, 30 May 2026 22:33:26 +0000 by KefkaIIV