Data Structure Chapter 1 Introduction Assignment (corrected)

True or False

The 1-1
data item is the smallest unit of data.

T F

Textbook P3

The 1-2
data element is the smallest unit of data.

T F

Textbook P3

1-3
The logical structure of data refers to the logical relationship between data items.

T F

Textbook P4: The logical structure of data refers to the logical relationship between
data elements ; data elements are the basic units of
data ; data items are the smallest units that make up data elements, have independent meanings, and are indivisible;
data objects are of the same nature The collection of data elements is a subset of the data;

1-4 The
concept of data structure includes three aspects: the logical structure between data, the way the data is stored in the computer, and the operation of the data.

TThe logical structure of F
Insert picture description here
1-5
data has nothing to do with the content and form of the data element itself.

T F

1-6
data elements can be composed of data items of different types.

T F

Textbook P3 refers to the definition of data elements and data items;

1-7
The logical structure of data describes the order relationship between data elements, which depends on the storage structure of the computer.

T F

Textbook P4: The logical structure of data describes the data from the logical relationship, it has nothing to do with the storage of the data, and is independent of the computer.

The 1-8
algorithm is independent of the specific programming language and has nothing to do with the specific computer.

T F


There is no difference between 1-9 algorithm and program, both are common in data structure.

T F

1-10
The pros and cons of the algorithm have nothing to do with the algorithm description language, but with the computer used.

T F

Textbook P11: Time complexity and space complexity are the two main indicators for measuring algorithms;

Multiple choice

2-1
The data elements processed by the computer are not isolated. They generally have a certain relationship with each other. The relationship between data elements is usually called

A. Rules
B. Structure
C. Set
D. Operation

Textbook P4: Data structure is a collection of data elements with "structure", and "structure" refers to the relationship that exists between data elements;

2-2 The
following statement about data structure is wrong ().

A. The data structure is the same, and the corresponding storage structure is also the same
B. The data structure involves three aspects: the logical structure of the data, the storage structure and the operations imposed on it.
C. The realization of the data structure operation is related to the storage structure
. D. The storage structure may not be considered when defining the logical structure.

The data structure is the same, the logical structure must be the same, but the realization of the logical structure can use different storage structures;

2-3 Which of the
following statements about data structure is correct is ().

A. The logical structure of the data structure is independent of its storage structure
B. The storage structure of the data structure is independent of the logical structure of the
data structure C. The logical structure of the data structure uniquely determines the storage structure of the
data structure D. The data structure is only determined by its logical structure and storage structure

B. Storage structure: The logical structure of data is realized by computer language;
C. The logical structure and storage structure of data are two closely related aspects of the data structure. The same logical structure can correspond to different storage structures;
D. Data structure concept Including three aspects: the logical structure between the data, the storage method of the data in the computer, and the calculation of the data;

Among
the data structures below 2-4 , () is a non-linear data structure.

A. Tree
B. String
C. Queue
D. Stack

Textbook P4-5:
The logical structure of data:
1. Linear structure: linear table, stack, queue, string, array, generalized table;
2. Non-linear structure: tree, binary tree, directed graph, undirected graph;

2-5
can logically divide the data structure into ().

A. Dynamic structure and static structure
B. Compact structure and non-compact structure
C. Internal structure and external structure
D. Linear structure and nonlinear structure

2-6
The following description of abstract data types is incorrect ().

A. Data encapsulation
B. Separation of use and realization
C. Information hiding
D. Use case driven

Textbook P7: Abstract data types are independent of specific implementations, encapsulating data and operations together, so that user programs can only access the data through certain operations defined by abstract data types, thereby realizing information hiding;

2-7
The time complexity of the following program is ().

for(i = 0; i < m; i++)
     for(j = 0; j < n; j++ )
          A[i][j] = i*j;

A.O(m^2​​)
B.O(n^​2​​)
C.O(m × n)
D.O(m + n)


The time complexity of the 2-8 algorithm is related to ().

A. Scale of the problem
B. The operating speed of computer hardware
C. The length of the source program
D. The quality of the executed program after compilation

Textbook P11: Regardless of environmental factors such as computer software and hardware, the main factor affecting the time cost of the algorithm is the problem scale;

2-9
The time complexity of an algorithm is O(n^2), indicating the algorithm's ().

