Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Stacks and Queues

1. Use a stack or a queue (or both!) to determine if a given input is a palindrome or not.
2. Evaluate an infix expression using a stack or a queue (or both!)

Queues
You own a car wash and would like to implement a program to keep up with the queue of cars waiting.

When you open your car wash (at the start of the program), your queue is empty.

Once the cars start coming, you add them to your queue. Every car has a make (string), a color (string)
and a plate number (int).

Once you finish washing a car you remove it from the queue and print all the information about the car.

If no more cars are waiting (the queue is empty), you close your program.

The program contains a menu with the following options:

1. To insert a car to the queue


2. To remove the car from the queue

When you want to add a car to the queue, you should also add the in

Inside class Queue, write the following functions:

 enqueue(c): Insert car cat the rear of the queue.


 dequeue(): Remove and return from the queue the car at the front
 size(): Return the number of cars in the queue.
 isEmpty(): Return a Boolean (True or False) value that indicates whether the queue is empty.
 front(): Return, but do not remove, the front car in the queue

Stack
You work for the MIB (men in black) and would like to decode the messages that they send you.

The message contains alphabetical characters, white spaces, and Asterix.

To decode the message, you need a stack.

You start looping through the message pushing each alphabetical character and white space to your
stack. Once you reach an Asterix, you pop one character out of your stack.

Sometimes, you receive an incomplete message. Therefore, if you reach the end of the string and you
still have characters in your stack, pop all of them out.
An example of such decoding is:

Input: SIVLE ****** DAED TNSI ***

Output: ELVIS ISNT DEAD

Priority Queues
You work at the HR office of SE Factory and you would like to schedule the FSW interviews for the
students.
Each student has a name, a midterm grade (int value between 0 and 100), a final grade (int value
between 0 and 100), and a Boolean value that indicates if they have a good character or not.

You give the students priority based on the following criteria:

-first, you interview the students with good attitude. Among these students, you start with the one with
the highest grade on the final. If two students have the same grade on the final, you give priority to the
student with the highest midterm grade. If these students have the same midterm grade, you can
choose any one of them.

For example, if these were your students:

- Batoul, midterm grade: 60/100, final grade: 70/100, GoodAttitude: True


- Ali, midterm grade:100/100, final grade: 100/100, GoodAttitude: False
- Mazen: midterm grade:70/100, final grade: 70/100, GoodAttitude: True
- Faisal: midterm grade: 30/100, final grade: 80/100, GoodAttitude: True

You would interview them in the following order: Faisal, Mazen, Batoul, Ali.

Write a program with the following menu:

1. Add a student
2. Interview a student

In option 1, the user adds a student to the priority queue. You ask the user for the attributes of the
student and add them to the priority queue

In option 2, you print the name of the student the user should interview next.

Graphs
1. Given a graph where the nodes are cities and the edges are the routes connecting them. Write a
function that takes as input two cities and returns true if there is a route connecting them, false
otherwise.
Write another function that takes as input one city and prints all the other cities reachable from
it.
2. Given a graph, write a function that checks if the graph contains a cycle.
3. Given a graph that represents the Instagram social media app. The nodes there represent users,
and we connect user 1 to user 2 if user 1 follows user 2 (the graph is undirected).
Write a function that takes as input a two users and prints the list of users they both follow.
Write another function that prints the list of users none of them follow

Trees
1. Given a list of numbers, use a binary search tree to print these numbers in ascending order
2. A full binary tree is a tree where every node either contains two children, or is a leaf (so the
node either has exactly 2 children or 0). Write a function to check if a binary tree is full.
3. Given a binary search tree of integers, and an input integer i, return true if i is repeated multiple
times in the tree

You might also like