TRANSLATE THIS PSEUDO CODE INTO JAVA. A high-level algorithm for the traceFile method is given below: Initialize
Fantastic news! We've Found the answer you've been seeking!
Question:
TRANSLATE THIS PSEUDO CODE INTO JAVA.
Transcribed Image Text:
A high-level algorithm for the traceFile method is given below: Initialize stack to an empty stack of CodeBlocks. Open file using filename. while file has lines line = next line in file. if line is not empty and line does not start with '#' indents = number of spaces in line / SPACES_COUNT. while indents is less than size of stack if indents is 0 Close file and return the total complexity of stack.top. else old Top stack.pop() old TopComplexity = total complexity of old Top if oldTopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = old TopComplexity if line contains a keyword keyword=keyword in line. if keyword is "for" Determine the complexity at end of line ("N:" or "log_N: ") Create new 0(n) or 0(log(n)) CodeBlock and push onto stack. else if keyword is "while" else loopVariable = variable being updated (first token after "while"). Create new 0(1) CodeBlock with loopVariable and push onto stack. else Create new 0(1) CodeBlock and push onto the stack. else if stack.top is a "while" block and line updates stack.top's loopVariable Update the blockComplexity of stack.top. Ignore line. while size of stack > 1 oldTop stack.pop() oldTopComplexity = total complexity of oldTop if old TopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = oldTopComplexity Return stack.pop(). A high-level algorithm for the traceFile method is given below: Initialize stack to an empty stack of CodeBlocks. Open file using filename. while file has lines line = next line in file. if line is not empty and line does not start with '#' indents = number of spaces in line / SPACES_COUNT. while indents is less than size of stack if indents is 0 Close file and return the total complexity of stack.top. else old Top stack.pop() old TopComplexity = total complexity of old Top if oldTopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = old TopComplexity if line contains a keyword keyword=keyword in line. if keyword is "for" Determine the complexity at end of line ("N:" or "log_N: ") Create new 0(n) or 0(log(n)) CodeBlock and push onto stack. else if keyword is "while" else loopVariable = variable being updated (first token after "while"). Create new 0(1) CodeBlock with loopVariable and push onto stack. else Create new 0(1) CodeBlock and push onto the stack. else if stack.top is a "while" block and line updates stack.top's loopVariable Update the blockComplexity of stack.top. Ignore line. while size of stack > 1 oldTop stack.pop() oldTopComplexity = total complexity of oldTop if old TopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = oldTopComplexity Return stack.pop(). A high-level algorithm for the traceFile method is given below: Initialize stack to an empty stack of CodeBlocks. Open file using filename. while file has lines line = next line in file. if line is not empty and line does not start with '#' indents = number of spaces in line / SPACES_COUNT. while indents is less than size of stack if indents is 0 Close file and return the total complexity of stack.top. else old Top stack.pop() old TopComplexity = total complexity of old Top if oldTopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = old TopComplexity if line contains a keyword keyword=keyword in line. if keyword is "for" Determine the complexity at end of line ("N:" or "log_N: ") Create new 0(n) or 0(log(n)) CodeBlock and push onto stack. else if keyword is "while" else loopVariable = variable being updated (first token after "while"). Create new 0(1) CodeBlock with loopVariable and push onto stack. else Create new 0(1) CodeBlock and push onto the stack. else if stack.top is a "while" block and line updates stack.top's loopVariable Update the blockComplexity of stack.top. Ignore line. while size of stack > 1 oldTop stack.pop() oldTopComplexity = total complexity of oldTop if old TopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = oldTopComplexity Return stack.pop().
Expert Answer:
Answer rating: 100% (QA)
This algorithm is used to analyze a file containing code and determine the complexity of each block ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
When my niece Michelle told me she had learned to read, she was bursting with pride. How might reflecting on this accomplishment affect how Michelle thinks about herself?
-
What concerns must the organization address with regard to data security?
-
What are the gaps that can occur in service quality, and what are the steps that service marketers can take to close them?
-
In an air standard diesel cycle, the temperatures at the start and at the end of compression stroke are \(298 \mathrm{~K}\) and \(800 \mathrm{k}\), respectively. The energy added at constant pressure...
-
The board of directors of Swogen Company authorized the president to lease a corporate jet to facilitate her travels to domestic and international subsidiaries of the company. After extensive...
-
Greer Utsey earned $47,500 in 2022 for a company in Kentucky. Greer is single with one dependent under 17 and is paidweekly. The FUTA rate in Kentucky for 2022 is 0.6 percent on the first $7,000 of...
-
Funtime, Inc., manufactures video game machines. Market saturation and technological innovations caused pricing pressures that resulted in declining profits. To stem the slide in profits until new...
-
Natasha is a dangerous criminal who is being held at Asgard police station following her arrest. PC Banner, a newly qualified police officer, doesn't lock the door to Natasha's cell properly,...
-
How does an understanding of the value chain help explain how business models emerge?
-
What is meant by the term resource leverage? How does an understanding of this term help a firm exploit new product or service opportunities?
-
What is meant by the term strategic asset? Provide examples of the strategic assets of three well-known firms.
-
Describe the two potential pitfalls of using a team to start a firm.
-
A potential candidate in the third borough conducted a poll to decide whether he should challenge the incumbent. From a previous poll, he knows that the current incumbent has the support of 45% of...
-
From the NIPP of 2013, what is meant by Partnership Structure? Give an example. Choose one of the 16 Critical Infrastructure Sectors and comment on its Sector-Specific Plan. What other sectors is it...
-
Read the case study Richter: Information Technology at Hungarys Largest Pharma and answer the following question: How does the organization ensure the accuracy of the data it stores?
-
Bev and Ken Hair have been married for 3 years. They live at 3567 River Street, Springfield, MO 63126. Ken is a full-time student at Southwest Missouri State University (SMSU) and Bev works as an...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-4. Ivan and Irene paid the following in 2012 (all by check or can otherwise be...
-
In 2012, Michael has net short-term capital losses of $2,000, a net long-term capital loss of $45,000, and other ordinary taxable income of $45,000. a. Calculate the amount of Michael's deduction for...
-
See the option quote on IBM from the CBOE Web site on the next page showing options expiring in March and April 2022. a. Which option contract had the most trades that day? b. Which option contract...
-
You are an options dealer who deals in non-publicly traded options. One of your clients wants to purchase a one-year European call option on HAL Computer Systems stock with a strike price of \($20.\)...
-
It is February 21, 2022, and you have decided to purchase 10 June call contracts on eBays stock with an exercise price of \($57.50.\) Because you are buying, you must pay the ask price. How much...
Study smarter with the SolutionInn App