Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE ANSWER IN JAVA QUESTIONS 1 & 3 IS ONE QUESTION I WILL UPVOTE IF CORRECT!!! 1. Using your favorite programming language (Java is suggested),

PLEASE ANSWER IN JAVA

image text in transcribed

image text in transcribed

QUESTIONS 1 & 3 IS ONE QUESTION

I WILL UPVOTE IF CORRECT!!!

1. Using your favorite programming language (Java is suggested), design and implement a stack on an array. Implement the following operations: push, pop, top, size, isEmpty. Make sure that your program checks whether the stack is full in the push operation, and whether the stack is empty in the pop operation. Practical application 2: Context-free language recognizer. (a) Design an algorithm that recognizes (accepts) strings of the following context-free language: L={0n1n : where n1}. That is, strings that contain a number of zeros followed by the same number of ones. Examples of strings in the language are: 01,0011,000111, etc. Strings that are not in the language are, for example, 10, 00, 111, 1100, 0101, and many more. The algorithm should take a string of 0's and 1's as input and output "Yes" if the string belongs to the language, and "No" if the string doesn't belong to the language. The algorithm should use a stack. When it reads a 0 from the string, it pushes 0 onto the stack. When it reads a 1 , it checks if the stack has a 0 , in which case that 0 is popped from the stack. When the stack is empty and the end of the string is reached, the string is recognized as correct (Yes). Otherwise, the string is not in the language (No). (b) Implement the algorithm of (a) in your favorite programming language and run it on different strings as follows: 01, 000111, 00000001111111, and 10,00, 00111, 0101, and others. (c) Consider an input string of size n : (i) what is the worst-case time that your algorithm takes to decide whether or not the string belongs to the language? (ii) Why? Give your answers in terms of the O-notation. (d) [ Optional] Run your algorithm on strings of lengths n=2,4,8,16,32,,220. Compute the running time in nanoseconds and draw a table with the results. Draw a table or a plot of the results for different values of n and compare the results obtained with the complexity you found in (c). Note: if all (or most of) the running times become 0 , try running the program 1,000 times and compute the average

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions