Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 111 In-class Exam 1 - Sample Questions and Answers, Exams of Data Structures and Algorithms

Sample questions and answers for an in-class exam on data structures, specifically focusing on stacks, for a university-level computer science course. The questions include processing a postfix expression, writing a function to copy a stack, analyzing program output, drawing pictures of linked lists, and implementing a method for stack equality.

Typology: Exams

2012/2013

Uploaded on 04/07/2013

sethuraman_h34rt
sethuraman_h34rt 🇮🇳

4.3

(8)

159 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name:___________________________________
CS 111: Data Structures
In-class EXAM #1 – Sample Questions
Do not open this exam until we instruct you to do so.
This is a closed book, closed notes, closed electronics, closed neighbor, pencil and
paper exam.
This exam is designed to be completed in 50 minutes. However, you may take
120 minutes to work on the questions. You must immediately turn in the exam
when we call for it.
Write answers in the spaces provided. Indicate your final answer clearly. Cleanly
erase or cross out any work you do not want graded. Show your work and explain
your reasoning where appropriate; this will help to earn partial credit.
Backpacks must be left at the front of the room.
Electronic devices of any kind, including cell phones and calculators, must be
completely turned off and stowed in your backpack.
The exam must be written with a pencil.
1
pf3
pf4
pf5

Partial preview of the text

Download CS 111 In-class Exam 1 - Sample Questions and Answers and more Exams Data Structures and Algorithms in PDF only on Docsity!

Name:___________________________________

CS 111: Data Structures

In-class EXAM #1 – Sample Questions

• Do not open this exam until we instruct you to do so.

• This is a closed book, closed notes, closed electronics, closed neighbor, pencil and

paper exam.

• This exam is designed to be completed in 50 minutes. However, you may take

120 minutes to work on the questions. You must immediately turn in the exam

when we call for it.

• Write answers in the spaces provided. Indicate your final answer clearly. Cleanly

erase or cross out any work you do not want graded. Show your work and explain

your reasoning where appropriate; this will help to earn partial credit.

• Backpacks must be left at the front of the room.

• Electronic devices of any kind, including cell phones and calculators, must be

completely turned off and stowed in your backpack.

• The exam must be written with a pencil.

Question 1

We use a stack to evaluate postfix expressions. Below is an expression consisting of 13 tokens. Show

the contents of the stack after each token is processed. Your answer should therefore consist of 13

pictures of the stack..

Question 3 :

Tell what is output by the following program.

#include using namespace std; void mystery(char c, int & v) { cout << v cout << "..." << c; v = v 1; c = 'A'; } int main() { int x = 3; string s = "Hello"; for (int i=0;i<x;i++) mystery(s[i],x); cout << endl; cout << s << endl; }

Question 4

A. Assume a linked list structure containing integers. Draw a picture of the structure this code

generates.

int main() { Node *nodes[ 4 ]; for (size_t i=0;i< 4 ;i++) { nodes[i] = NULL; for (size_t j=1;j<=i;j++) { Node *temp = new Node; temp>data = j; temp>next = nodes[i]; nodes[i] = temp; } } }

B. Now assume the following structure:

struct Dnode { Dnode * prev; int data; Dnode *next; };

Write a code fragment that generates this picture.