A. The problem size is n​^2
B. The problem size is proportional
to n^​2 C. The execution time is equal to n^​2
D. Execution time is proportional to n​^2

2-10
Design data structure and algorithm

A. Data structure is program
B. Algorithm + data structure = program
C. Algorithm = data structure + program
D. Algorithm is program

Programming questions

7-1 Temperature conversion (5 points)

This question requires writing a program to calculate the Celsius temperature corresponding to a Fahrenheit temperature of 150°F. Calculation formula: C=5×(F−32)/9, where C represents temperature in Celsius, F represents temperature in Fahrenheit, and the output data is required to be integer.

Input format:
There is no input for this question.

Output format: output
in the following format

fahr = 150, celsius = 计算所得摄氏温度的整数值
public class Main {
    
    

	public static void main(String[] args) {
    
    
		int F = 150;
		int C;
		C = 5 * (F - 32) / 9;
		System.out.println("fahr = " + F + ", celsius = " + C);
	}
}

7-2 Four arithmetic of integers (10 points)

This question requires writing a program to calculate and output the sum, difference, product, and quotient of two positive integers. The question ensures that the input and output are all within the integer range.

Input format:
Input two positive integers A and B in one line.

Output format:
output sum, difference, product, and quotient in the order of the format "A operator B = result" in the 4 lines.

Input sample:

3 2

Sample output:

3 + 2 = 5
3 - 2 = 1
3 * 2 = 6
3 / 2 = 1
import java.util.Scanner;

public class Main {
    
    

	public static void main(String[] args) {
    
    
		Scanner input = new Scanner(System.in);
		int A = input.nextInt();
		int B = input.nextInt();
		int add = A + B;
		int minus = A - B;
		int multiply = A * B;
		int divide = A / B;
		System.out.println(A + " + " + B + " = " + add);
		System.out.println(A + " - " + B + " = " + minus);
		System.out.println(A + " * " + B + " = " + multiply);
		System.out.println(A + " / " + B + " = " + divide);
	}
}

7-3 Find the largest, second largest and third largest value (25 points)

This question requires reading in n integers, using the least number of comparisons, and outputting their maximum value, the second largest value, and the third largest value. For example, for the 6 numbers 13 13 1 10 34 10, the maximum value is 34, the second largest value is 13, and the third largest value is 10.

Input format:
There are two lines of input. The first line is the number of integers n (≤1 000 000), and the second line gives n integers separated by spaces.

Output format:
For each group of input, output the maximum value, the second largest value, and the third largest value in one line, separated by a space, but there is no extra space at the end of the line. If the input data is less than three, "Invalid Input" is output. If there is no third largest element, output "There is no third largest element". If there is no second largest and third largest value, output "There is no second largest and third largest element".

Input sample:

6
13 13 1 10 34 10 

Sample output:

34 13 10 
#include<bits/stdc++.h>
using namespace std;

#define Max 10000000 
int main(){
    
    
 long long int n;                
 long long int t,i;      
 long long int med=-Max,min=-Max;
 long long int max=-Max;         
 //如果输入的数字比-10000000还小怎么办??
 scanf("%lld",&n);
 if(n<3)
 {
    
    
  printf("Invalid Input");  
  return 0;
 }
 for(i=0;i<=n-1;i++) 
 {
    
    
  scanf("%lld",&t);
  if(t>max && t!=max && t!=min && t!=med)//首先先与最大的数字进行比较 
  {
    
    
   min=med;     
   med=max;  
   max=t; 
   continue; 
  } 
  if(t>med && t!=max && t!=min && t!=med) //一系列数中,可能会有相同数字 
  {
    
    
   min=med; 
   med=t;
   continue;
  }
  if(t>min && t!=max && t!=min && t!=med)
  {
    
    
   min=t;
   continue;
  }
 }
 
 if(min==med && min==-Max)                  //这种情况会出现在所有数都一样的情况下 
 {
    
    
  printf("There is no second largest and third largest element");
  return 0;
 }
 if(min==-Max)  //一般情况,没有第三大的数字 
 {
    
    
  printf("There is no third largest element");
  return 0;
 }
 if(med==-Max)//一般情况,没有第二和第三大的数字 
 {
    
    
  printf("There is no second largest and third largest element");
  return 0;
 }
 printf("%lld %lld %lld",max,med,min);
 return 0;
}

Guess you like

Origin blog.csdn.net/Jessieeeeeee/article/details/107323560