Systems Architecture
Systems Architecture
7th Edition
ISBN: 9781305080195
Author: Stephen D. Burd
Publisher: Cengage Learning
bartleby

Concept explainers

Question
Book Icon
Chapter 3, Problem 2PE
Program Plan Intro

Inserting an element to array

Program Plan:

  • Include required header files.
  • Declare an array with the size “100”.
  • Declare an integer variable “top_value” to store the index of last inserted element.
  • Define the function “insert_in_array()” with two parameters “element” and “position”. This function is used to insert an element to specified position of an array.
    • Declare required variable.
    • Check condition for “position”. If “position” is less than “0” or “position” is greater than “top_value”, then display an error message.
    • Otherwise, that is if the position is in the range.
      • Insert an element one by one in the specified position using “for” loop.
        • Shift elements by “1” position to the right.
      • Insert the element at the desired location.
      • Increment the value of “top_value” by “1”.
  • Define the function “display_array()” which is used to display the elements in the array.
    • Declare required variables.
    • If the “top_value” is equal to “0” that is there is no element in the array, then display an error message.
    • Otherwise, display all elements in the array.
  • Define main function.
    • Declare required variables.
    • Set “top_value” to “0”.
    • Performs “do-while” loop. This loop will perform until the user enters the choice “3”.
      • Display menu options to user.
      • Read choice from user.
      • Check user entered option using “switch” statement.
        • If the user entered option is “1”, then
          • Read the position for element from user.
          • Read an element for given position from user.
          • Call the function “insert_in_array()” with argument “insert_element” and “idx”.
            • If user entered option is “2”, then display the array elements by calling the function “display_array()”.

Blurred answer
Students have asked these similar questions
Design a dynamic programming algorithm for the Longest Alternating Subsequence problem described below: Input: A sequence of n integers Output: The length of the longest subsequence where the numbers alternate between being larger and smaller than their predecessor The algorithm must take O(n²) time. You must also write and explain the recurrence. Example 1: Input: [3, 5, 4, 1, 3, 6, 5, 7, 3, 4] Output: 8 ([3, 5, 4, 6, 5, 7, 3, 4]) Example 2: Input: [4,7,2,5,8, 3, 8, 0, 4, 7, 8] Output: 8 ([4, 7, 2, 5, 3, 8, 0,4]) (Take your time with this for the subproblem for this one)
Design a dynamic programming algorithm for the Coin-change problem described below: Input: An amount of money C and a set of n possible coin values with an unlimited supply of each kind of coin. Output: The smallest number of coins that add up to C exactly, or output that no such set exists. The algorithm must take O(n C) time. You must also write and explain the recurrence. Example 1: Input: C24, Coin values = = [1, 5, 10, 25, 50] Output: 6 (since 24 = 10+ 10+1+1 +1 + 1) Example 2: Input: C = 86, Coin values = [1, 5, 6, 23, 35, 46, 50] Output: 2 (since 86 = 46+35+5)
Design a dynamic programming algorithm for the Longest Common Subsequence problem de- scribed below Input: Two strings x = x1x2 xm and y = Y1Y2... Yn Output: The length of the longest subsequence that is common to both x and y. . The algorithm must take O(m n) time. You must also write and explain the recurrence. (I want the largest k such that there are 1 ≤ i₁ < ... < ik ≤ m and 1 ≤ j₁ < ... < jk ≤ n such that Xi₁ Xi2 Xik = Yj1Yj2 ··· Yjk) Example 1: Input: x = 'abcdefghijklmnopqrst' and y = 'ygrhnodsh ftw' Output: 6 ('ghnost' is the longest common subsequence to both strings) Example 2: Input: x = 'ahshku' and y = ‘asu' Output: 3 ('asu' is the longest common subsequence to both strings)

Chapter 3 Solutions

Systems Architecture

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT