제어프로그램


감시 프로그램

 - 각종 프로그램의 실행과 시스템 전체의 작동 상태를 감시감독하는 프로그램


작업제어 프로그램

 - 어떤 업무를 처리하고 다른 업무로의 이행을 자동으로 수행하기 위한

준비 및 그 처리에 대한 완료를 담당하는 프로그램

 

자료 관리 프로그램

 - 주기억장치와 보조기억장치 사이에 데이터 전송과

보조기억장치의 자료 갱신 및 유지 보수 기능을 수행하는 프로그램








처리프로그램


언어번역 프로그램

 - 원시 프로그램을 기계어 형태의 목적 프로그램으로 번역하는 프로그램

// 어셈블러, 컴파일러, 인터프리터


서비스 프로그램

 - 컴퓨터를 효율적으로 사용할 수 있는 사용빈도가 높은 프로그램


문제 프로그램

 - 특정 업무 및 해결을 위해 사용자가 작성한 프로그램








컴파일러와 인터프리터


컴파일러

 - 고급언어로 작성된 소스 프로그램 전체를 목적 프로그램으로 번역한 후,

링킹 작업을 통해 컴퓨터에서 실행 가능한 실행 프로그램을 생성함

 - 번역 과정이 번거롭고, 번역 시간이 오래 걸리지만 실행 속도가 빠름

// FORTRAN, COBOL, PASCAL, C, C++, PL/1

인터프리터

 - 고급언어로 작성된 프로그램을 한 줄 단위로 받아들여 번역하고,

번역과 동시에 프로그램을 한줄 단위로 즉시 실행시키는 프로그램

 - 줄 단위로 번역 실행되기 때문에 시분할 시스템에 유용함

 - 프로그램이 직접 실행되므로 목적 프로그램이 실행되지 않음

 - 번역 속도는 빠르지만 실행 속도는 느림

// BASIC, SNOBOL, LISP, APL








어셈블러


어셈블리어를 기계어 형태의 오브젝트 코드로 해석해주는 컴퓨터 언어 번역프로그램

어셈블러는 기본 컴퓨터 명령어들을, 컴퓨터 프로세서가 기본 연산을 수행하는데

사용할 수 있는 비트 패턴으로 변환시키는 프로그램

'ComputerScience > OperatingSystem' 카테고리의 다른 글

프로세서 스케줄  (0) 2017.10.10
프로세스  (0) 2017.10.10
링커와 로더  (0) 2017.10.10
매크로  (0) 2017.10.10
운영체제의 개요  (0) 2017.10.10


선택정렬 Θ(n^2)

버블정렬 Θ(n^2)

삽입정렬 Θ(n^2) Θ(n)




선택정렬 Θ(n^2)

A[1..n]에서 가장 큰 원소를 찾아 이 원소와 배열의 맨 끝자리에 있는 A[n]과 자리를 바꾼다.


8 31 48 73 3 65 20 29   index 0~7중에 가장 큰 수의 위치를 찾아 index 7의 값과 바꾼다.

8 31 48 29 3 65 20 73   index 0~6중에 가장 큰 수의 위치를 찾아 index 6의 값과 바꾼다.

8 31 20 29 3 65 48 73   반복

8 31 20 29 3 65 48 73

8 3 20 29 31 65 48 73

8 3 20 29 31 65 48 73

8 3 20 29 31 65 48 73

3 8 20 29 31 65 48 73



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    public static void selectionSort(int []arr){
        for(int i=arr.length-1 ; i>0 ; i--){
            int biggestNum = i;
            for(int j=0 ; j<i ; j++){
                if(arr[biggestNum]<arr[j]){
                    biggestNum = j;
                }
            }
            if(biggestNum!=i){
                int temp = arr[i];
                arr[i] = arr[biggestNum];
                arr[biggestNum] = temp;
            }
        }
    }
cs



PS)

알고리즘 책에서는 뒤에서부터 정렬해 나가지만

정보처리기사에서는 앞에서부터 정렬하게 나온다.

