Information Technology Department
كلية الصناعة والطاقة جامعة برج العرب التكنولوجية
2rd Year
LECTURERs : Dr. Eman Shawky COURSE : Data Structure
TAs: Eng. Mostafa Elmansy, Eng. Mohamed Ehab, Eng. Mena allah Semester : Spring 2024-2025
Ashraf
Sheet 3 (Stack)
Choose the correct answer:
1. What is the primary factor in determining the performance of a programming
algorithm?
a) Space and Time
b) CPU Type
c) Programming Language
d) Number of Functions
2. Which of the following time complexities represents the best performance as input
size grows?
a) O(n^2)
b) O(n log n)
c) O(2^n)
d) O(log n)
3. If a loop runs by multiplying the counter by 2 each time, the complexity is:
a) O(n)
b) O(n^2)
c) O(log n)
d) O(n log n)
Information Technology Department
كلية الصناعة والطاقة جامعة برج العرب التكنولوجية
2rd Year
4. What is the property of a stack?
a) First In, First Out (FIFO)
b) Last In, First Out (LIFO)
c) Both A and B
d) None of the above
5. In a singly linked list, each node contains:
a) Only data
b) Data and a pointer to the next node
c) Data and pointers to both the next and previous nodes
d) A pointer to the previous node only
6. What is a key advantage of a linked list over an array?
a) Uses less memory than arrays
b) Allows dynamic memory allocation and efficient insertions/deletions
c) Faster for accessing elements at any index
d) Cannot store large data structures
7. What is the purpose of a linked list's head pointer?
a) Points to the last node
b) Points to the first node
c) Points to the middle node
d) Holds the number of nodes
8.Convert the following infix expression to prefix: (A+B)∗C
a) * + A B C
b) A B + C *
Information Technology Department
كلية الصناعة والطاقة جامعة برج العرب التكنولوجية
2rd Year
c) + A B * C
d) * A B + C
9. Convert the following infix expression to postfix: A+(B−C)∗D
a) A B C - D * +
b) A B + C D * -
c) A B C D * - +
d) A B - C D * +
10.Evaluate the following postfix expression: 5 6 + 2 *
a) 10
b) 11
c) 22
d) 17
12.What is an advantage of a doubly linked list over a singly linked list?
a) Requires less memory
b) Can be traversed in both directions
c) Uses fewer pointers per node
d) Does not require a head pointer
13.Which data structure is most suitable for implementing recursion?
a) Queue
b) Stack
c) Array
d) Linked List
Information Technology Department
كلية الصناعة والطاقة جامعة برج العرب التكنولوجية
2rd Year
14.What is a circular linked list?
a) A list where the last node points to NULL
b) A list where the last node points to the head
c) A list that only supports FIFO operations
d) A list that automatically sorts elements
15.What is the main difference between an array and a linked list in terms of memory
allocation?
o a) Arrays use dynamic allocation, linked lists use static allocation
o b) Arrays have fixed size, linked lists are dynamic
o c) Arrays are more memory-efficient than linked lists
o d) Linked lists store elements contiguously
Postfix and Prefix Problems:
Convert the following infix expression to postfix:
(A+B)∗(C−D)/E
Convert the following infix expression to prefix:
A∗(B+C)−D/E
Evaluate the following postfix expression:
62/3−42∗+
Evaluate the following prefix expression:
−∗54+32
Information Technology Department
كلية الصناعة والطاقة جامعة برج العرب التكنولوجية
2rd Year
Solutions for Postfix and Prefix Problems
1. Convert Infix to Postfix:
Expression:
(A+B)∗(C−D)/E
Steps:
• Solve the inner parentheses: A+B → AB+
• Solve the other parentheses: C−D → CD-
• Multiply the results: AB+CD−∗
• Divide by E: AB+CD−∗E/
Final Answer:
AB+CD−∗E/
2. Convert Infix to Prefix:
Expression:
A∗(B+C)−D/E
Steps:
• Solve the inner parentheses: B+C → +BC
• Multiply: A∗(B+C) → ∗A+BC
• Divide: D/E → /DE
• Subtract the results: −∗A+BC/DE
Final Answer:
−∗A+BC/DE
3. Evaluate the Postfix Expression:
Expression:
62/3−42∗+
Steps:
1. 6 ÷ 2 = 3
2. 3 - 3 = 0
3. 4 × 2 = 8
4. 0 + 8 = 8
Final Answer:
8
Information Technology Department
كلية الصناعة والطاقة جامعة برج العرب التكنولوجية
2rd Year
4. Evaluate the Prefix Expression:
Expression:
−∗54+32
Steps:
1. Multiply 5 × 4 = 20
2. Add 3 + 2 = 5
3. Subtract 20 - 5 = 15
Final Answer:
15