0% found this document useful (0 votes)
54 views4 pages

Tidily

This document contains a midterm exam for a data structures course. It has 3 parts: 1) Multiple choice questions about stacks, queues, and infix to postfix notation conversion. 2) Short answer and coding problems involving linked lists, palindromes, and stack contents for a given sequence. 3) Students must solve just one of two longer coding problems involving queues.

Uploaded by

shahwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views4 pages

Tidily

This document contains a midterm exam for a data structures course. It has 3 parts: 1) Multiple choice questions about stacks, queues, and infix to postfix notation conversion. 2) Short answer and coding problems involving linked lists, palindromes, and stack contents for a given sequence. 3) Students must solve just one of two longer coding problems involving queues.

Uploaded by

shahwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Çankaya University

Department of Computer Engineering


CENG 218 Data Structures
Midterm 1
Instructor: Abdulkadir GORUR

Time Allowed: 100 minutes Date: 7 / 04 / 2005

Name and Surname :……………………………………………………………………

Student Number :…………………………………

 Write CLEARLY and tidily


 Read the questions carefully.

 Spend your first 5 minutes to read all questions.(Extra 5 minutes is given


for this purpose)

Part I(Multiple Choice )25p

Q1 Which of the following stack operations could result in stack underflow?


a) is_empty
b) pop
c) push
d) Two or more of the above answers

Q2 Consider the following pseudocode:


declare a stack of characters
while ( there are more characters in the word to read )
{
read a character
push the character on the stack
push the character on the stack
}
while ( the stack is not empty )
{
pop a character off the stack
write the character to the screen
}
What is written to the screen for the input "carpets"?
a) sstteepprraacc
b) carpets
c) steprac
d) ccaarrppeettss

Sayfa 1 / 4
Q3 Here is an INCORRECT pseudocode for the algorithm which is supposed to determine whether a
sequence of parentheses is balanced:
declare a character stack
while ( more input is available)
{
read a character
if the character is a '('
push it on the stack
else if the character is a ')' and the stack is not empty
pop a character off the stack
else
print "unbalanced" and exit
}
print "balanced"
Which of these unbalanced sequences does the above code think is balanced?
a) ((())
b) ())(()
c) (()()))
d) (()))()

Q4 Here is an infix expression: 4+3*(6*3-12). Suppose that we are using the usual Stack algorithm to
convert the expression from infix to postfix notation. What is the maximum number of symbols that
will appear on the stack AT ONE TIME during the conversion of this expression?
a) 1
b) 2
c) 3
d) 4
e) 5

Part II (Solve all questions)

Q1)Following pictures a linked listed based on array. (15p)

Info Link
Head 0 C 6
3 1 B 0
2 5
3 A 1
Avail 4 F -1
2 5 -1
6 D 7
7 E 4 Info Link
Head 0
1
2
3
Avail 4
5
6
7
1. Find the sequence of characters in the list.(5 P)
2. Suppose Z is inserted at the beginin of the list later F then C are deleted from the list
and G is inserted at the beginning of the list. Find the final structure.(Use following
figure to give your answer) (10p)

Sayfa 2 / 4
Q2) A palindrome is a string that reads the same both forward and backward. For
example
"bob" "otto" "1991" "x" "live dual - laud evil" are all palindromes, but "teeth" is not.
Write a C function that takes a string as an argument and (1) if the string is a
palindrome prints it and returns 1 else (2) returns 0. Use this function to write a
program that will accept a sequence of lines, print those that are palindromes, and
finally print the number of palindromes found. (10p)

Q3) Give the contents of the stack after each operation in the sequence
EAS*Y**QUE***ST***I*ON**
Here a letter means “push" the letter, and “*" means “pop." (20p)

Sayfa 3 / 4
Part III (Solve Only ONE question)

Q4) Write a function that takes a char queue q as an argument, where the queue contains a selection of
symbols “a,………,z” and some ‘+’ symbols. The function should print to the screen the two
characters that precede (come before) every occurrence of ‘+’ in the queue. For example, if q
contains {a,b,c,+,e,e,e,+,f,g,+,p} then “cbeegf” should be printed to the screen. Assume that at least
2 alphabet symbols precede each ‘+’ symbol. (use only valid queue operations) (45 P)

a b c + e e e + f g + p
Front Rear

Q5) Consider the following queue.  Write a function to remove the repeated symbols from queue.
Don’t use array(Assume queue operations isEmpty, delete, and append are available)
(35P)Consider following example, If input Queue is;

1 1 4 1 1 2 8 3 8 9 9 9 7 5 9 7 0 6 5 3 9
Fron Rea
t r

Output Queue is;

4 2 0 6
Front Rear

Sayfa 4 / 4

You might also like