순서의 차이일뿐 똑같은 방법이기 때문에 상관없으려고 했는데 

문제 풀때 헤깔려서 짜증난다.








버블정렬 Θ(n^2)

선택정렬처럼 제일 큰 원소를 끝자리로 옮기는 작업을 반복하는 정렬


8 31 48 73 3 65 20 29   index 0과 index 1의 값을 비교해 큰 수를 뒤로 미룬다.

8 31 48 73 3 65 20 29   index 1과 index 2의 값을 비교해 큰 수를 뒤로 미룬다.

8 31 48 73 3 65 20 29   반복

8 31 48 73 3 65 20 29

8 31 48 3 73 65 20 29

8 31 48 3 65 73 20 29

8 31 48 3 65 20 73 29

8 31 48 3 65 20 29 73  index 7에 가장 큰 수가 왔으므로 선택정렬처럼 범위를 줄여서 반복한다.



1
2
3
4
5
6
7
8
9
10
11
    public static void bubbleSort(int []arr){
        for(int i=arr.length-1;i>0;i--){
            for(int j=0;j<i;j++){
                if(arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1= temp;
                }
            }
        }
    }
cs










삽입정렬 Θ(n^2) Θ(n)

이미 정렬되어 있는 i개짜리 배열에 하나의 원소를 더 더하여 정렬된 i+1개짜리 배열을 만드는 과정을 반복하는 정렬

정렬되어 있을수록 더 빠른 수행시간을 가진다.

완전히 정렬되어 있다면 Θ(n)의 시간이 든다.


8 31 48 73 3 65 20 29

8 31 48 73 3 65 20 29   1개짜리 정렬된 배열

8 31 48 73 3 65 20 29   2개짜리 정렬된 배열

8 31 48 73 3 65 20 29   3개짜리 정렬된 배열

8 31 48 73 3 65 20 29   4개짜리 정렬된 배열

3 8 31 48 73 65 20 29   5개짜리 정렬된 배열 (추가된 3을 맞는 위치에 가게 한다.)

3 8 31 48 65 73 20 29   반복

3 8 20 31 48 65 73 29

3 8 20 29 31 48 65 73



1
2
3
4
5
6
7
8
9
10
11
12
13
    public static void insertionSort(int []arr){
        for(int i=1;i<arr.length;i++){
            for(int j=i;j>0;j--){
                if(arr[j-1]>arr[j]){
                    int temp = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1= temp;
                }else{
                    break;
                }
            }
        }
    }
cs






중간 연산


연산 

형식 

반환형식 

연산의 인수 

함수 디스크립터 

 filter 

 중간 연산 

 Stream<T>

 Predicate<T> 

 T -> boolean 

 map 

 중간 연산 

 Stream<T> 

 Function<T, R>

 T -> R

 limit

 중간 연산 

 Stream<T>

 

 

 sorted

 중간 연산 

 Stream<T>

 Comparator<T>

 (T, T) -> int

 distinct

 중간 연산 

 Stream<T>

 

 



최종 연산


 연산

 형식

 목적

 forEach

 최종 연산

 스트림의 각 요소를 소비하면서 람다를 적용한다. void를 반환

 count

 최종 연산

 스트림의 요소 개수를 반환한다. long을 반환

 collect

 최종 연산

 스트림을 리듀스해서 리스트, 맵, 정수 형식의 컬렉션을 만든다.








필터링과 슬라이싱


distinct

        List<Integer> numbers = Arrays.asList(1213324);
        numbers.stream()
            .filter(i -> i%2==0)
            .distinct()
            .forEach(System.out::println);
cs


limit

        List<Integer> numbers = Arrays.asList(12133246);
        numbers.stream()
            .filter(i -> i%2==0)
            .distinct()
            .limit(2)
            .forEach(System.out::println);
cs


skip

        List<Integer> numbers = Arrays.asList(12133246);
        numbers.stream()
            .filter(i -> i%2==0)
            .distinct()
            .skip(1)
            .forEach(System.out::println);
cs







매핑


map

        List<Integer> nameSize = productList.stream()
                                    .map(Product::getName)
                                    .map(String::length)
                                    .collect(Collectors.toList());
cs


Arrays.stream

       String strings[] = new String[]{"hello""world"};
        Stream<String> strStream = Arrays.stream(strings);
cs


잘못된 예

        List<String> charList = strStream
                .map(word -> word.split(""))
                .map(Arrays::stream)
                .distinct()
                .collect(Collectors.toList());
cs

Stream<String[]>

Stream<Stream<String>>

이 되기때문에 컴파일 에러가 난다.


flatMap : 각 배열을 스트림이 아니라 스트림의 콘텐츠로 매핑한다.

        List<String> charList2 = strStream
                .map(word -> word.split(""))
                .flatMap(Arrays::stream)
                .distinct()
                .collect(Collectors.toList());
cs







검색과 매칭

쇼트서킷 기법을 이용함


anyMatch

        if(productList.stream().anyMatch(p -> p.name.equals("TV"))) {
            System.out.println("I have TV");
        }
cs


allMatch

        if(productList.stream().allMatch(p -> p.price>300000)) {
            System.out.println("I haven't cheap product");
        }
cs


noneMatch

        if(productList.stream().noneMatch(p -> p.price>300000)) {
            System.out.println("I have cheap product");
        }
cs


findAny

        Optional<Product> product = productList.stream()
                .filter(p -> p.price>1000000)
                .findAny();
cs


findFirst

        Optional<Product> product = productList.stream()
                .filter(p -> p.price>1000000)
                .findFirst();
cs








리듀싱


        List<Integer> numbers = Arrays.asList(12345678910);
        int sum = numbers.stream().reduce(0, (a, b) -> a+b);
cs








숫자형 스트림

IntStream에 경우 사용할 수 있는 메서드

sum, max, min, average 등


매핑

        int sumPrice = productList.stream()
                .mapToInt(Product::getPrice)
                .sum();
cs


객체스트림으로 복원

        Stream<Integer> priceStream = productList.stream()
                .mapToInt(Product::getPrice)
                .boxed();
cs


OptionalInt

        OptionalInt maxPrice = productList.stream()
                .mapToInt(Product::getPrice)
                .max();
        System.out.println(maxPrice.orElse(0));
cs


range

        int oddSum = IntStream.range(011)
                .filter(i -> i%2==1)
                .sum();
cs


rangeClosed

        int evenSum = IntStream.rangeClosed(110)
                .filter(i -> i%2==0)
                .sum();
cs








스트림 만들기


값으로 스트림 만들기

        Stream<String> strStream = Stream.of("Hello""World");
cs


배열로 스트림 만들기

        String strings[] = new String[]{"Hello""World"};
        Stream<String> strStream = Arrays.stream(strings);
cs


파일로 스트림 만들기

        try {
            Stream<String> lines = Files.lines(Paths.get("example.txt"), Charset.defaultCharset());
            lines.flatMap(line -> Arrays.stream(line.split(" ")))
                .forEach(System.out::println);
        } catch(IOException e) {
            e.printStackTrace();
        }
cs


함수로 무한 스트림 만들기


iterate

        Stream.iterate(1, i->i+1)
            .filter(i -> i%2==0)
            .limit(10)
            .forEach(System.out::println);
cs


generate : Supplier를 통해 인수를 받는다

        Stream.generate(Math::random)
            .map(d -> d*44+1)
            .mapToInt(Double::intValue)
            .distinct()
            .limit(6)
            .forEach(System.out::println);
cs




'창고' 카테고리의 다른 글

드로이드나이츠(Droid Knights) 2018  (0) 2018.06.10
Googl I/O 2017 Extended in Seoul  (0) 2017.11.10
드로이드나이츠(Droid Knights) 내용  (0) 2017.11.09
드로이드나이츠(Droid Knights)  (0) 2017.11.09
람다 표현식  (0) 2017.10.03

+ Recent posts